diff options
author | pfullbright | 2011-10-26 15:28:55 +0000 |
---|---|---|
committer | pfullbright | 2011-10-26 15:28:55 +0000 |
commit | da38e96bec21802ed849b6355457d88344d5e603 (patch) | |
tree | a0df17d0c4298f1ade43a1f1266c12a24d2e66e2 /jaxb/plugins/org.eclipse.jpt.jaxb.core/src | |
parent | 2087891bb649109dc31e37014b91ffdf3843510c (diff) | |
download | webtools.dali-da38e96bec21802ed849b6355457d88344d5e603.tar.gz webtools.dali-da38e96bec21802ed849b6355457d88344d5e603.tar.xz webtools.dali-da38e96bec21802ed849b6355457d88344d5e603.zip |
XmlSchemaType validation
Diffstat (limited to 'jaxb/plugins/org.eclipse.jpt.jaxb.core/src')
5 files changed, 101 insertions, 4 deletions
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaAttributeMappingXmlSchemaType.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaAttributeMappingXmlSchemaType.java index dc3fda16bc..2c89a7a931 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaAttributeMappingXmlSchemaType.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaAttributeMappingXmlSchemaType.java @@ -9,11 +9,17 @@ ******************************************************************************/ package org.eclipse.jpt.jaxb.core.internal.context.java; +import java.util.List; +import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jpt.jaxb.core.context.JaxbAttributeMapping; import org.eclipse.jpt.jaxb.core.context.JaxbClassMapping; import org.eclipse.jpt.jaxb.core.context.JaxbPackage; import org.eclipse.jpt.jaxb.core.context.JaxbPersistentAttribute; +import org.eclipse.jpt.jaxb.core.internal.validation.DefaultValidationMessages; +import org.eclipse.jpt.jaxb.core.internal.validation.JaxbValidationMessages; import org.eclipse.jpt.jaxb.core.resource.java.XmlSchemaTypeAnnotation; +import org.eclipse.wst.validation.internal.provisional.core.IMessage; +import org.eclipse.wst.validation.internal.provisional.core.IReporter; public class GenericJavaAttributeMappingXmlSchemaType extends GenericJavaXmlSchemaType { @@ -43,4 +49,22 @@ public class GenericJavaAttributeMappingXmlSchemaType protected JaxbPackage getJaxbPackage() { return this.getJaxbClassMapping().getJaxbType().getJaxbPackage(); } + + + // ***** validation ***** + + @Override + public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { + super.validate(messages, reporter, astRoot); + + String fqType = getFullyQualifiedType(); + if (fqType != null && ! XmlSchemaTypeAnnotation.DEFAULT_TYPE.equals(fqType)) { + messages.add( + DefaultValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + JaxbValidationMessages.XML_SCHEMA_TYPE__TYPE_SPECIFIED_ON_ATTRIBUTE, + this, + getTypeTextRange(astRoot))); + } + } } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaPackageXmlSchemaType.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaPackageXmlSchemaType.java index 4edb60cf25..04480116be 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaPackageXmlSchemaType.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaPackageXmlSchemaType.java @@ -9,9 +9,15 @@ ******************************************************************************/ package org.eclipse.jpt.jaxb.core.internal.context.java; +import java.util.List; +import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jpt.jaxb.core.context.JaxbPackage; import org.eclipse.jpt.jaxb.core.context.JaxbPackageInfo; +import org.eclipse.jpt.jaxb.core.internal.validation.DefaultValidationMessages; +import org.eclipse.jpt.jaxb.core.internal.validation.JaxbValidationMessages; import org.eclipse.jpt.jaxb.core.resource.java.XmlSchemaTypeAnnotation; +import org.eclipse.wst.validation.internal.provisional.core.IMessage; +import org.eclipse.wst.validation.internal.provisional.core.IReporter; public class GenericJavaPackageXmlSchemaType extends GenericJavaXmlSchemaType @@ -34,4 +40,22 @@ public class GenericJavaPackageXmlSchemaType protected JaxbPackage getJaxbPackage() { return getJaxbPackageInfo().getJaxbPackage(); } + + + // ***** validation ***** + + @Override + public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { + super.validate(messages, reporter, astRoot); + + String fqType = getFullyQualifiedType(); + if (fqType == null || XmlSchemaTypeAnnotation.DEFAULT_TYPE.equals(fqType)) { + messages.add( + DefaultValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + JaxbValidationMessages.XML_SCHEMA_TYPE__TYPE_NOT_SPECIFIED_ON_PACKAGE, + this, + getValidationTextRange(astRoot))); + } + } } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlSchemaType.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlSchemaType.java index 3526a797af..f32cc4db99 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlSchemaType.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlSchemaType.java @@ -22,6 +22,8 @@ import org.eclipse.jpt.jaxb.core.context.JaxbQName; import org.eclipse.jpt.jaxb.core.context.XmlSchemaType; import org.eclipse.jpt.jaxb.core.context.java.JavaContextNode; import org.eclipse.jpt.jaxb.core.internal.JptJaxbCoreMessages; +import org.eclipse.jpt.jaxb.core.internal.validation.DefaultValidationMessages; +import org.eclipse.jpt.jaxb.core.internal.validation.JaxbValidationMessages; import org.eclipse.jpt.jaxb.core.resource.java.QNameAnnotation; import org.eclipse.jpt.jaxb.core.resource.java.XmlSchemaTypeAnnotation; import org.eclipse.jpt.jaxb.core.xsd.XsdSchema; @@ -100,6 +102,26 @@ public abstract class GenericJavaXmlSchemaType return this.annotation.getType(); } + public String getFullyQualifiedType() { + return getXmlSchemaTypeAnnotation().getFullyQualifiedType(); + } + + + // ***** misc ***** + + protected XsdTypeDefinition getXsdTypeDefinition_() { + XsdSchema xsdSchema = getJaxbPackage().getXsdSchema(); + if (xsdSchema == null) { + return null; + } + + if (! StringTools.stringIsEmpty(this.qName.getName())) { + return xsdSchema.getTypeDefinition(this.qName.getNamespace(), this.qName.getName()); + } + + return null; + } + // ***** content assist ***** @@ -131,6 +153,21 @@ public abstract class GenericJavaXmlSchemaType super.validate(messages, reporter, astRoot); this.qName.validate(messages, reporter, astRoot); + + XsdTypeDefinition xsdType = getXsdTypeDefinition_(); + if (xsdType != null && xsdType.getKind() != XsdTypeDefinition.Kind.SIMPLE) { + messages.add( + DefaultValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + JaxbValidationMessages.XML_SCHEMA_TYPE__NON_SIMPLE_TYPE, + new String[] { qName.getName() }, + this, + getValidationTextRange(astRoot))); + } + } + + protected TextRange getTypeTextRange(CompilationUnit astRoot) { + return getXmlSchemaTypeAnnotation().getTypeTextRange(astRoot); } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/validation/JaxbValidationMessages.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/validation/JaxbValidationMessages.java index f4b9bc8da5..b5f3352eed 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/validation/JaxbValidationMessages.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/validation/JaxbValidationMessages.java @@ -98,6 +98,10 @@ public interface JaxbValidationMessages { // general validation + String XML_SCHEMA_TYPE__NON_SIMPLE_TYPE = "XML_SCHEMA_TYPE__NON_SIMPLE_TYPE"; + String XML_SCHEMA_TYPE__TYPE_NOT_SPECIFIED_ON_PACKAGE = "XML_SCHEMA_TYPE__TYPE_NOT_SPECIFIED_ON_PACKAGE"; + String XML_SCHEMA_TYPE__TYPE_SPECIFIED_ON_ATTRIBUTE = "XML_SCHEMA_TYPE__TYPE_SPECIFIED_ON_ATTRIBUTE"; + String QNAME__MISSING_NAME = "QNAME__MISSING_NAME"; String QNAME__UNRESOLVED_COMPONENT = "QNAME__UNRESOLVED_COMPONENT"; } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/XmlSchemaTypeAnnotation.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/XmlSchemaTypeAnnotation.java index f899506f36..f6a255e72c 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/XmlSchemaTypeAnnotation.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/XmlSchemaTypeAnnotation.java @@ -29,6 +29,8 @@ import org.eclipse.jpt.common.core.utility.TextRange; public interface XmlSchemaTypeAnnotation extends QNameAnnotation, NestableAnnotation { + String TYPE_PROPERTY = "type"; //$NON-NLS-1$ + /** * Corresponds to the 'type' element of the XmlSchemaType annotation. * Return null if the element does not exist in Java. @@ -39,19 +41,21 @@ public interface XmlSchemaTypeAnnotation * will return "XMLGregorianCalendar" */ String getType(); - String TYPE_PROPERTY = "type"; //$NON-NLS-1$ - + /** * Corresponds to the 'type' element of the XmlSchemaType annotation. * Set to null to remove the element. */ void setType(String type); + /** * Return the {@link TextRange} for the 'type' element. If the element * does not exist return the {@link TextRange} for the XmlSchemaType annotation. */ TextRange getTypeTextRange(CompilationUnit astRoot); - + + String FULLY_QUALIFIED_TYPE_PROPERTY = "fullyQualifiedType"; //$NON-NLS-1$ + /** * Return the fully-qualified type name as resolved by the AST's bindings. * <pre> @@ -62,5 +66,9 @@ public interface XmlSchemaTypeAnnotation * @return */ String getFullyQualifiedType(); - String FULLY_QUALIFIED_TYPE_PROPERTY = "fullyQualifiedType"; //$NON-NLS-1$ + + /** + * The default type when none is specified + */ + String DEFAULT_TYPE = "javax.xml.bind.annotation.XmlSchemaType.DEFAULT"; } |