diff options
author | pfullbright | 2011-10-18 17:32:04 +0000 |
---|---|---|
committer | pfullbright | 2011-10-18 17:32:04 +0000 |
commit | 8163bc3ac991ac70ee303e6f3a6ae56eebb6010d (patch) | |
tree | 0a6b5837bfebfc7c00270c37a878eab53807fcd9 /jaxb/plugins/org.eclipse.jpt.jaxb.core | |
parent | fcc396c05a706c3e04216d4f78763787174b5aa1 (diff) | |
download | webtools.dali-8163bc3ac991ac70ee303e6f3a6ae56eebb6010d.tar.gz webtools.dali-8163bc3ac991ac70ee303e6f3a6ae56eebb6010d.tar.xz webtools.dali-8163bc3ac991ac70ee303e6f3a6ae56eebb6010d.zip |
support for included attributes
Diffstat (limited to 'jaxb/plugins/org.eclipse.jpt.jaxb.core')
10 files changed, 329 insertions, 205 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 827b3134dd..9ea4973509 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 @@ -25,6 +25,11 @@ ATTRIBUTE_MAPPING__UNSUPPORTED_ANNOTATION = The annotation ''{0}'' is not allowe 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_ANY_ATTRIBUTE__MULTIPLE_MAPPINGS_DEFINED = Multiple attributes are annotated with @XmlAnyAttribute. At most one field or property per class is allowed. +XML_ANY_ATTRIBUTE__NON_MAP_TYPE = The type of a field or property annotated with @XmlAnyAttribute must be assignable to java.util.Map. + +XML_ANY_ELEMENT__MULTIPLE_MAPPINGS_DEFINED = Multiple attributes are annotated with @XmlAnyElement. At most one field or property per class is allowed. + XML_ELEMENT__UNSPECIFIED_TYPE = Unspecified XML element type. XML_ELEMENT__ILLEGAL_TYPE = XML element type must be a sub-type of ''{0}''. @@ -45,17 +50,16 @@ XML_ELEMENT_REFS__DUPLICATE_XML_ELEMENT_QNAME = Duplicate element name ''{0}''in 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_ID__MULTIPLE_MAPPINGS_DEFINED = Multiple attributes are annotated with @XmlID. At most one field or property per class is allowed. +XML_ID_DEFINED_ON_NON_STRING = XmlID is only allowed on a java.lang.String property + XML_REGISTRY__DUPLICATE_XML_ELEMENT_QNAME = Duplicate XML element decl name ''{0}'' {1}. +XML_VALUE__MULTIPLE_MAPPINGS_DEFINED = Multiple attributes are annotated with @XmlValue. At most one field or property per class is allowed. +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_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. XML_LIST_DEFINED_ON_NON_ARRAY_NON_COLLECTION = Only a collection or array property may be mapped as an XML list. -MULTIPLE_XML_ANY_ELEMENT_MAPPINGS_DEFINED = Attribute ''{0}'' cannot be mapped as XmlAnyElement because attribute ''{1}'' is already mapped as XmlAnyElement, cannot define multiple XmlAnyElement mappings -MULTIPLE_XML_ANY_ATTRIBUTE_MAPPINGS_DEFINED = Attribute ''{0}'' cannot be mapped as XmlAnyAttribute because attribute ''{1}'' is already mapped as XmlAnyAttribute, cannot define multiple XmlAnyAttribute mappings -MULTIPLE_XML_VALUE_MAPPINGS_DEFINED = Attribute ''{0}'' cannot be mapped as XmlValue because attribute ''{1}'' is already mapped as XmlValue, cannot define multiple XmlValue mappings -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 QNAME__MISSING_NAME = {0} name not specified QNAME__UNRESOLVED_COMPONENT = Cannot resolve {0} with namespace ''{1}'' and name ''{2}'' in this context
\ No newline at end of file diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbAttributesContainer.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbAttributesContainer.java index e5a9ebcb3a..5f9e757bcd 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbAttributesContainer.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbAttributesContainer.java @@ -36,23 +36,6 @@ public interface JaxbAttributesContainer /********** attributes **********/ Iterable<JaxbPersistentAttribute> getAttributes(); - int getAttributesSize(); - interface Owner { - - /** - * Return the access type of the owner, to be used in determining which attributes to build - */ - XmlAccessType getAccessType(); - - /** - * fire property change event for the added attribute - */ - void fireAttributeAdded(JaxbPersistentAttribute attribute); - - /** - * fire property change event for the removed attribute - */ - void fireAttributeRemoved(JaxbPersistentAttribute attribute); - } + int getAttributesSize(); } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbClassMapping.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbClassMapping.java index 8018e07349..74533f0794 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbClassMapping.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbClassMapping.java @@ -80,32 +80,30 @@ public interface JaxbClassMapping int getAttributesSize(); - // ***** inherited attributes ***** + // ***** included attributes ***** - String INHERITED_ATTRIBUTES_COLLECTION = "inheritedAttributes"; //$NON-NLS-1$ + String INCLUDED_ATTRIBUTES_COLLECTION = "includedAttributes"; //$NON-NLS-1$ /** - * Inherited attributes come from any direct superclasses that are mapped as @XmlTransient. - * (If there is an intervening class that is not transient, then that class will hold any - * inherited attributes from anything further up the hierarchy.) + * <i>Included</i> attributes come from any direct superclasses that are mapped as @XmlTransient. + * (As opposed to <i>inherited</i> attributes, which a class has by way of <i>any</i> mapped superclasses.) + * If there is an intervening class that is not transient, then that class will hold any + * included attributes from any direct superclass that are mapped as @XmlTransient. * @see JaxbClassMapping#getSuperclass() */ - Iterable<JaxbPersistentAttribute> getInheritedAttributes(); + Iterable<JaxbPersistentAttribute> getIncludedAttributes(); - int getInheritedAttributesSize(); - - /** - * Return true if the given attribute is one of the inherited attributes. - */ - boolean isInherited(JaxbPersistentAttribute attribute); + int getIncludedAttributesSize(); + + + // ***** inherited attributes ***** /** - * Only ask this of inherited persistent attributes. Returns the simple - * type name of the attribute's resource type. - * - * @see JaxbPersistentAttribute#isInherited() + * <i>Inherited</i> attributes are any attributes this class mapping has whose source + * is a superclass. + * Inherited attributes include <i>included</i> attributes. */ - String getJavaResourceAttributeOwningTypeName(JaxbPersistentAttribute attribute); + Iterable<JaxbPersistentAttribute> getInheritedAttributes(); // ***** misc ***** diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbPersistentAttribute.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbPersistentAttribute.java index 34f8e624e7..786fa81671 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbPersistentAttribute.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbPersistentAttribute.java @@ -12,6 +12,7 @@ package org.eclipse.jpt.jaxb.core.context; import org.eclipse.jpt.common.core.resource.java.JavaResourceAttribute; import org.eclipse.jpt.common.core.resource.java.JavaResourceField; import org.eclipse.jpt.common.core.resource.java.JavaResourceMethod; +import org.eclipse.jpt.common.core.resource.java.JavaResourceType; import org.eclipse.jpt.jaxb.core.context.java.JavaContextNode; /** @@ -31,22 +32,22 @@ public interface JaxbPersistentAttribute JaxbClassMapping getJaxbClassMapping(); + + // ***** declaring class/ inheritance ***** + /** - * Return true if this JaxbPersistentAttribute is inherited from one of the - * superclasses of the parent JaxbPersistentClass. + * Return the resource type where the source of the attribute is declared. + * This may not be where the attribute is fully defined, as it may be inherited */ - boolean isInherited(); + JavaResourceType getDeclaringJavaResourceType(); /** - * Only ask this of inherited persistent attributes. Returns the simple - * type name of the attribute's resource type. - * - * @see JaxbPersistentAttribute#isInherited() + * Return true if the source of the attribute is defined in a superclass */ - String getInheritedJavaResourceAttributeOwningTypeName(); + boolean isInherited(); - // ********** name ********** + // ***** name ***** /** * Return the name of the attribute. This will not change, a @@ -54,9 +55,8 @@ public interface JaxbPersistentAttribute */ String getName(); - boolean isFor(JavaResourceField resourceField); - boolean isFor(JavaResourceMethod resourceGetter, JavaResourceMethod resourceSetter); + // ***** resource attribute ***** JavaResourceAttribute getJavaResourceAttribute(); @@ -78,6 +78,10 @@ public interface JaxbPersistentAttribute */ boolean isJavaResourceAttributeTypeSubTypeOf(String typeName); + boolean isFor(JavaResourceField resourceField); + + boolean isFor(JavaResourceMethod resourceGetter, JavaResourceMethod resourceSetter); + // ********** mapping ********** diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/AbstractJavaTypeMapping.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/AbstractJavaTypeMapping.java index 7687e31f0e..d082e261e9 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/AbstractJavaTypeMapping.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/AbstractJavaTypeMapping.java @@ -286,9 +286,12 @@ public abstract class AbstractJavaTypeMapping // ***** misc ***** public final Iterable<String> getReferencedXmlTypeNames() { - if (! this.xmlTransient) { - return getNonTransientReferencedXmlTypeNames(); - } + return (this.xmlTransient) ? + getTransientReferencedXmlTypeNames() + : getNonTransientReferencedXmlTypeNames(); + } + + protected Iterable<String> getTransientReferencedXmlTypeNames() { return EmptyIterable.instance(); } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaAttributesContainer.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaAttributesContainer.java index 3b210a13f4..1c609bcf7d 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaAttributesContainer.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaAttributesContainer.java @@ -40,11 +40,11 @@ public class GenericJavaAttributesContainer protected JavaResourceType javaResourceType; - protected JaxbAttributesContainer.Owner owner; + protected Owner owner; protected final Vector<JaxbPersistentAttribute> attributes = new Vector<JaxbPersistentAttribute>(); - public GenericJavaAttributesContainer(JaxbClassMapping parent, JaxbAttributesContainer.Owner owner, JavaResourceType resourceType) { + public GenericJavaAttributesContainer(JaxbClassMapping parent, Owner owner, JavaResourceType resourceType) { super(parent); this.javaResourceType = resourceType; this.owner = owner; @@ -113,6 +113,9 @@ public class GenericJavaAttributesContainer } protected void initializeAttributes() { + if (getJaxbClassMapping().isXmlTransient()) { + return; + } if (getAccessType() == XmlAccessType.PUBLIC_MEMBER) { this.initializePublicMemberAccessAttributes(); } @@ -318,6 +321,12 @@ public class GenericJavaAttributesContainer * which can be controlled in a number of different places.... */ protected void updateAttributes() { + if (getJaxbClassMapping().isXmlTransient()) { + for (JaxbPersistentAttribute contextAttribute : getAttributes()) { + this.removeAttribute(contextAttribute); + } + return; + } if (getAccessType() == XmlAccessType.PUBLIC_MEMBER) { this.syncPublicMemberAccessAttributes(); } @@ -647,4 +656,23 @@ public class GenericJavaAttributesContainer public TextRange getValidationTextRange(CompilationUnit astRoot) { return getJaxbClassMapping().getValidationTextRange(astRoot); } + + + interface Owner { + + /** + * Return the access type of the owner, to be used in determining which attributes to build + */ + XmlAccessType getAccessType(); + + /** + * fire property change event for the added attribute + */ + void fireAttributeAdded(JaxbPersistentAttribute attribute); + + /** + * fire property change event for the removed attribute + */ + void fireAttributeRemoved(JaxbPersistentAttribute attribute); + } } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaClassMapping.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaClassMapping.java index 12a3dedb7b..099dcee7f8 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaClassMapping.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaClassMapping.java @@ -19,6 +19,7 @@ import org.eclipse.jpt.common.core.internal.utility.JDTTools; import org.eclipse.jpt.common.core.resource.java.JavaResourceType; import org.eclipse.jpt.common.utility.Filter; import org.eclipse.jpt.common.utility.internal.CollectionTools; +import org.eclipse.jpt.common.utility.internal.iterables.ChainIterable; import org.eclipse.jpt.common.utility.internal.iterables.CompositeIterable; import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable; import org.eclipse.jpt.common.utility.internal.iterables.FilteringIterable; @@ -72,11 +73,11 @@ public class GenericJavaClassMapping protected final JaxbAttributesContainer attributesContainer; - protected final Map<JaxbClassMapping, JaxbAttributesContainer> inheritedAttributesContainers; + protected final Map<JaxbClassMapping, JaxbAttributesContainer> includedAttributesContainers; public GenericJavaClassMapping(JaxbClass parent) { super(parent); - this.inheritedAttributesContainers = new HashMap<JaxbClassMapping, JaxbAttributesContainer>(); + this.includedAttributesContainers = new HashMap<JaxbClassMapping, JaxbAttributesContainer>(); this.propOrderContainer = new PropOrderContainer(); initFactoryClass(); @@ -87,7 +88,7 @@ public class GenericJavaClassMapping initSpecifiedAccessOrder(); initDefaultAccessOrder(); this.attributesContainer = new GenericJavaAttributesContainer(this, buildAttributesContainerOwner(), getJavaResourceType()); - initInheritedAttributes(); + initIncludedAttributes(); } @@ -119,7 +120,7 @@ public class GenericJavaClassMapping syncSpecifiedAccessType(); syncSpecifiedAccessOrder(); this.attributesContainer.synchronizeWithResourceModel(); - syncInheritedAttributes(); + syncIncludedAttributes(); } @Override @@ -130,7 +131,7 @@ public class GenericJavaClassMapping updateDefaultAccessOrder(); this.hasRootElementInHierarchy_loaded = false; // triggers that the value must be recalculated on next request this.attributesContainer.update(); - updateInheritedAttributes(); + updateIncludedAttributes(); } @@ -469,8 +470,8 @@ public class GenericJavaClassMapping return this.attributesContainer.getAttributesSize(); } - protected JaxbAttributesContainer.Owner buildAttributesContainerOwner() { - return new JaxbAttributesContainer.Owner() { + protected GenericJavaAttributesContainer.Owner buildAttributesContainerOwner() { + return new GenericJavaAttributesContainer.Owner() { public XmlAccessType getAccessType() { return GenericJavaClassMapping.this.getAccessType(); } @@ -486,15 +487,15 @@ public class GenericJavaClassMapping } - // ***** inherited attributes ***** + // ***** included attributes ***** - public Iterable<JaxbPersistentAttribute> getInheritedAttributes() { - return new CompositeIterable<JaxbPersistentAttribute>(getInheritedAttributeSets()); + public Iterable<JaxbPersistentAttribute> getIncludedAttributes() { + return new CompositeIterable<JaxbPersistentAttribute>(getIncludedAttributeSets()); } - protected Iterable<Iterable<JaxbPersistentAttribute>> getInheritedAttributeSets() { + protected Iterable<Iterable<JaxbPersistentAttribute>> getIncludedAttributeSets() { return new TransformationIterable<JaxbAttributesContainer, Iterable<JaxbPersistentAttribute>>( - getInheritedAttributesContainers()) { + getIncludedAttributesContainers()) { @Override protected Iterable<JaxbPersistentAttribute> transform(JaxbAttributesContainer attributesContainer) { return attributesContainer.getAttributes(); @@ -502,93 +503,93 @@ public class GenericJavaClassMapping }; } - protected Iterable<JaxbAttributesContainer> getInheritedAttributesContainers() { - return new LiveCloneIterable<JaxbAttributesContainer>(this.inheritedAttributesContainers.values()); // read-only + protected Iterable<JaxbAttributesContainer> getIncludedAttributesContainers() { + return new LiveCloneIterable<JaxbAttributesContainer>(this.includedAttributesContainers.values()); // read-only } - public int getInheritedAttributesSize() { + public int getIncludedAttributesSize() { int size = 0; - for (JaxbAttributesContainer attributesContainer : getInheritedAttributesContainers()) { + for (JaxbAttributesContainer attributesContainer : getIncludedAttributesContainers()) { size += attributesContainer.getAttributesSize(); } return size; } - protected void initInheritedAttributes() { + protected void initIncludedAttributes() { + // xml transient classes have no included attributes + if (isXmlTransient()) { + return; + } JaxbClassMapping superclass = this.superclass; // only add inherited attributes for superclasses up until a mapped class is encountered while (superclass != null && superclass.isXmlTransient()) { - this.inheritedAttributesContainers.put(superclass, buildInheritedAttributesContainer(superclass)); + this.includedAttributesContainers.put(superclass, buildIncludedAttributesContainer(superclass)); superclass = superclass.getSuperclass(); } } - protected void syncInheritedAttributes() { - for (JaxbAttributesContainer attributesContainer : this.inheritedAttributesContainers.values()) { + protected void syncIncludedAttributes() { + for (JaxbAttributesContainer attributesContainer : this.includedAttributesContainers.values()) { attributesContainer.synchronizeWithResourceModel(); } } - protected void updateInheritedAttributes() { + protected void updateIncludedAttributes() { HashSet<JaxbClassMapping> oldSuperclasses - = CollectionTools.set(this.inheritedAttributesContainers.keySet()); - Set<JaxbPersistentAttribute> oldAttributes = CollectionTools.set(getInheritedAttributes()); - JaxbClassMapping superclass = this.superclass; - // only add inherited attributes for superclasses up until a mapped class is encountered - while (superclass != null && superclass.isXmlTransient()) { - if (this.inheritedAttributesContainers.containsKey(superclass)) { - this.inheritedAttributesContainers.get(superclass).update(); - oldSuperclasses.remove(superclass); - } - else { - this.inheritedAttributesContainers.put(superclass, buildInheritedAttributesContainer(superclass)); + = CollectionTools.set(this.includedAttributesContainers.keySet()); + Set<JaxbPersistentAttribute> oldAttributes = CollectionTools.set(getIncludedAttributes()); + + if (! isXmlTransient()) { + JaxbClassMapping superclass = this.superclass; + // only add inherited attributes for superclasses up until a mapped class is encountered + while (superclass != null && superclass.isXmlTransient()) { + if (this.includedAttributesContainers.containsKey(superclass)) { + this.includedAttributesContainers.get(superclass).update(); + oldSuperclasses.remove(superclass); + } + else { + this.includedAttributesContainers.put(superclass, buildIncludedAttributesContainer(superclass)); + } + superclass = superclass.getSuperclass(); } - superclass = superclass.getSuperclass(); } for (JaxbClassMapping oldSuperclass : oldSuperclasses) { - this.inheritedAttributesContainers.remove(oldSuperclass); + this.includedAttributesContainers.remove(oldSuperclass); } - Set<JaxbPersistentAttribute> newAttributes = CollectionTools.set(getInheritedAttributes()); + Set<JaxbPersistentAttribute> newAttributes = CollectionTools.set(getIncludedAttributes()); if (CollectionTools.elementsAreDifferent(oldAttributes, newAttributes)) { - fireCollectionChanged(INHERITED_ATTRIBUTES_COLLECTION, newAttributes); + fireCollectionChanged(INCLUDED_ATTRIBUTES_COLLECTION, newAttributes); } } - protected JaxbAttributesContainer buildInheritedAttributesContainer(JaxbClassMapping jaxbClassMapping) { - return new GenericJavaAttributesContainer(this, buildInheritedAttributesContainerOwner(), jaxbClassMapping.getJaxbType().getJavaResourceType()); + protected JaxbAttributesContainer buildIncludedAttributesContainer(JaxbClassMapping jaxbClassMapping) { + return new GenericJavaAttributesContainer(this, buildIncludedAttributesContainerOwner(), jaxbClassMapping.getJaxbType().getJavaResourceType()); } - protected JaxbAttributesContainer.Owner buildInheritedAttributesContainerOwner() { - return new JaxbAttributesContainer.Owner() { + protected GenericJavaAttributesContainer.Owner buildIncludedAttributesContainerOwner() { + return new GenericJavaAttributesContainer.Owner() { public XmlAccessType getAccessType() { return GenericJavaClassMapping.this.getAccessType(); } public void fireAttributeAdded(JaxbPersistentAttribute attribute) { - GenericJavaClassMapping.this.fireItemAdded(INHERITED_ATTRIBUTES_COLLECTION, attribute); + GenericJavaClassMapping.this.fireItemAdded(INCLUDED_ATTRIBUTES_COLLECTION, attribute); } public void fireAttributeRemoved(JaxbPersistentAttribute attribute) { - GenericJavaClassMapping.this.fireItemRemoved(INHERITED_ATTRIBUTES_COLLECTION, attribute); + GenericJavaClassMapping.this.fireItemRemoved(INCLUDED_ATTRIBUTES_COLLECTION, attribute); } }; } - public boolean isInherited(JaxbPersistentAttribute attribute) { - if (attribute.getParent() != this) { - throw new IllegalArgumentException("The attribute is not owned by this JaxbClassMapping"); //$NON-NLS-1$ - } - return ! CollectionTools.contains(this.getAttributes(), attribute); - } - public String getJavaResourceAttributeOwningTypeName(JaxbPersistentAttribute attribute) { if (attribute.getParent() != this) { throw new IllegalArgumentException("The attribute is not owned by this JaxbClassMapping"); //$NON-NLS-1$ } - for (JaxbClassMapping superclass : this.inheritedAttributesContainers.keySet()) { - if (CollectionTools.contains(this.inheritedAttributesContainers.get(superclass).getAttributes(), attribute)) { + for (JaxbClassMapping superclass : this.includedAttributesContainers.keySet()) { + if (CollectionTools.contains(this.includedAttributesContainers.get(superclass).getAttributes(), attribute)) { return superclass.getJaxbType().getSimpleName(); } } @@ -596,6 +597,34 @@ public class GenericJavaClassMapping } + // ***** inherited attributes ***** + + public Iterable<JaxbPersistentAttribute> getInheritedAttributes() { + return new CompositeIterable<JaxbPersistentAttribute>( + getIncludedAttributes(), + getOtherInheritedAttributes()); + } + + /** + * return those inherited attributes that are not included + */ + protected Iterable<JaxbPersistentAttribute> getOtherInheritedAttributes() { + return new CompositeIterable<JaxbPersistentAttribute>( + new TransformationIterable<JaxbClassMapping, Iterable<JaxbPersistentAttribute>>( + new ChainIterable<JaxbClassMapping>(getSuperclass()) { + @Override + protected JaxbClassMapping nextLink(JaxbClassMapping currentLink) { + return currentLink.getSuperclass(); + } + }) { + @Override + protected Iterable<JaxbPersistentAttribute> transform(JaxbClassMapping o) { + return o.getAttributes(); + } + }); + } + + // ***** subClasses ***** @Override @@ -630,6 +659,13 @@ public class GenericJavaClassMapping // ***** misc ***** @Override + protected Iterable<String> getTransientReferencedXmlTypeNames() { + return new CompositeIterable<String>( + super.getTransientReferencedXmlTypeNames(), + new SingleElementIterable(getJavaResourceType().getSuperclassQualifiedName())); + } + + @Override protected Iterable<String> getNonTransientReferencedXmlTypeNames() { return new CompositeIterable<String>( super.getNonTransientReferencedXmlTypeNames(), @@ -722,96 +758,151 @@ public class GenericJavaClassMapping } } - protected void validateXmlValueMapping(List<IMessage> messages, CompilationUnit astRoot) { - String xmlValueMapping = null; + protected void validateXmlAnyAttributeMapping(List<IMessage> messages, CompilationUnit astRoot) { + Set<JaxbPersistentAttribute> localAttributes = new HashSet<JaxbPersistentAttribute>(); + Set<JaxbPersistentAttribute> allAttributes = new HashSet<JaxbPersistentAttribute>(); + for (JaxbPersistentAttribute attribute : getAttributes()) { - if (attribute.getMappingKey() == MappingKeys.XML_VALUE_ATTRIBUTE_MAPPING_KEY) { - if (xmlValueMapping != null) { - messages.add( - DefaultValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JaxbValidationMessages.MULTIPLE_XML_VALUE_MAPPINGS_DEFINED, - new String[] {attribute.getName(), xmlValueMapping}, - attribute.getMapping(), - attribute.getMapping().getValidationTextRange(astRoot))); - } - else { - xmlValueMapping = attribute.getName(); - } + if (attribute.getMappingKey() == MappingKeys.XML_ANY_ATTRIBUTE_ATTRIBUTE_MAPPING_KEY) { + localAttributes.add(attribute); + allAttributes.add(attribute); } } - if (xmlValueMapping != null) { - for (JaxbPersistentAttribute attribute : getAttributes()) { - if (attribute.getName() != xmlValueMapping) { - if (attribute.getMappingKey() != MappingKeys.XML_ATTRIBUTE_ATTRIBUTE_MAPPING_KEY - && attribute.getMappingKey() != MappingKeys.XML_TRANSIENT_ATTRIBUTE_MAPPING_KEY) { - messages.add( - DefaultValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JaxbValidationMessages.XML_VALUE_MAPPING_WITH_NON_XML_ATTRIBUTE_MAPPING_DEFINED, - new String[] {attribute.getName(), xmlValueMapping}, - attribute.getMapping(), - attribute.getMapping().getValidationTextRange(astRoot))); - } - } + + for (JaxbPersistentAttribute attribute : getInheritedAttributes()) { + if (attribute.getMappingKey() == MappingKeys.XML_ANY_ATTRIBUTE_ATTRIBUTE_MAPPING_KEY) { + allAttributes.add(attribute); + } + } + + if (allAttributes.size() > 1) { + messages.add( + DefaultValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + JaxbValidationMessages.XML_ANY_ATTRIBUTE__MULTIPLE_MAPPINGS_DEFINED, + this, + getValidationTextRange(astRoot))); + + for (JaxbPersistentAttribute anyAttribute : localAttributes) { + messages.add( + DefaultValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + JaxbValidationMessages.XML_ANY_ATTRIBUTE__MULTIPLE_MAPPINGS_DEFINED, + anyAttribute.getMapping(), + anyAttribute.getMapping().getValidationTextRange(astRoot))); } } } - protected void validateXmlAnyAttributeMapping(List<IMessage> messages, CompilationUnit astRoot) { - String xmlAnyAttributeMapping = null; + protected void validateXmlAnyElementMapping(List<IMessage> messages, CompilationUnit astRoot) { + Set<JaxbPersistentAttribute> localAttributes = new HashSet<JaxbPersistentAttribute>(); + Set<JaxbPersistentAttribute> allAttributes = new HashSet<JaxbPersistentAttribute>(); + for (JaxbPersistentAttribute attribute : getAttributes()) { - if (attribute.getMappingKey() == MappingKeys.XML_ANY_ATTRIBUTE_ATTRIBUTE_MAPPING_KEY) { - if (xmlAnyAttributeMapping != null) { - messages.add( - DefaultValidationMessages.buildMessage( + if (attribute.getMappingKey() == MappingKeys.XML_ANY_ELEMENT_ATTRIBUTE_MAPPING_KEY) { + localAttributes.add(attribute); + allAttributes.add(attribute); + } + } + + for (JaxbPersistentAttribute attribute : getInheritedAttributes()) { + if (attribute.getMappingKey() == MappingKeys.XML_ANY_ELEMENT_ATTRIBUTE_MAPPING_KEY) { + allAttributes.add(attribute); + } + } + + if (allAttributes.size() > 1) { + messages.add( + DefaultValidationMessages.buildMessage( IMessage.HIGH_SEVERITY, - JaxbValidationMessages.MULTIPLE_XML_ANY_ATTRIBUTE_MAPPINGS_DEFINED, - new String[] {attribute.getName(), xmlAnyAttributeMapping}, - attribute.getMapping(), - attribute.getMapping().getValidationTextRange(astRoot))); - } - else { - xmlAnyAttributeMapping = attribute.getName(); - } + JaxbValidationMessages.XML_ANY_ELEMENT__MULTIPLE_MAPPINGS_DEFINED, + this, + getValidationTextRange(astRoot))); + + for (JaxbPersistentAttribute anyAttribute : localAttributes) { + messages.add( + DefaultValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + JaxbValidationMessages.XML_ANY_ELEMENT__MULTIPLE_MAPPINGS_DEFINED, + anyAttribute.getMapping(), + anyAttribute.getMapping().getValidationTextRange(astRoot))); } } } - protected void validateXmlAnyElementMapping(List<IMessage> messages, CompilationUnit astRoot) { - String xmlAnyElementMapping = null; + protected void validateXmlValueMapping(List<IMessage> messages, CompilationUnit astRoot) { + Set<JaxbPersistentAttribute> localAttributes = new HashSet<JaxbPersistentAttribute>(); + Set<JaxbPersistentAttribute> allAttributes = new HashSet<JaxbPersistentAttribute>(); + for (JaxbPersistentAttribute attribute : getAttributes()) { - if (attribute.getMappingKey() == MappingKeys.XML_ANY_ELEMENT_ATTRIBUTE_MAPPING_KEY) { - if (xmlAnyElementMapping != null) { - messages.add( - DefaultValidationMessages.buildMessage( + if (attribute.getMappingKey() == MappingKeys.XML_VALUE_ATTRIBUTE_MAPPING_KEY) { + localAttributes.add(attribute); + allAttributes.add(attribute); + } + } + + for (JaxbPersistentAttribute attribute : getInheritedAttributes()) { + if (attribute.getMappingKey() == MappingKeys.XML_VALUE_ATTRIBUTE_MAPPING_KEY) { + allAttributes.add(attribute); + } + } + + if (allAttributes.size() > 1) { + messages.add( + DefaultValidationMessages.buildMessage( IMessage.HIGH_SEVERITY, - JaxbValidationMessages.MULTIPLE_XML_ANY_ELEMENT_MAPPINGS_DEFINED, - new String[] {attribute.getName(), xmlAnyElementMapping}, - attribute.getMapping(), - attribute.getMapping().getValidationTextRange(astRoot))); - } - else { - xmlAnyElementMapping = attribute.getName(); - } + JaxbValidationMessages.XML_VALUE__MULTIPLE_MAPPINGS_DEFINED, + this, + getValidationTextRange(astRoot))); + + for (JaxbPersistentAttribute anyAttribute : localAttributes) { + messages.add( + DefaultValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + JaxbValidationMessages.XML_VALUE__MULTIPLE_MAPPINGS_DEFINED, + anyAttribute.getMapping(), + anyAttribute.getMapping().getValidationTextRange(astRoot))); } } } protected void validateXmlIDs(List<IMessage> messages, CompilationUnit astRoot) { - String xmlIdMapping = null; - for (JaxbBasicMapping containmentMapping : getBasicMappingsWithXmlID()) { - if (xmlIdMapping != null) { + + Set<JaxbPersistentAttribute> localAttributes = new HashSet<JaxbPersistentAttribute>(); + Set<JaxbPersistentAttribute> allAttributes = new HashSet<JaxbPersistentAttribute>(); + + for (JaxbPersistentAttribute attribute : getAttributes()) { + if ((attribute.getMappingKey() == MappingKeys.XML_ATTRIBUTE_ATTRIBUTE_MAPPING_KEY + || attribute.getMappingKey() == MappingKeys.XML_ELEMENT_ATTRIBUTE_MAPPING_KEY) + && ((JaxbBasicMapping) attribute.getMapping()).getXmlID() != null) { + localAttributes.add(attribute); + allAttributes.add(attribute); + } + } + + for (JaxbPersistentAttribute attribute : getInheritedAttributes()) { + if ((attribute.getMappingKey() == MappingKeys.XML_ATTRIBUTE_ATTRIBUTE_MAPPING_KEY + || attribute.getMappingKey() == MappingKeys.XML_ELEMENT_ATTRIBUTE_MAPPING_KEY) + && ((JaxbBasicMapping) attribute.getMapping()).getXmlID() != null) { + allAttributes.add(attribute); + } + } + + if (allAttributes.size() > 1) { + messages.add( + DefaultValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + JaxbValidationMessages.XML_ID__MULTIPLE_MAPPINGS_DEFINED, + this, + getValidationTextRange(astRoot))); + + for (JaxbPersistentAttribute anyAttribute : localAttributes) { messages.add( DefaultValidationMessages.buildMessage( IMessage.HIGH_SEVERITY, - JaxbValidationMessages.MULTIPLE_XML_IDS_DEFINED, - new String[] { containmentMapping.getPersistentAttribute().getName(), xmlIdMapping }, - containmentMapping, - containmentMapping.getValidationTextRange(astRoot))); - } - else { - xmlIdMapping = containmentMapping.getPersistentAttribute().getName(); + JaxbValidationMessages.XML_ID__MULTIPLE_MAPPINGS_DEFINED, + anyAttribute.getMapping(), + anyAttribute.getMapping().getValidationTextRange(astRoot))); } } } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaPersistentAttribute.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaPersistentAttribute.java index 1b0caee2f3..ca1b994b48 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaPersistentAttribute.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaPersistentAttribute.java @@ -15,6 +15,7 @@ import org.eclipse.jpt.common.core.resource.java.Annotation; import org.eclipse.jpt.common.core.resource.java.JavaResourceAttribute; import org.eclipse.jpt.common.core.resource.java.JavaResourceField; import org.eclipse.jpt.common.core.resource.java.JavaResourceMethod; +import org.eclipse.jpt.common.core.resource.java.JavaResourceType; import org.eclipse.jpt.common.core.utility.TextRange; import org.eclipse.jpt.common.utility.Filter; import org.eclipse.jpt.common.utility.internal.CollectionTools; @@ -35,24 +36,27 @@ public class GenericJavaPersistentAttribute extends AbstractJavaContextNode implements JaxbPersistentAttribute { + protected final Accessor accessor; + protected JaxbAttributeMapping mapping; // never null protected String defaultMappingKey; - protected final Accessor accessor; public static JaxbPersistentAttribute buildPersistentProperty( - JaxbClassMapping parent, + JaxbClassMapping parent, JavaResourceMethod resourceGetter, JavaResourceMethod resourceSetter) { - return new GenericJavaPersistentAttribute(parent, new PropertyAccessor(parent, resourceGetter, resourceSetter)); + return new GenericJavaPersistentAttribute( + parent, new PropertyAccessor(parent, resourceGetter, resourceSetter)); } public static JaxbPersistentAttribute buildPersistentField( - JaxbClassMapping parent, + JaxbClassMapping parent, JavaResourceField resourceField) { - return new GenericJavaPersistentAttribute(parent, new FieldAccessor(parent, resourceField)); + return new GenericJavaPersistentAttribute( + parent, new FieldAccessor(parent, resourceField)); } @@ -66,38 +70,43 @@ public class GenericJavaPersistentAttribute public JaxbClassMapping getJaxbClassMapping() { return (JaxbClassMapping) super.getParent(); } - - public boolean isInherited() { - return getJaxbClassMapping().isInherited(this); - } - - public String getInheritedJavaResourceAttributeOwningTypeName() { - return getJaxbClassMapping().getJavaResourceAttributeOwningTypeName(this); - } - // ********** synchronize/update ********** - + // ***** synchronize/update ***** + @Override public void synchronizeWithResourceModel() { super.synchronizeWithResourceModel(); this.syncMapping(); } - + @Override public void update() { super.update(); this.updateMapping(); } - - // ********** name ********** - + + + // ***** declaring class/ inheritance ***** + + public JavaResourceType getDeclaringJavaResourceType() { + return this.accessor.getJavaResourceAttribute().getResourceType(); + } + + public boolean isInherited() { + return getDeclaringJavaResourceType() != getJaxbClassMapping().getJaxbType().getJavaResourceType(); + } + + + // ***** name ***** + public String getName() { return this.getJavaResourceAttribute().getName(); } - - // ********** accessor ******** - + + + // ***** accessor ***** + public boolean isFor(JavaResourceField resourceField) { return this.accessor.isFor(resourceField); } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlAnyAttributeMapping.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlAnyAttributeMapping.java index aa40067575..6b94b4273d 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlAnyAttributeMapping.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlAnyAttributeMapping.java @@ -52,7 +52,7 @@ public class GenericJavaXmlAnyAttributeMapping messages.add( DefaultValidationMessages.buildMessage( IMessage.HIGH_SEVERITY, - JaxbValidationMessages.XML_ANY_ATTRIBUTE_MAPPING_DEFINED_ON_NON_MAP, + JaxbValidationMessages.XML_ANY_ATTRIBUTE__NON_MAP_TYPE, this, getValidationTextRange(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 1ec2e5b10a..5dd7c8e182 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 @@ -44,6 +44,11 @@ public interface JaxbValidationMessages { 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_ANY_ATTRIBUTE__MULTIPLE_MAPPINGS_DEFINED = "XML_ANY_ATTRIBUTE__MULTIPLE_MAPPINGS_DEFINED"; + String XML_ANY_ATTRIBUTE__NON_MAP_TYPE = "XML_ANY_ATTRIBUTE__NON_MAP_TYPE"; + + String XML_ANY_ELEMENT__MULTIPLE_MAPPINGS_DEFINED = "XML_ANY_ELEMENT__MULTIPLE_MAPPINGS_DEFINED"; + String XML_ELEMENT__UNSPECIFIED_TYPE = "XML_ELEMENT__UNSPECIFIED_TYPE"; String XML_ELEMENT__ILLEGAL_TYPE = "XML_ELEMENT__ILLEGAL_TYPE"; @@ -64,18 +69,17 @@ public interface JaxbValidationMessages { 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_ID__MULTIPLE_MAPPINGS_DEFINED = "XML_ID__MULTIPLE_MAPPINGS_DEFINED"; + String XML_ID_DEFINED_ON_NON_STRING = "XML_ID_DEFINED_ON_NON_STRING"; + 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_IDREF__TYPE_DOES_NOT_CONTAIN_XML_ID = "XML_IDREF__TYPE_DOES_NOT_CONTAIN_XML_ID"; String XML_LIST_DEFINED_ON_NON_ARRAY_NON_COLLECTION = "XML_LIST_DEFINED_ON_NON_ARRAY_NON_COLLECTION"; - String MULTIPLE_XML_ANY_ATTRIBUTE_MAPPINGS_DEFINED = "MULTIPLE_XML_ANY_ATTRIBUTE_MAPPINGS_DEFINED"; - String MULTIPLE_XML_ANY_ELEMENT_MAPPINGS_DEFINED = "MULTIPLE_XML_ANY_ELEMENT_MAPPINGS_DEFINED"; - String MULTIPLE_XML_VALUE_MAPPINGS_DEFINED = "MULTIPLE_XML_VALUE_MAPPINGS_DEFINED"; String XML_VALUE_MAPPING_WITH_NON_XML_ATTRIBUTE_MAPPING_DEFINED = "XML_VALUE_MAPPING_WITH_NON_XML_ATTRIBUTE_MAPPING_DEFINED"; - 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"; // general validation |