Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpfullbright2011-12-02 21:45:14 +0000
committerpfullbright2011-12-02 21:45:14 +0000
commitf0b2a16788a4d3f2e788e60eed62e563701bb7d1 (patch)
tree667b48224503bbe37104b18c933bb0b784240442 /jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt
parentb041cb96ff61f0d99d5edc6ff12b9038d7945697 (diff)
downloadwebtools.dali-f0b2a16788a4d3f2e788e60eed62e563701bb7d1.tar.gz
webtools.dali-f0b2a16788a4d3f2e788e60eed62e563701bb7d1.tar.xz
webtools.dali-f0b2a16788a4d3f2e788e60eed62e563701bb7d1.zip
added XmlSchemaType to XmlValueMapping, and added text content validation to XmlValue
Diffstat (limited to 'jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt')
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/XmlValueMapping.java11
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/AbstractJavaBasicMapping.java3
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlValueMapping.java186
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/validation/JaxbValidationMessages.java1
4 files changed, 175 insertions, 26 deletions
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/XmlValueMapping.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/XmlValueMapping.java
index 0509dc42e5..c04335c848 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/XmlValueMapping.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/XmlValueMapping.java
@@ -24,5 +24,14 @@ package org.eclipse.jpt.jaxb.core.context;
*/
public interface XmlValueMapping
extends JaxbAttributeMapping, XmlAdaptableMapping, XmlListMapping {
-
+
+ // ***** XmlSchemaType *****
+
+ String XML_SCHEMA_TYPE_PROPERTY = "xmlSchemaType"; //$NON-NLS-1$
+
+ XmlSchemaType getXmlSchemaType();
+
+ XmlSchemaType addXmlSchemaType();
+
+ void removeXmlSchemaType();
} \ No newline at end of file
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/AbstractJavaBasicMapping.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/AbstractJavaBasicMapping.java
index 11ef231267..1610730ae4 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/AbstractJavaBasicMapping.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/AbstractJavaBasicMapping.java
@@ -157,7 +157,8 @@ public abstract class AbstractJavaBasicMapping<A extends JaxbBasicSchemaComponen
this.setXmlSchemaType_(null);
}
}
-
+
+
// ***** XmlList *****
public boolean isXmlList() {
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlValueMapping.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlValueMapping.java
index cecee0d568..a768780cab 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlValueMapping.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlValueMapping.java
@@ -12,24 +12,33 @@ package org.eclipse.jpt.jaxb.core.internal.context.java;
import java.util.List;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jpt.common.core.utility.TextRange;
+import org.eclipse.jpt.common.utility.Filter;
+import org.eclipse.jpt.common.utility.internal.CollectionTools;
+import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable;
import org.eclipse.jpt.jaxb.core.MappingKeys;
import org.eclipse.jpt.jaxb.core.context.JaxbPersistentAttribute;
+import org.eclipse.jpt.jaxb.core.context.XmlSchemaType;
import org.eclipse.jpt.jaxb.core.context.XmlValueMapping;
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.JAXB;
import org.eclipse.jpt.jaxb.core.resource.java.XmlListAnnotation;
+import org.eclipse.jpt.jaxb.core.resource.java.XmlSchemaTypeAnnotation;
import org.eclipse.jpt.jaxb.core.resource.java.XmlValueAnnotation;
+import org.eclipse.jpt.jaxb.core.xsd.XsdComplexTypeDefinition;
import org.eclipse.jpt.jaxb.core.xsd.XsdSimpleTypeDefinition;
import org.eclipse.jpt.jaxb.core.xsd.XsdTypeDefinition;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
+import org.eclipse.xsd.XSDContentTypeCategory;
import org.eclipse.xsd.XSDVariety;
public class GenericJavaXmlValueMapping
extends AbstractJavaAdaptableAttributeMapping<XmlValueAnnotation>
implements XmlValueMapping {
+ protected XmlSchemaType xmlSchemaType;
+
protected boolean specifiedXmlList;
protected boolean defaultXmlList;
@@ -37,6 +46,7 @@ public class GenericJavaXmlValueMapping
public GenericJavaXmlValueMapping(JaxbPersistentAttribute parent) {
super(parent);
+ initializeXmlSchemaType();
initializeXmlList();
}
@@ -56,9 +66,88 @@ public class GenericJavaXmlValueMapping
@Override
public void synchronizeWithResourceModel() {
super.synchronizeWithResourceModel();
+ syncXmlSchemaType();
syncXmlList();
}
+ @Override
+ public void update() {
+ super.update();
+ updateXmlSchemaType();
+ }
+
+
+ // ***** XmlSchemaType *****
+
+ public XmlSchemaType getXmlSchemaType() {
+ return this.xmlSchemaType;
+ }
+
+ protected void setXmlSchemaType_(XmlSchemaType xmlSchemaType) {
+ XmlSchemaType oldXmlSchemaType = this.xmlSchemaType;
+ this.xmlSchemaType = xmlSchemaType;
+ this.firePropertyChanged(XML_SCHEMA_TYPE_PROPERTY, oldXmlSchemaType, xmlSchemaType);
+ }
+
+ public boolean hasXmlSchemaType() {
+ return this.xmlSchemaType != null;
+ }
+
+ public XmlSchemaType addXmlSchemaType() {
+ if (this.xmlSchemaType != null) {
+ throw new IllegalStateException();
+ }
+ XmlSchemaTypeAnnotation annotation = (XmlSchemaTypeAnnotation) this.getJavaResourceAttribute().addAnnotation(0, JAXB.XML_SCHEMA_TYPE);
+
+ XmlSchemaType xmlJavaTypeAdapter = this.buildXmlSchemaType(annotation);
+ this.setXmlSchemaType_(xmlJavaTypeAdapter);
+ return xmlJavaTypeAdapter;
+ }
+
+ public void removeXmlSchemaType() {
+ if (this.xmlSchemaType == null) {
+ throw new IllegalStateException();
+ }
+ this.getJavaResourceAttribute().removeAnnotation(JAXB.XML_SCHEMA_TYPE);
+ this.setXmlSchemaType_(null);
+ }
+
+ protected XmlSchemaType buildXmlSchemaType(XmlSchemaTypeAnnotation annotation) {
+ return new GenericJavaAttributeMappingXmlSchemaType(this, annotation);
+ }
+
+ protected XmlSchemaTypeAnnotation getXmlSchemaTypeAnnotation() {
+ return (XmlSchemaTypeAnnotation) this.getJavaResourceAttribute().getAnnotation(0, JAXB.XML_SCHEMA_TYPE);
+ }
+
+ protected void initializeXmlSchemaType() {
+ XmlSchemaTypeAnnotation annotation = this.getXmlSchemaTypeAnnotation();
+ if (annotation != null) {
+ this.xmlSchemaType = this.buildXmlSchemaType(annotation);
+ }
+ }
+
+ protected void updateXmlSchemaType() {
+ if (this.xmlSchemaType != null) {
+ this.xmlSchemaType.update();
+ }
+ }
+
+ protected void syncXmlSchemaType() {
+ XmlSchemaTypeAnnotation annotation = this.getXmlSchemaTypeAnnotation();
+ if (annotation != null) {
+ if (this.getXmlSchemaType() != null) {
+ this.getXmlSchemaType().synchronizeWithResourceModel();
+ }
+ else {
+ this.setXmlSchemaType_(this.buildXmlSchemaType(annotation));
+ }
+ }
+ else {
+ this.setXmlSchemaType_(null);
+ }
+ }
+
// ***** XmlList *****
@@ -116,45 +205,94 @@ public class GenericJavaXmlValueMapping
}
+ // ***** misc *****
+
+ @Override
+ public XsdTypeDefinition getDataTypeXsdTypeDefinition() {
+ if (this.xmlSchemaType != null) {
+ return this.xmlSchemaType.getXsdTypeDefinition();
+ }
+ return super.getDataTypeXsdTypeDefinition();
+ }
+
+
+ // ***** content assist *****
+
+ @Override
+ public Iterable<String> getJavaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) {
+ Iterable<String> result = super.getJavaCompletionProposals(pos, filter, astRoot);
+ if (! CollectionTools.isEmpty(result)) {
+ return result;
+ }
+
+ if (this.xmlSchemaType != null) {
+ result = this.xmlSchemaType.getJavaCompletionProposals(pos, filter, astRoot);
+ if (! CollectionTools.isEmpty(result)) {
+ return result;
+ }
+ }
+
+ return EmptyIterable.instance();
+ }
+
+
// ***** validation *****
@Override
public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) {
super.validate(messages, reporter, astRoot);
+ if (this.xmlSchemaType != null) {
+ this.xmlSchemaType.validate(messages, reporter, astRoot);
+ }
+
if (isXmlList()) {
- if (! getPersistentAttribute().isJavaResourceAttributeCollectionType()) {
- messages.add(
- DefaultValidationMessages.buildMessage(
- IMessage.HIGH_SEVERITY,
- JaxbValidationMessages.XML_LIST__ATTRIBUTE_NOT_COLLECTION_TYPE,
- this,
- getXmlListValidationTextRange(astRoot)));
- }
- else {
- XsdTypeDefinition xsdType = getDataTypeXsdTypeDefinition();
- if (xsdType != null
- && (xsdType.getKind() != XsdTypeDefinition.Kind.SIMPLE
- || ((XsdSimpleTypeDefinition) xsdType).getXSDComponent().getVariety() == XSDVariety.LIST_LITERAL)) {
-
- messages.add(
- DefaultValidationMessages.buildMessage(
- IMessage.HIGH_SEVERITY,
- JaxbValidationMessages.XML_LIST__ITEM_TYPE_NOT_MAPPED_TO_VALID_SCHEMA_TYPE,
- new String[] { getValueTypeName() },
- this,
- getValidationTextRange(astRoot)));
- }
- }
+ validateXmlList(messages, reporter, astRoot);
}
validateSchemaType(messages, reporter, astRoot);
}
-
+ protected void validateXmlList(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) {
+ if (! getPersistentAttribute().isJavaResourceAttributeCollectionType()) {
+ messages.add(
+ DefaultValidationMessages.buildMessage(
+ IMessage.HIGH_SEVERITY,
+ JaxbValidationMessages.XML_LIST__ATTRIBUTE_NOT_COLLECTION_TYPE,
+ this,
+ getXmlListValidationTextRange(astRoot)));
+ }
+ else {
+ XsdTypeDefinition xsdType = getDataTypeXsdTypeDefinition();
+ if (xsdType != null
+ && (xsdType.getKind() != XsdTypeDefinition.Kind.SIMPLE
+ || ((XsdSimpleTypeDefinition) xsdType).getXSDComponent().getVariety() == XSDVariety.LIST_LITERAL)) {
+
+ messages.add(
+ DefaultValidationMessages.buildMessage(
+ IMessage.HIGH_SEVERITY,
+ JaxbValidationMessages.XML_LIST__ITEM_TYPE_NOT_MAPPED_TO_VALID_SCHEMA_TYPE,
+ new String[] { getValueTypeName() },
+ this,
+ getValidationTextRange(astRoot)));
+ }
+ }
+ }
protected void validateSchemaType(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) {
XsdTypeDefinition xsdClassType = getClassMapping().getXsdTypeDefinition();
+
+ if (! (xsdClassType.getKind() == XsdTypeDefinition.Kind.SIMPLE
+ || ((XsdComplexTypeDefinition) xsdClassType).getXSDComponent().getContentTypeCategory() == XSDContentTypeCategory.SIMPLE_LITERAL)) {
+ messages.add(
+ DefaultValidationMessages.buildMessage(
+ IMessage.HIGH_SEVERITY,
+ JaxbValidationMessages.XML_VALUE__NO_TEXT_CONTENT,
+ this,
+ getValidationTextRange(astRoot)));
+ return;
+ }
+
XsdTypeDefinition xsdType = (xsdClassType == null) ? null : xsdClassType.getBaseType();
XsdTypeDefinition expectedSchemaType = getDataTypeXsdTypeDefinition();
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 73c2569c9a..4f687a96d1 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
@@ -102,6 +102,7 @@ public interface JaxbValidationMessages {
String XML_REGISTRY__DUPLICATE_XML_ELEMENT_QNAME = "XML_REGISTRY__DUPLICATE_XML_ELEMENT_QNAME";
String XML_VALUE__MULTIPLE_MAPPINGS_DEFINED = "XML_VALUE__MULTIPLE_MAPPINGS_DEFINED";
+ String XML_VALUE__NO_TEXT_CONTENT = "XML_VALUE__NO_TEXT_CONTENT";
String XML_VALUE__INVALID_SCHEMA_TYPE = "XML_VALUE__INVALID_SCHEMA_TYPE";
String XML_VALUE_MAPPING_WITH_NON_XML_ATTRIBUTE_MAPPING_DEFINED = "XML_VALUE_MAPPING_WITH_NON_XML_ATTRIBUTE_MAPPING_DEFINED";

Back to the top