Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpfullbright2011-08-25 21:37:05 +0000
committerpfullbright2011-08-25 21:37:05 +0000
commit99b1956f6d03064da4aee97572208b62947c7fb7 (patch)
treeaa6d6b1d067763bcbe9700afe8f15db7a01e99c5
parent99486aa12599749c981aaa16704f532ba4cbe449 (diff)
downloadwebtools.dali-99b1956f6d03064da4aee97572208b62947c7fb7.tar.gz
webtools.dali-99b1956f6d03064da4aee97572208b62947c7fb7.tar.xz
webtools.dali-99b1956f6d03064da4aee97572208b62947c7fb7.zip
XmlElementRef validation (and refactoring to support it)
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/property_files/jaxb_validation.properties6
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/AbstractJavaElementQName.java122
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlElement.java91
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlElementRef.java204
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlElementRefMapping.java48
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/validation/JaxbValidationMessages.java6
6 files changed, 298 insertions, 179 deletions
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/property_files/jaxb_validation.properties b/jaxb/plugins/org.eclipse.jpt.jaxb.core/property_files/jaxb_validation.properties
index fc45c950bd..dcd667cd4b 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/property_files/jaxb_validation.properties
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/property_files/jaxb_validation.properties
@@ -24,9 +24,13 @@ XML_ROOT_ELEMENT_TYPE_CONFLICTS_WITH_XML_TYPE = The xml type of the element decl
ATTRIBUTE_MAPPING__UNSUPPORTED_ANNOTATION = The annotation ''{0}'' is not allowed to be used in conjunction with ''{1}''.
ATTRIBUTE_MAPPING_XML_JAVA_TYPE_ADAPTER_TYPE_NOT_DEFINED = The type for XML Java type adapter is not defined.
XML_ELEMENT_WRAPPER_DEFINED_ON_NON_ARRAY_NON_COLLECTION = An XML element wrapper may only be defined on a collection or array property
+
XML_ELEMENT__UNSPECIFIED_TYPE = Unspecified XML element type.
XML_ELEMENT__ILLEGAL_TYPE = XML element type must be a sub-type of ''{0}''.
-XML_ELEMENT__UNSPECIFIED_ELEMENT_NAME = Unspecified XML element name.
+
+XML_ELEMENT_REF__NO_REGISTRY = There is no XML registry configured for this package.
+XML_ELEMENT_REF__NO_MATCHING_ELEMENT_DECL = There is no XML element decl in the XML registry matching the namespace ''{0}'' and name ''{1}''.
+
XML_ELEMENTS__DUPLICATE_XML_ELEMENT_TYPE = Duplicate type ''{0}'' in XML elements.
XML_ELEMENTS__DUPLICATE_XML_ELEMENT_QNAME = Duplicate element name ''{0}'' in XML elements.
XML_IDREF__TYPE_DOES_NOT_CONTAIN_XML_ID = In order to be used with an XML ID ref, type ''{0}'' must contain a property or field mapped as an XML ID.
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/AbstractJavaElementQName.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/AbstractJavaElementQName.java
new file mode 100644
index 0000000000..c480813518
--- /dev/null
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/AbstractJavaElementQName.java
@@ -0,0 +1,122 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ *******************************************************************************/
+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.utility.Filter;
+import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable;
+import org.eclipse.jpt.jaxb.core.context.JaxbPackage;
+import org.eclipse.jpt.jaxb.core.context.JaxbPersistentAttribute;
+import org.eclipse.jpt.jaxb.core.context.JaxbPersistentClass;
+import org.eclipse.jpt.jaxb.core.context.XmlElementWrapper;
+import org.eclipse.jpt.jaxb.core.context.XmlNsForm;
+import org.eclipse.jpt.jaxb.core.context.java.JavaContextNode;
+import org.eclipse.jpt.jaxb.core.internal.JptJaxbCoreMessages;
+import org.eclipse.jpt.jaxb.core.xsd.XsdElementDeclaration;
+import org.eclipse.jpt.jaxb.core.xsd.XsdSchema;
+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;
+
+
+public abstract class AbstractJavaElementQName
+ extends AbstractJavaQName {
+
+ public AbstractJavaElementQName(JavaContextNode parent) {
+ super(parent);
+ }
+
+
+ @Override
+ public String getReferencedComponentTypeDescription() {
+ return JptJaxbCoreMessages.XML_ELEMENT_DESC;
+ }
+
+ protected abstract JaxbPersistentAttribute getPersistentAttribute();
+
+ protected JaxbPersistentClass getPersistentClass() {
+ return getPersistentAttribute().getPersistentClass();
+ }
+
+ protected JaxbPackage getJaxbPackage() {
+ return getPersistentClass().getJaxbPackage();
+ }
+
+ protected abstract XmlElementWrapper getElementWrapper();
+
+ @Override
+ public String getDefaultName() {
+ return getPersistentAttribute().getJavaResourceAttribute().getName();
+ }
+
+ @Override
+ public Iterable<String> getNameProposals(Filter<String> filter) {
+ XsdTypeDefinition xsdType = getPersistentClass().getXsdTypeDefinition();
+ if (xsdType == null) {
+ return EmptyIterable.instance();
+ }
+
+ XmlElementWrapper elementWrapper = getElementWrapper();
+
+ if (elementWrapper == null) {
+ return xsdType.getElementNameProposals(getNamespace(), filter);
+ }
+ else {
+ XsdElementDeclaration xsdWrapperElement = elementWrapper.getXsdElementDeclaration();
+ if (xsdWrapperElement != null) {
+ return xsdWrapperElement.getElementNameProposals(getNamespace(), filter);
+ }
+ }
+
+ return EmptyIterable.instance();
+ }
+
+ @Override
+ public String getDefaultNamespace() {
+ return (getJaxbPackage().getElementFormDefault() == XmlNsForm.QUALIFIED) ?
+ getPersistentClass().getQName().getNamespace() : "";
+ }
+
+ @Override
+ public Iterable<String> getNamespaceProposals(Filter<String> filter) {
+ XsdSchema schema = getJaxbPackage().getXsdSchema();
+ return (schema == null) ? EmptyIterable.<String>instance() : schema.getNamespaceProposals(filter);
+ }
+
+ @Override
+ protected void validateReference(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) {
+ XsdTypeDefinition xsdType = getPersistentClass().getXsdTypeDefinition();
+ if (xsdType == null) {
+ return;
+ }
+
+ XsdElementDeclaration resolvedXsdElement = null;
+
+ XmlElementWrapper elementWrapper = getElementWrapper();
+
+ if (elementWrapper == null) {
+ resolvedXsdElement = xsdType.getElement(getNamespace(), getName());
+ }
+ else {
+ XsdElementDeclaration xsdWrapperElement = elementWrapper.getXsdElementDeclaration();
+ if (xsdWrapperElement == null) {
+ // there will be a separate message for unresolved wrapper element
+ // no need to also have a message for the nested element
+ return;
+ }
+ resolvedXsdElement = xsdWrapperElement.getElement(getNamespace(), getName());
+ }
+
+ if (resolvedXsdElement == null) {
+ messages.add(getUnresolveSchemaComponentMessage(astRoot));
+ }
+ }
+}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlElement.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlElement.java
index a07ce2ae78..dfc403c382 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlElement.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlElement.java
@@ -25,16 +25,11 @@ import org.eclipse.jpt.jaxb.core.context.JaxbPersistentClass;
import org.eclipse.jpt.jaxb.core.context.JaxbQName;
import org.eclipse.jpt.jaxb.core.context.XmlElement;
import org.eclipse.jpt.jaxb.core.context.XmlElementWrapper;
-import org.eclipse.jpt.jaxb.core.context.XmlNsForm;
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.XmlElementAnnotation;
-import org.eclipse.jpt.jaxb.core.xsd.XsdElementDeclaration;
-import org.eclipse.jpt.jaxb.core.xsd.XsdSchema;
-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;
@@ -311,17 +306,8 @@ public class GenericJavaXmlElement
@Override
public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) {
super.validate(messages, reporter, astRoot);
-
+ this.qName.validate(messages, reporter, astRoot);
validateType(messages, reporter, astRoot);
-
- if (StringTools.stringIsEmpty(this.qName.getName())) {
- messages.add(
- DefaultValidationMessages.buildMessage(
- IMessage.HIGH_SEVERITY,
- JaxbValidationMessages.XML_ELEMENT__UNSPECIFIED_ELEMENT_NAME,
- this,
- this.qName.getNameTextRange(astRoot)));
- }
}
protected void validateType(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) {
@@ -353,89 +339,26 @@ public class GenericJavaXmlElement
protected class XmlElementQName
- extends AbstractJavaQName {
+ extends AbstractJavaElementQName {
protected XmlElementQName(JavaContextNode parent) {
super(parent);
}
@Override
- public String getReferencedComponentTypeDescription() {
- return JptJaxbCoreMessages.XML_ELEMENT_DESC;
- }
-
- @Override
protected QNameAnnotation getAnnotation(boolean createIfNull) {
return GenericJavaXmlElement.this.getAnnotation(createIfNull);
}
@Override
- public String getDefaultName() {
- return GenericJavaXmlElement.this.getPersistentAttribute().getJavaResourceAttribute().getName();
+ protected JaxbPersistentAttribute getPersistentAttribute() {
+ return GenericJavaXmlElement.this.getPersistentAttribute();
}
@Override
- public Iterable<String> getNameProposals(Filter<String> filter) {
- XsdTypeDefinition xsdType = GenericJavaXmlElement.this.getPersistentClass().getXsdTypeDefinition();
- if (xsdType == null) {
- return EmptyIterable.instance();
- }
-
- XmlElementWrapper elementWrapper = GenericJavaXmlElement.this.getContext().getElementWrapper();
-
- if (elementWrapper == null) {
- return xsdType.getElementNameProposals(getNamespace(), filter);
- }
- else {
- XsdElementDeclaration xsdWrapperElement = elementWrapper.getXsdElementDeclaration();
- if (xsdWrapperElement != null) {
- return xsdWrapperElement.getElementNameProposals(getNamespace(), filter);
- }
- }
-
- return EmptyIterable.instance();
- }
-
- @Override
- public String getDefaultNamespace() {
- return (GenericJavaXmlElement.this.getJaxbPackage().getElementFormDefault() == XmlNsForm.QUALIFIED) ?
- GenericJavaXmlElement.this.getPersistentClass().getQName().getNamespace() : "";
- }
-
- @Override
- public Iterable<String> getNamespaceProposals(Filter<String> filter) {
- XsdSchema schema = GenericJavaXmlElement.this.getJaxbPackage().getXsdSchema();
- return (schema == null) ? EmptyIterable.<String>instance() : schema.getNamespaceProposals(filter);
- }
-
- @Override
- protected void validateReference(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) {
- XsdTypeDefinition xsdType = GenericJavaXmlElement.this.getPersistentClass().getXsdTypeDefinition();
- if (xsdType == null) {
- return;
- }
-
- XsdElementDeclaration resolvedXsdElement = null;
-
- XmlElementWrapper elementWrapper = GenericJavaXmlElement.this.getContext().getElementWrapper();
-
- if (elementWrapper == null) {
- resolvedXsdElement = xsdType.getElement(getNamespace(), getName());
- }
- else {
- XsdElementDeclaration xsdWrapperElement = elementWrapper.getXsdElementDeclaration();
- if (xsdWrapperElement == null) {
- // there will be a separate message for unresolved wrapper element
- // no need to also have a message for the nested element
- return;
- }
- resolvedXsdElement = xsdWrapperElement.getElement(getNamespace(), getName());
- }
-
- if (resolvedXsdElement == null) {
- messages.add(getUnresolveSchemaComponentMessage(astRoot));
- }
- }
+ protected XmlElementWrapper getElementWrapper() {
+ return GenericJavaXmlElement.this.context.getElementWrapper();
+ }
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlElementRef.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlElementRef.java
index a2bb271f97..eb3da2a3f1 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlElementRef.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlElementRef.java
@@ -11,23 +11,30 @@ 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.internal.utility.JDTTools;
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.StringTools;
+import org.eclipse.jpt.common.utility.internal.Tools;
import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable;
import org.eclipse.jpt.common.utility.internal.iterables.SingleElementIterable;
import org.eclipse.jpt.jaxb.core.context.JaxbAttributeMapping;
+import org.eclipse.jpt.jaxb.core.context.JaxbElementFactoryMethod;
import org.eclipse.jpt.jaxb.core.context.JaxbPackage;
import org.eclipse.jpt.jaxb.core.context.JaxbPersistentAttribute;
import org.eclipse.jpt.jaxb.core.context.JaxbPersistentClass;
import org.eclipse.jpt.jaxb.core.context.JaxbQName;
+import org.eclipse.jpt.jaxb.core.context.JaxbRegistry;
import org.eclipse.jpt.jaxb.core.context.XmlElementRef;
import org.eclipse.jpt.jaxb.core.context.XmlElementWrapper;
-import org.eclipse.jpt.jaxb.core.context.XmlNsForm;
+import org.eclipse.jpt.jaxb.core.context.XmlRootElement;
import org.eclipse.jpt.jaxb.core.context.java.JavaContextNode;
+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.QNameAnnotation;
import org.eclipse.jpt.jaxb.core.resource.java.XmlElementRefAnnotation;
-import org.eclipse.jpt.jaxb.core.xsd.XsdSchema;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
@@ -223,52 +230,41 @@ public class GenericJavaXmlElementRef
@Override
public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) {
super.validate(messages, reporter, astRoot);
-
- // TODO
-// validateType(messages, reporter, astRoot);
-//
-// if (StringTools.stringIsEmpty(this.schemaElementRef.getName())) {
-// messages.add(
-// DefaultValidationMessages.buildMessage(
-// IMessage.HIGH_SEVERITY,
-// JaxbValidationMessages.XML_ELEMENT__UNSPECIFIED_ELEMENT_NAME,
-// this,
-// this.schemaElementRef.getNameTextRange(astRoot)));
-// }
+ this.qName.validate(messages, reporter, astRoot);
+ validateType(messages, reporter, astRoot);
}
protected void validateType(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) {
- // TODO
-// String fqType = getFullyQualifiedType();
-// if (StringTools.stringIsEmpty(fqType)) {
-// messages.add(
-// DefaultValidationMessages.buildMessage(
-// IMessage.HIGH_SEVERITY,
-// JaxbValidationMessages.XML_ELEMENT__UNSPECIFIED_TYPE,
-// this,
-// getTypeTextRange(astRoot)));
-// }
-// else if (! StringTools.stringIsEmpty(this.specifiedType)
-// // verify that type actually exists before validating
-// && JDTTools.findType(getJaxbProject().getJavaProject(), fqType) != null) {
-// String attributeBaseType = getPersistentAttribute().getJavaResourceAttributeBaseTypeName();
-// if (! JDTTools.typeIsSubType(getJaxbProject().getJavaProject(), fqType, attributeBaseType)) {
-// messages.add(
-// DefaultValidationMessages.buildMessage(
-// IMessage.HIGH_SEVERITY,
-// JaxbValidationMessages.XML_ELEMENT__ILLEGAL_TYPE,
-// new String[] { attributeBaseType },
-// this,
-// getTypeTextRange(astRoot)));
-//
-// }
-// }
+ String fqType = getFullyQualifiedType();
+ if (StringTools.stringIsEmpty(fqType)) {
+ messages.add(
+ DefaultValidationMessages.buildMessage(
+ IMessage.HIGH_SEVERITY,
+ JaxbValidationMessages.XML_ELEMENT__UNSPECIFIED_TYPE,
+ this,
+ getTypeTextRange(astRoot)));
+ }
+ else if (! StringTools.stringIsEmpty(this.specifiedType)
+ // verify that type actually exists before validating
+ && JDTTools.findType(getJaxbProject().getJavaProject(), fqType) != null) {
+ String attributeBaseType = getPersistentAttribute().getJavaResourceAttributeBaseTypeName();
+ if (! JDTTools.typeIsSubType(getJaxbProject().getJavaProject(), fqType, attributeBaseType)) {
+ messages.add(
+ DefaultValidationMessages.buildMessage(
+ IMessage.HIGH_SEVERITY,
+ JaxbValidationMessages.XML_ELEMENT__ILLEGAL_TYPE,
+ new String[] { attributeBaseType },
+ this,
+ getTypeTextRange(astRoot)));
+
+ }
+ }
}
protected class XmlElementRefQName
- extends AbstractJavaQName {
+ extends AbstractJavaElementQName {
protected XmlElementRefQName(JavaContextNode parent) {
super(parent);
@@ -280,75 +276,97 @@ public class GenericJavaXmlElementRef
}
@Override
- public String getDefaultName() {
- return GenericJavaXmlElementRef.this.getPersistentAttribute().getJavaResourceAttribute().getName();
+ protected JaxbPersistentAttribute getPersistentAttribute() {
+ return GenericJavaXmlElementRef.this.getPersistentAttribute();
+ }
+
+ protected boolean isTypeJAXBElement() {
+ return JAXB.JAXB_ELEMENT.equals(GenericJavaXmlElementRef.this.getFullyQualifiedType());
+ }
+
+ protected JaxbPersistentClass getReferencedPersistentClass() {
+ String fqTypeName = GenericJavaXmlElementRef.this.getFullyQualifiedType();
+ return getJaxbProject().getContextRoot().getPersistentClass(fqTypeName);
}
@Override
- public Iterable<String> getNameProposals(Filter<String> filter) {
+ protected XmlElementWrapper getElementWrapper() {
+ return GenericJavaXmlElementRef.this.context.getElementWrapper();
+ }
+
+ @Override
+ public String getDefaultName() {
+ if (isTypeJAXBElement()) {
+ return super.getDefaultName();
+ }
+
+ JaxbPersistentClass referencedClass = getReferencedPersistentClass();
+ if (referencedClass != null) {
+ XmlRootElement rootElement = referencedClass.getRootElement();
+ if (rootElement != null) {
+ return rootElement.getQName().getName();
+ }
+ }
- // TODO
-// XsdTypeDefinition xsdType = GenericJavaXmlElementRef.this.getPersistentClass().getXsdTypeDefinition();
-// if (xsdType == null) {
-// return EmptyIterable.instance();
-// }
-//
-// XmlElementWrapper elementWrapper = GenericJavaXmlElementRef.this.getContext().getElementWrapper();
-//
-// if (elementWrapper == null) {
-// return xsdType.getElementNameProposals(getNamespace(), filter);
-// }
-// else {
-// XsdElementDeclaration xsdWrapperElement = elementWrapper.getXsdElementDeclaration();
-// if (xsdWrapperElement != null) {
-// return xsdWrapperElement.getElementNameProposals(getNamespace(), filter);
-// }
-// }
-//
- return EmptyIterable.instance();
+ return "";
}
@Override
public String getDefaultNamespace() {
- return (GenericJavaXmlElementRef.this.getJaxbPackage().getElementFormDefault() == XmlNsForm.QUALIFIED) ?
- GenericJavaXmlElementRef.this.getPersistentClass().getQName().getNamespace() : "";
+ JaxbPersistentClass referencedClass = getReferencedPersistentClass();
+ if (referencedClass != null) {
+ XmlRootElement rootElement = referencedClass.getRootElement();
+ if (rootElement != null) {
+ return rootElement.getQName().getNamespace();
+ }
+ }
+
+ return super.getDefaultNamespace();
}
@Override
- public Iterable<String> getNamespaceProposals(Filter<String> filter) {
- XsdSchema schema = GenericJavaXmlElementRef.this.getJaxbPackage().getXsdSchema();
- return (schema == null) ? EmptyIterable.<String>instance() : schema.getNamespaceProposals(filter);
+ protected void validateName(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) {
+ // only validate if type is JAXBElement
+ if (isTypeJAXBElement()) {
+ super.validateName(messages, reporter, astRoot);
+ }
}
@Override
protected void validateReference(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) {
+ super.validateReference(messages, reporter, astRoot);
+
+ // if type is JAXBElement, then name/namespace must also point at a valid XmlElementDecl
+ if (! isTypeJAXBElement()) {
+ return;
+ }
+
+ JaxbRegistry registry = getJaxbPackage().getRegistry();
+
+ if (registry == null) {
+ messages.add(
+ DefaultValidationMessages.buildMessage(
+ IMessage.HIGH_SEVERITY,
+ JaxbValidationMessages.XML_ELEMENT_REF__NO_REGISTRY,
+ this,
+ getValidationTextRange(astRoot)));
+ return;
+ }
- // TODO
-// XsdTypeDefinition xsdType = GenericJavaXmlElementRef.this.getPersistentClass().getXsdTypeDefinition();
-// if (xsdType == null) {
-// return;
-// }
-//
-// XsdElementDeclaration resolvedXsdElement = null;
-//
-// XmlElementWrapper elementWrapper = GenericJavaXmlElementRef.this.getContext().getElementWrapper();
-//
-// if (elementWrapper == null) {
-// resolvedXsdElement = xsdType.getElement(getNamespace(), getName());
-// }
-// else {
-// XsdElementDeclaration xsdWrapperElement = elementWrapper.getXsdElementDeclaration();
-// if (xsdWrapperElement == null) {
-// // there will be a separate message for unresolved wrapper element
-// // no need to also have a message for the nested element
-// return;
-// }
-// resolvedXsdElement = xsdWrapperElement.getElement(getNamespace(), getName());
-// }
-//
-// if (resolvedXsdElement == null) {
-// messages.add(getUnresolveSchemaComponentMessage(astRoot));
-// }
+ for (JaxbElementFactoryMethod elementDecl : registry.getElementFactoryMethods()) {
+ if (Tools.valuesAreEqual(getName(), elementDecl.getElementName())
+ && Tools.valuesAreEqual(getNamespace(), elementDecl.getNamespace())) {
+ return;
+ }
+ }
+ messages.add(
+ DefaultValidationMessages.buildMessage(
+ IMessage.HIGH_SEVERITY,
+ JaxbValidationMessages.XML_ELEMENT_REF__NO_MATCHING_ELEMENT_DECL,
+ new String[] { getNamespace(), getName() },
+ this,
+ getValidationTextRange(astRoot)));
+
}
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlElementRefMapping.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlElementRefMapping.java
index 0733a97e92..35603e6339 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlElementRefMapping.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlElementRefMapping.java
@@ -9,7 +9,12 @@
*******************************************************************************/
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.resource.java.JavaResourceAnnotatedElement;
+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.JaxbAttributeMapping;
import org.eclipse.jpt.jaxb.core.context.JaxbPersistentAttribute;
@@ -22,6 +27,8 @@ import org.eclipse.jpt.jaxb.core.resource.java.JAXB;
import org.eclipse.jpt.jaxb.core.resource.java.XmlElementRefAnnotation;
import org.eclipse.jpt.jaxb.core.resource.java.XmlElementWrapperAnnotation;
import org.eclipse.jpt.jaxb.core.resource.java.XmlJavaTypeAdapterAnnotation;
+import org.eclipse.wst.validation.internal.provisional.core.IMessage;
+import org.eclipse.wst.validation.internal.provisional.core.IReporter;
public class GenericJavaXmlElementRefMapping
@@ -181,6 +188,47 @@ public class GenericJavaXmlElementRefMapping
}
+ // ***** 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;
+ }
+
+ result = this.xmlElementRef.getJavaCompletionProposals(pos, filter, astRoot);
+ if (! CollectionTools.isEmpty(result)) {
+ return result;
+ }
+
+ if (this.xmlElementWrapper != null) {
+ result = this.xmlElementWrapper.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);
+
+ this.xmlElementRef.validate(messages, reporter, astRoot);
+
+ this.xmlAdaptable.validate(messages, reporter, astRoot);
+
+ if (this.getXmlElementWrapper() != null) {
+ this.getXmlElementWrapper().validate(messages, reporter, astRoot);
+ }
+ }
+
+
public class XmlElementRefContext
implements GenericJavaXmlElementRef.Context {
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 d3d1ae59ef..b31f92fb3a 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
@@ -43,9 +43,13 @@ public interface JaxbValidationMessages {
String ATTRIBUTE_MAPPING__UNSUPPORTED_ANNOTATION = "ATTRIBUTE_MAPPING__UNSUPPORTED_ANNOTATION";
String ATTRIBUTE_MAPPING_XML_JAVA_TYPE_ADAPTER_TYPE_NOT_DEFINED = "ATTRIBUTE_MAPPING_XML_JAVA_TYPE_ADAPTER_TYPE_NOT_DEFINED";
String XML_ELEMENT_WRAPPER_DEFINED_ON_NON_ARRAY_NON_COLLECTION = "XML_ELEMENT_WRAPPER_DEFINED_ON_NON_ARRAY_NON_COLLECTION";
+
String XML_ELEMENT__UNSPECIFIED_TYPE = "XML_ELEMENT__UNSPECIFIED_TYPE";
String XML_ELEMENT__ILLEGAL_TYPE = "XML_ELEMENT__ILLEGAL_TYPE";
- String XML_ELEMENT__UNSPECIFIED_ELEMENT_NAME = "XML_ELEMENT__UNSPECIFIED_ELEMENT_NAME";
+
+ String XML_ELEMENT_REF__NO_REGISTRY = "XML_ELEMENT_REF__NO_REGISTRY";
+ String XML_ELEMENT_REF__NO_MATCHING_ELEMENT_DECL = "XML_ELEMENT_REF__NO_MATCHING_ELEMENT_DECL";
+
String XML_ELEMENTS__DUPLICATE_XML_ELEMENT_TYPE = "XML_ELEMENTS__DUPLICATE_XML_ELEMENT_TYPE";
String XML_ELEMENTS__DUPLICATE_XML_ELEMENT_QNAME = "XML_ELEMENTS__DUPLICATE_XML_ELEMENT_QNAME";
String XML_IDREF__TYPE_DOES_NOT_CONTAIN_XML_ID = "XML_IDREF__TYPE_DOES_NOT_CONTAIN_XML_ID";

Back to the top