diff options
author | kmoore | 2011-03-02 19:39:43 +0000 |
---|---|---|
committer | kmoore | 2011-03-02 19:39:43 +0000 |
commit | 93c62a6f3803548e6a77f6f951a5768fc499369b (patch) | |
tree | 9dd4941c8f231bc67d11c2c8e23fcc7e6c69d63f /jaxb | |
parent | f9e0de102015494efb98efc26545bcbe205c21c3 (diff) | |
download | webtools.dali-93c62a6f3803548e6a77f6f951a5768fc499369b.tar.gz webtools.dali-93c62a6f3803548e6a77f6f951a5768fc499369b.tar.xz webtools.dali-93c62a6f3803548e6a77f6f951a5768fc499369b.zip |
326720 - XmlIDREF and XmlAttachmentRef context model support and validation
Diffstat (limited to 'jaxb')
12 files changed, 607 insertions, 2 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 3b744716ce..321b87376d 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 @@ -29,4 +29,5 @@ MULTIPLE_XML_VALUE_MAPPINGS_DEFINED = Attribute ''{0}'' cannot be mapped as XmlV XML_VALUE_MAPPING_WITH_NON_XML_ATTRIBUTE_MAPPING_DEFINED = Attribute ''{0}'' must be mapped as XmlAttribute because another attribute ''{1}'' is mapped as XmlValue XML_ANY_ATTRIBUTE_MAPPING_DEFINED_ON_NON_MAP = XmlAnyAttribute is only allowed on a property assignable to java.util.Map XML_ID_DEFINED_ON_NON_STRING = XmlID is only allowed on a java.lang.String property -MULTIPLE_XML_IDS_DEFINED = Attribute ''{0}'' cannot have an XmlID because attribute ''{1}'' already has an XmlID, cannot define multiple mappings with XmlID
\ No newline at end of file +MULTIPLE_XML_IDS_DEFINED = Attribute ''{0}'' cannot have an XmlID because attribute ''{1}'' already has an XmlID, cannot define multiple mappings with XmlID +XML_IDREF_TYPE_DOES_NOT_CONTAIN_XML_ID = Attribute ''{0}'' is an XmlIDREF, type ''{1}'' must contain a property or field annotated with @XmlId
\ No newline at end of file diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbContainmentMapping.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbContainmentMapping.java index 34a49ffb83..20097e7bc7 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbContainmentMapping.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbContainmentMapping.java @@ -76,4 +76,18 @@ public interface JaxbContainmentMapping void removeXmlID(); String XML_ID_PROPERTY = "xmlID"; //$NON-NLS-1$ + + /********** XmlIDREF **********/ + XmlIDREF getXmlIDREF(); + XmlIDREF addXmlIDREF(); + void removeXmlIDREF(); + String XML_IDREF_PROPERTY = "xmlIDREF"; //$NON-NLS-1$ + + + /********** XmlAttachmentRef **********/ + XmlAttachmentRef getXmlAttachmentRef(); + XmlAttachmentRef addXmlAttachmentRef(); + void removeXmlAttachmentRef(); + String XML_ATTACHMENT_REF_PROPERTY = "xmlAttachmentRef"; //$NON-NLS-1$ + }
\ No newline at end of file diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbPersistentClass.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbPersistentClass.java index b88288edc1..68ea100d87 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbPersistentClass.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbPersistentClass.java @@ -58,4 +58,10 @@ public interface JaxbPersistentClass */ String getJavaResourceAttributeOwningTypeName(JaxbPersistentAttribute attribute); + /** + * Return true if 1 or more attributes include the @XmlId annotation + */ + boolean containsXmlId(); + + } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/XmlAttachmentRef.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/XmlAttachmentRef.java new file mode 100644 index 0000000000..903e3c246f --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/XmlAttachmentRef.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * 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.context; + +import org.eclipse.jpt.jaxb.core.context.java.JavaContextNode; + + +/** + * Represents a JAXB XmlAttachmentRef + * <p> + * Provisional API: This interface is part of an interim API that is still + * under development and expected to change significantly before reaching + * stability. It is available at this early stage to solicit feedback from + * pioneering adopters on the understanding that any code that uses this API + * will almost certainly be broken (repeatedly) as the API evolves. + * + * @version 3.0 + * @since 3.0 + */ +public interface XmlAttachmentRef + extends JavaContextNode { + + +}
\ No newline at end of file diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/XmlIDREF.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/XmlIDREF.java new file mode 100644 index 0000000000..72581acdc0 --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/XmlIDREF.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * 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.context; + +import org.eclipse.jpt.jaxb.core.context.java.JavaContextNode; + + +/** + * Represents a JAXB XmlIDREF + * <p> + * Provisional API: This interface is part of an interim API that is still + * under development and expected to change significantly before reaching + * stability. It is available at this early stage to solicit feedback from + * pioneering adopters on the understanding that any code that uses this API + * will almost certainly be broken (repeatedly) as the API evolves. + * + * @version 3.0 + * @since 3.0 + */ +public interface XmlIDREF + extends JavaContextNode { + + +}
\ 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/GenericJavaContainmentMapping.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaContainmentMapping.java index fce15fa32e..6bfef1f08c 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaContainmentMapping.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaContainmentMapping.java @@ -17,13 +17,17 @@ import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable; import org.eclipse.jpt.jaxb.core.context.JaxbContainmentMapping; import org.eclipse.jpt.jaxb.core.context.JaxbPersistentAttribute; import org.eclipse.jpt.jaxb.core.context.XmlAdaptable; +import org.eclipse.jpt.jaxb.core.context.XmlAttachmentRef; import org.eclipse.jpt.jaxb.core.context.XmlID; +import org.eclipse.jpt.jaxb.core.context.XmlIDREF; import org.eclipse.jpt.jaxb.core.context.XmlJavaTypeAdapter; import org.eclipse.jpt.jaxb.core.context.XmlList; import org.eclipse.jpt.jaxb.core.context.XmlSchemaType; import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceAnnotatedElement; import org.eclipse.jpt.jaxb.core.resource.java.JaxbContainmentAnnotation; +import org.eclipse.jpt.jaxb.core.resource.java.XmlAttachmentRefAnnotation; import org.eclipse.jpt.jaxb.core.resource.java.XmlIDAnnotation; +import org.eclipse.jpt.jaxb.core.resource.java.XmlIDREFAnnotation; import org.eclipse.jpt.jaxb.core.resource.java.XmlJavaTypeAdapterAnnotation; import org.eclipse.jpt.jaxb.core.resource.java.XmlListAnnotation; import org.eclipse.jpt.jaxb.core.resource.java.XmlSchemaTypeAnnotation; @@ -49,6 +53,10 @@ public abstract class GenericJavaContainmentMapping<A extends JaxbContainmentAnn protected XmlID xmlID; + protected XmlIDREF xmlIDREF; + + protected XmlAttachmentRef xmlAttachmentRef; + public GenericJavaContainmentMapping(JaxbPersistentAttribute parent) { super(parent); this.specifiedName = buildSpecifiedName(); @@ -58,6 +66,8 @@ public abstract class GenericJavaContainmentMapping<A extends JaxbContainmentAnn this.initializeXmlSchemaType(); this.initializeXmlList(); this.initializeXmlID(); + this.initializeXmlIDREF(); + this.initializeXmlAttachmentRef(); } @Override @@ -70,6 +80,8 @@ public abstract class GenericJavaContainmentMapping<A extends JaxbContainmentAnn this.syncXmlSchemaType(); this.syncXmlList(); this.syncXmlID(); + this.syncXmlIDREF(); + this.syncXmlAttachmentRef(); } @Override @@ -79,6 +91,8 @@ public abstract class GenericJavaContainmentMapping<A extends JaxbContainmentAnn this.updateXmlSchemaType(); this.updateXmlList(); this.updateXmlID(); + this.updateXmlIDREF(); + this.updateXmlAttachmentRef(); } @@ -406,7 +420,143 @@ public abstract class GenericJavaContainmentMapping<A extends JaxbContainmentAnn protected void setXmlID_(XmlID xmlID) { XmlID oldXmlID = this.xmlID; this.xmlID = xmlID; - firePropertyChanged(XML_LIST_PROPERTY, oldXmlID, xmlID); + firePropertyChanged(XML_ID_PROPERTY, oldXmlID, xmlID); + } + + + //************ XmlIDREF *************** + + public XmlIDREF getXmlIDREF() { + return this.xmlIDREF; + } + + public XmlIDREF addXmlIDREF() { + if (this.xmlIDREF != null) { + throw new IllegalStateException(); + } + XmlIDREFAnnotation annotation = (XmlIDREFAnnotation) this.getJavaResourceAttribute().addAnnotation(XmlIDREFAnnotation.ANNOTATION_NAME); + + XmlIDREF xmlIDREF = this.buildXmlIDREF(annotation); + this.setXmlIDREF_(xmlIDREF); + return xmlIDREF; + } + + protected XmlIDREF buildXmlIDREF(XmlIDREFAnnotation xmlIDREFAnnotation) { + return new GenericJavaXmlIDREF(this, xmlIDREFAnnotation); + } + + public void removeXmlIDREF() { + if (this.xmlIDREF == null) { + throw new IllegalStateException(); + } + this.getJavaResourceAttribute().removeAnnotation(XmlIDREFAnnotation.ANNOTATION_NAME); + this.setXmlIDREF_(null); + } + + protected void initializeXmlIDREF() { + XmlIDREFAnnotation annotation = this.getXmlIDREFAnnotation(); + if (annotation != null) { + this.xmlIDREF = this.buildXmlIDREF(annotation); + } + } + + protected XmlIDREFAnnotation getXmlIDREFAnnotation() { + return (XmlIDREFAnnotation) this.getJavaResourceAttribute().getAnnotation(XmlIDREFAnnotation.ANNOTATION_NAME); + } + + protected void syncXmlIDREF() { + XmlIDREFAnnotation annotation = this.getXmlIDREFAnnotation(); + if (annotation != null) { + if (this.getXmlIDREF() != null) { + this.getXmlIDREF().synchronizeWithResourceModel(); + } + else { + this.setXmlIDREF_(this.buildXmlIDREF(annotation)); + } + } + else { + this.setXmlIDREF_(null); + } + } + + protected void updateXmlIDREF() { + if (this.getXmlIDREF() != null) { + this.getXmlIDREF().update(); + } + } + + protected void setXmlIDREF_(XmlIDREF xmlIDREF) { + XmlIDREF oldXmlIDREF = this.xmlIDREF; + this.xmlIDREF = xmlIDREF; + firePropertyChanged(XML_IDREF_PROPERTY, oldXmlIDREF, xmlIDREF); + } + + + //************ XmlAttachmentRef *************** + + public XmlAttachmentRef getXmlAttachmentRef() { + return this.xmlAttachmentRef; + } + + public XmlAttachmentRef addXmlAttachmentRef() { + if (this.xmlAttachmentRef != null) { + throw new IllegalStateException(); + } + XmlAttachmentRefAnnotation annotation = (XmlAttachmentRefAnnotation) this.getJavaResourceAttribute().addAnnotation(XmlAttachmentRefAnnotation.ANNOTATION_NAME); + + XmlAttachmentRef xmlAttachmentRef = this.buildXmlAttachmentRef(annotation); + this.setXmlAttachmentRef_(xmlAttachmentRef); + return xmlAttachmentRef; + } + + protected XmlAttachmentRef buildXmlAttachmentRef(XmlAttachmentRefAnnotation xmlAttachmentRefAnnotation) { + return new GenericJavaXmlAttachmentRef(this, xmlAttachmentRefAnnotation); + } + + public void removeXmlAttachmentRef() { + if (this.xmlAttachmentRef == null) { + throw new IllegalStateException(); + } + this.getJavaResourceAttribute().removeAnnotation(XmlAttachmentRefAnnotation.ANNOTATION_NAME); + this.setXmlAttachmentRef_(null); + } + + protected void initializeXmlAttachmentRef() { + XmlAttachmentRefAnnotation annotation = this.getXmlAttachmentRefAnnotation(); + if (annotation != null) { + this.xmlAttachmentRef = this.buildXmlAttachmentRef(annotation); + } + } + + protected XmlAttachmentRefAnnotation getXmlAttachmentRefAnnotation() { + return (XmlAttachmentRefAnnotation) this.getJavaResourceAttribute().getAnnotation(XmlAttachmentRefAnnotation.ANNOTATION_NAME); + } + + protected void syncXmlAttachmentRef() { + XmlAttachmentRefAnnotation annotation = this.getXmlAttachmentRefAnnotation(); + if (annotation != null) { + if (this.getXmlAttachmentRef() != null) { + this.getXmlAttachmentRef().synchronizeWithResourceModel(); + } + else { + this.setXmlAttachmentRef_(this.buildXmlAttachmentRef(annotation)); + } + } + else { + this.setXmlAttachmentRef_(null); + } + } + + protected void updateXmlAttachmentRef() { + if (this.getXmlAttachmentRef() != null) { + this.getXmlAttachmentRef().update(); + } + } + + protected void setXmlAttachmentRef_(XmlAttachmentRef xmlAttachmentRef) { + XmlAttachmentRef oldXmlAttachmentRef = this.xmlAttachmentRef; + this.xmlAttachmentRef = xmlAttachmentRef; + firePropertyChanged(XML_ATTACHMENT_REF_PROPERTY, oldXmlAttachmentRef, xmlAttachmentRef); } @@ -444,5 +594,11 @@ public abstract class GenericJavaContainmentMapping<A extends JaxbContainmentAnn if (this.xmlID != null) { this.xmlID.validate(messages, reporter, astRoot); } + if (this.xmlIDREF != null) { + this.xmlIDREF.validate(messages, reporter, astRoot); + } + if (this.xmlAttachmentRef != null) { + this.xmlAttachmentRef.validate(messages, reporter, astRoot); + } } } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaPersistentClass.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaPersistentClass.java index 9de29b3452..9960bbed2d 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaPersistentClass.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaPersistentClass.java @@ -688,4 +688,8 @@ public class GenericJavaPersistentClass } }; } + + public boolean containsXmlId() { + return !CollectionTools.isEmpty(getContainmentMappingsWithXmlID()); + } } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlAttachmentRef.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlAttachmentRef.java new file mode 100644 index 0000000000..f6de872df5 --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlAttachmentRef.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * 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 org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jpt.common.core.utility.TextRange; +import org.eclipse.jpt.jaxb.core.context.JaxbAttributeMapping; +import org.eclipse.jpt.jaxb.core.context.JaxbPersistentAttribute; +import org.eclipse.jpt.jaxb.core.context.XmlAttachmentRef; +import org.eclipse.jpt.jaxb.core.resource.java.XmlAttachmentRefAnnotation; + +public class GenericJavaXmlAttachmentRef + extends AbstractJavaContextNode + implements XmlAttachmentRef +{ + + protected final XmlAttachmentRefAnnotation resourceXmlAttachmentRef; + + public GenericJavaXmlAttachmentRef(JaxbAttributeMapping parent, XmlAttachmentRefAnnotation resource) { + super(parent); + this.resourceXmlAttachmentRef = resource; + } + + @Override + public JaxbAttributeMapping getParent() { + return (JaxbAttributeMapping) super.getParent(); + } + + protected JaxbPersistentAttribute getPersistentAttribute() { + return getParent().getParent(); + } + + @Override + public TextRange getValidationTextRange(CompilationUnit astRoot) { + return this.resourceXmlAttachmentRef.getTextRange(astRoot); + } +} diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlIDREF.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlIDREF.java new file mode 100644 index 0000000000..91e31f80d8 --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlIDREF.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * 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.core.utility.TextRange; +import org.eclipse.jpt.jaxb.core.context.JaxbAttributeMapping; +import org.eclipse.jpt.jaxb.core.context.JaxbPersistentAttribute; +import org.eclipse.jpt.jaxb.core.context.JaxbPersistentClass; +import org.eclipse.jpt.jaxb.core.context.XmlIDREF; +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.XmlIDREFAnnotation; +import org.eclipse.wst.validation.internal.provisional.core.IMessage; +import org.eclipse.wst.validation.internal.provisional.core.IReporter; + +public class GenericJavaXmlIDREF + extends AbstractJavaContextNode + implements XmlIDREF +{ + + protected final XmlIDREFAnnotation resourceXmlIDREF; + + public GenericJavaXmlIDREF(JaxbAttributeMapping parent, XmlIDREFAnnotation resource) { + super(parent); + this.resourceXmlIDREF = resource; + } + + @Override + public JaxbAttributeMapping getParent() { + return (JaxbAttributeMapping) super.getParent(); + } + + protected JaxbPersistentAttribute getPersistentAttribute() { + return getParent().getParent(); + } + + + //************* validation **************** + /** + * From the JAXB spec section 8.9.12 XmlIDREF: + * <p> + * The following mapping constraints must be enforced:<ul> + * <li> If the type of the field or property is a collection type, then the collection + * item type must contain a property or field annotated with @XmlID. + * <li> If the field or property is not a collection type, then the type of the + * property or field must contain a property or field annotated with @XmlID. + * </ul> + * <p> + * Note: If the collection item type or the type of the property (for non collection type) + * is java.lang.Object, then the instance must contain a property/field annotated with @XmlID attribute. + */ + @Override + public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { + super.validate(messages, reporter, astRoot); + if (getPersistentAttribute().getJavaResourceAttributeTypeName() == Object.class.getName()) { + //The instance must contain a property/field annotated with @XmlID attribute, but we cannot validate the instance + return; + } + String typeName = getPersistentAttribute().getJavaResourceAttributeTypeName(); + JaxbPersistentClass persistentClass = getContextRoot().getPersistentClass(typeName); + if (persistentClass != null) { + if (!persistentClass.containsXmlId()) { + messages.add( + DefaultValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + JaxbValidationMessages.XML_IDREF_TYPE_DOES_NOT_CONTAIN_XML_ID, + new String[] {getPersistentAttribute().getName(), typeName}, + this, + getValidationTextRange(astRoot))); + } + } + else { + //do we validate this case?? + } + } + + @Override + public TextRange getValidationTextRange(CompilationUnit astRoot) { + return this.resourceXmlIDREF.getTextRange(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 9036c747c1..ee5ac49471 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 @@ -41,4 +41,5 @@ public interface JaxbValidationMessages { String XML_ANY_ATTRIBUTE_MAPPING_DEFINED_ON_NON_MAP = "XML_ANY_ATTRIBUTE_MAPPING_DEFINED_ON_NON_MAP"; String XML_ID_DEFINED_ON_NON_STRING = "XML_ID_DEFINED_ON_NON_STRING"; String MULTIPLE_XML_IDS_DEFINED = "MULTIPLE_XML_IDS_DEFINED"; + String XML_IDREF_TYPE_DOES_NOT_CONTAIN_XML_ID = "XML_IDREF_TYPE_DOES_NOT_CONTAIN_XML_ID"; } diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlAttributeMappingTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlAttributeMappingTests.java index 9e77cac46f..7a491a8890 100644 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlAttributeMappingTests.java +++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlAttributeMappingTests.java @@ -26,9 +26,11 @@ import org.eclipse.jpt.jaxb.core.context.XmlAttributeMapping; import org.eclipse.jpt.jaxb.core.context.XmlElementMapping; import org.eclipse.jpt.jaxb.core.resource.java.JAXB; import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceAttribute; +import org.eclipse.jpt.jaxb.core.resource.java.XmlAttachmentRefAnnotation; import org.eclipse.jpt.jaxb.core.resource.java.XmlAttributeAnnotation; import org.eclipse.jpt.jaxb.core.resource.java.XmlElementAnnotation; import org.eclipse.jpt.jaxb.core.resource.java.XmlIDAnnotation; +import org.eclipse.jpt.jaxb.core.resource.java.XmlIDREFAnnotation; import org.eclipse.jpt.jaxb.core.resource.java.XmlJavaTypeAdapterAnnotation; import org.eclipse.jpt.jaxb.core.resource.java.XmlListAnnotation; import org.eclipse.jpt.jaxb.core.resource.java.XmlSchemaTypeAnnotation; @@ -491,4 +493,115 @@ public class GenericJavaXmlAttributeMappingTests extends JaxbContextModelTestCas assertNull(xmlIDAnnotation); } + public void testModifyXmlIDREF() throws Exception { + createTypeWithXmlAttribute(); + + JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); + JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); + XmlAttributeMapping xmlAttributeMapping = (XmlAttributeMapping) persistentAttribute.getMapping(); + JavaResourceAttribute resourceAttribute = xmlAttributeMapping.getParent().getJavaResourceAttribute(); + + XmlIDREFAnnotation xmlIDREFAnnotation = (XmlIDREFAnnotation) resourceAttribute.getAnnotation(XmlIDREFAnnotation.ANNOTATION_NAME); + assertNull(xmlAttributeMapping.getXmlIDREF()); + assertNull(xmlIDREFAnnotation); + + xmlAttributeMapping.addXmlIDREF(); + xmlIDREFAnnotation = (XmlIDREFAnnotation) resourceAttribute.getAnnotation(XmlIDREFAnnotation.ANNOTATION_NAME); + assertNotNull(xmlAttributeMapping.getXmlIDREF()); + assertNotNull(xmlIDREFAnnotation); + + xmlAttributeMapping.removeXmlIDREF(); + xmlIDREFAnnotation = (XmlIDREFAnnotation) resourceAttribute.getAnnotation(XmlIDREFAnnotation.ANNOTATION_NAME); + } + + public void testUpdateXmlIDREF() throws Exception { + createTypeWithXmlAttribute(); + + JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); + JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); + XmlAttributeMapping xmlAttributeMapping = (XmlAttributeMapping) persistentAttribute.getMapping(); + JavaResourceAttribute resourceAttribute = xmlAttributeMapping.getParent().getJavaResourceAttribute(); + + XmlIDREFAnnotation xmlIDREFAnnotation = (XmlIDREFAnnotation) resourceAttribute.getAnnotation(XmlIDREFAnnotation.ANNOTATION_NAME); + assertNull(xmlAttributeMapping.getXmlIDREF()); + assertNull(xmlIDREFAnnotation); + + + //add an XmlIDREF annotation + AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute); + annotatedElement.edit(new Member.Editor() { + public void edit(ModifiedDeclaration declaration) { + GenericJavaXmlAttributeMappingTests.this.addMarkerAnnotation(declaration.getDeclaration(), XmlIDREFAnnotation.ANNOTATION_NAME); + } + }); + xmlIDREFAnnotation = (XmlIDREFAnnotation) resourceAttribute.getAnnotation(XmlIDREFAnnotation.ANNOTATION_NAME); + assertNotNull(xmlAttributeMapping.getXmlIDREF()); + assertNotNull(xmlIDREFAnnotation); + + //remove the XmlIDREF annotation + annotatedElement.edit(new Member.Editor() { + public void edit(ModifiedDeclaration declaration) { + GenericJavaXmlAttributeMappingTests.this.removeAnnotation(declaration, XmlIDREFAnnotation.ANNOTATION_NAME); + } + }); + xmlIDREFAnnotation = (XmlIDREFAnnotation) resourceAttribute.getAnnotation(XmlIDREFAnnotation.ANNOTATION_NAME); + assertNull(xmlAttributeMapping.getXmlIDREF()); + assertNull(xmlIDREFAnnotation); + } + + public void testModifyXmlAttachmentRef() throws Exception { + createTypeWithXmlAttribute(); + + JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); + JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); + XmlAttributeMapping xmlAttributeMapping = (XmlAttributeMapping) persistentAttribute.getMapping(); + JavaResourceAttribute resourceAttribute = xmlAttributeMapping.getParent().getJavaResourceAttribute(); + + XmlAttachmentRefAnnotation xmlAttachmentRefAnnotation = (XmlAttachmentRefAnnotation) resourceAttribute.getAnnotation(XmlAttachmentRefAnnotation.ANNOTATION_NAME); + assertNull(xmlAttributeMapping.getXmlAttachmentRef()); + assertNull(xmlAttachmentRefAnnotation); + + xmlAttributeMapping.addXmlAttachmentRef(); + xmlAttachmentRefAnnotation = (XmlAttachmentRefAnnotation) resourceAttribute.getAnnotation(XmlAttachmentRefAnnotation.ANNOTATION_NAME); + assertNotNull(xmlAttributeMapping.getXmlAttachmentRef()); + assertNotNull(xmlAttachmentRefAnnotation); + + xmlAttributeMapping.removeXmlAttachmentRef(); + xmlAttachmentRefAnnotation = (XmlAttachmentRefAnnotation) resourceAttribute.getAnnotation(XmlAttachmentRefAnnotation.ANNOTATION_NAME); + } + + public void testUpdateXmlAttachmentRef() throws Exception { + createTypeWithXmlAttribute(); + + JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); + JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); + XmlAttributeMapping xmlAttributeMapping = (XmlAttributeMapping) persistentAttribute.getMapping(); + JavaResourceAttribute resourceAttribute = xmlAttributeMapping.getParent().getJavaResourceAttribute(); + + XmlAttachmentRefAnnotation xmlAttachmentRefAnnotation = (XmlAttachmentRefAnnotation) resourceAttribute.getAnnotation(XmlAttachmentRefAnnotation.ANNOTATION_NAME); + assertNull(xmlAttributeMapping.getXmlAttachmentRef()); + assertNull(xmlAttachmentRefAnnotation); + + + //add an XmlAttachmentRef annotation + AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute); + annotatedElement.edit(new Member.Editor() { + public void edit(ModifiedDeclaration declaration) { + GenericJavaXmlAttributeMappingTests.this.addMarkerAnnotation(declaration.getDeclaration(), XmlAttachmentRefAnnotation.ANNOTATION_NAME); + } + }); + xmlAttachmentRefAnnotation = (XmlAttachmentRefAnnotation) resourceAttribute.getAnnotation(XmlAttachmentRefAnnotation.ANNOTATION_NAME); + assertNotNull(xmlAttributeMapping.getXmlAttachmentRef()); + assertNotNull(xmlAttachmentRefAnnotation); + + //remove the XmlAttachmentRef annotation + annotatedElement.edit(new Member.Editor() { + public void edit(ModifiedDeclaration declaration) { + GenericJavaXmlAttributeMappingTests.this.removeAnnotation(declaration, XmlAttachmentRefAnnotation.ANNOTATION_NAME); + } + }); + xmlAttachmentRefAnnotation = (XmlAttachmentRefAnnotation) resourceAttribute.getAnnotation(XmlAttachmentRefAnnotation.ANNOTATION_NAME); + assertNull(xmlAttributeMapping.getXmlAttachmentRef()); + assertNull(xmlAttachmentRefAnnotation); + } }
\ No newline at end of file diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlElementMappingTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlElementMappingTests.java index 3e8d35e408..d224e5ff0f 100644 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlElementMappingTests.java +++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlElementMappingTests.java @@ -26,10 +26,12 @@ import org.eclipse.jpt.jaxb.core.context.XmlAttributeMapping; import org.eclipse.jpt.jaxb.core.context.XmlElementMapping; import org.eclipse.jpt.jaxb.core.resource.java.JAXB; import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceAttribute; +import org.eclipse.jpt.jaxb.core.resource.java.XmlAttachmentRefAnnotation; import org.eclipse.jpt.jaxb.core.resource.java.XmlAttributeAnnotation; import org.eclipse.jpt.jaxb.core.resource.java.XmlElementAnnotation; import org.eclipse.jpt.jaxb.core.resource.java.XmlElementWrapperAnnotation; import org.eclipse.jpt.jaxb.core.resource.java.XmlIDAnnotation; +import org.eclipse.jpt.jaxb.core.resource.java.XmlIDREFAnnotation; import org.eclipse.jpt.jaxb.core.resource.java.XmlJavaTypeAdapterAnnotation; import org.eclipse.jpt.jaxb.core.resource.java.XmlListAnnotation; import org.eclipse.jpt.jaxb.core.resource.java.XmlSchemaTypeAnnotation; @@ -708,4 +710,116 @@ public class GenericJavaXmlElementMappingTests extends JaxbContextModelTestCase assertNull(xmlIDAnnotation); } + public void testModifyXmlIDREF() throws Exception { + createTypeWithXmlElement(); + + JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); + JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); + XmlElementMapping xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping(); + JavaResourceAttribute resourceAttribute = xmlElementMapping.getParent().getJavaResourceAttribute(); + + XmlIDREFAnnotation xmlIDREFAnnotation = (XmlIDREFAnnotation) resourceAttribute.getAnnotation(XmlIDREFAnnotation.ANNOTATION_NAME); + assertNull(xmlElementMapping.getXmlIDREF()); + assertNull(xmlIDREFAnnotation); + + xmlElementMapping.addXmlIDREF(); + xmlIDREFAnnotation = (XmlIDREFAnnotation) resourceAttribute.getAnnotation(XmlIDREFAnnotation.ANNOTATION_NAME); + assertNotNull(xmlElementMapping.getXmlIDREF()); + assertNotNull(xmlIDREFAnnotation); + + xmlElementMapping.removeXmlIDREF(); + xmlIDREFAnnotation = (XmlIDREFAnnotation) resourceAttribute.getAnnotation(XmlIDREFAnnotation.ANNOTATION_NAME); + } + + public void testUpdateXmlIDREF() throws Exception { + createTypeWithXmlElement(); + + JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); + JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); + XmlElementMapping xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping(); + JavaResourceAttribute resourceAttribute = xmlElementMapping.getParent().getJavaResourceAttribute(); + + XmlIDREFAnnotation xmlIDREFAnnotation = (XmlIDREFAnnotation) resourceAttribute.getAnnotation(XmlIDREFAnnotation.ANNOTATION_NAME); + assertNull(xmlElementMapping.getXmlIDREF()); + assertNull(xmlIDREFAnnotation); + + + //add an XmlIDREF annotation + AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute); + annotatedElement.edit(new Member.Editor() { + public void edit(ModifiedDeclaration declaration) { + GenericJavaXmlElementMappingTests.this.addMarkerAnnotation(declaration.getDeclaration(), XmlIDREFAnnotation.ANNOTATION_NAME); + } + }); + xmlIDREFAnnotation = (XmlIDREFAnnotation) resourceAttribute.getAnnotation(XmlIDREFAnnotation.ANNOTATION_NAME); + assertNotNull(xmlElementMapping.getXmlIDREF()); + assertNotNull(xmlIDREFAnnotation); + + //remove the XmlIDREF annotation + annotatedElement.edit(new Member.Editor() { + public void edit(ModifiedDeclaration declaration) { + GenericJavaXmlElementMappingTests.this.removeAnnotation(declaration, XmlIDREFAnnotation.ANNOTATION_NAME); + } + }); + xmlIDREFAnnotation = (XmlIDREFAnnotation) resourceAttribute.getAnnotation(XmlIDREFAnnotation.ANNOTATION_NAME); + assertNull(xmlElementMapping.getXmlIDREF()); + assertNull(xmlIDREFAnnotation); + } + + public void testModifyXmlAttachmentRef() throws Exception { + createTypeWithXmlElement(); + + JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); + JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); + XmlElementMapping xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping(); + JavaResourceAttribute resourceAttribute = xmlElementMapping.getParent().getJavaResourceAttribute(); + + XmlAttachmentRefAnnotation xmlAttachmentRefAnnotation = (XmlAttachmentRefAnnotation) resourceAttribute.getAnnotation(XmlAttachmentRefAnnotation.ANNOTATION_NAME); + assertNull(xmlElementMapping.getXmlAttachmentRef()); + assertNull(xmlAttachmentRefAnnotation); + + xmlElementMapping.addXmlAttachmentRef(); + xmlAttachmentRefAnnotation = (XmlAttachmentRefAnnotation) resourceAttribute.getAnnotation(XmlAttachmentRefAnnotation.ANNOTATION_NAME); + assertNotNull(xmlElementMapping.getXmlAttachmentRef()); + assertNotNull(xmlAttachmentRefAnnotation); + + xmlElementMapping.removeXmlAttachmentRef(); + xmlAttachmentRefAnnotation = (XmlAttachmentRefAnnotation) resourceAttribute.getAnnotation(XmlAttachmentRefAnnotation.ANNOTATION_NAME); + } + + public void testUpdateXmlAttachmentRef() throws Exception { + createTypeWithXmlElement(); + + JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); + JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); + XmlElementMapping xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping(); + JavaResourceAttribute resourceAttribute = xmlElementMapping.getParent().getJavaResourceAttribute(); + + XmlAttachmentRefAnnotation xmlAttachmentRefAnnotation = (XmlAttachmentRefAnnotation) resourceAttribute.getAnnotation(XmlAttachmentRefAnnotation.ANNOTATION_NAME); + assertNull(xmlElementMapping.getXmlAttachmentRef()); + assertNull(xmlAttachmentRefAnnotation); + + + //add an XmlAttachmentRef annotation + AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute); + annotatedElement.edit(new Member.Editor() { + public void edit(ModifiedDeclaration declaration) { + GenericJavaXmlElementMappingTests.this.addMarkerAnnotation(declaration.getDeclaration(), XmlAttachmentRefAnnotation.ANNOTATION_NAME); + } + }); + xmlAttachmentRefAnnotation = (XmlAttachmentRefAnnotation) resourceAttribute.getAnnotation(XmlAttachmentRefAnnotation.ANNOTATION_NAME); + assertNotNull(xmlElementMapping.getXmlAttachmentRef()); + assertNotNull(xmlAttachmentRefAnnotation); + + //remove the XmlAttachmentRef annotation + annotatedElement.edit(new Member.Editor() { + public void edit(ModifiedDeclaration declaration) { + GenericJavaXmlElementMappingTests.this.removeAnnotation(declaration, XmlAttachmentRefAnnotation.ANNOTATION_NAME); + } + }); + xmlAttachmentRefAnnotation = (XmlAttachmentRefAnnotation) resourceAttribute.getAnnotation(XmlAttachmentRefAnnotation.ANNOTATION_NAME); + assertNull(xmlElementMapping.getXmlAttachmentRef()); + assertNull(xmlAttachmentRefAnnotation); + } + }
\ No newline at end of file |