added context model support for the XmlType annotation along with tests
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 e27384a..d8963f4 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
@@ -9,6 +9,9 @@
*******************************************************************************/
package org.eclipse.jpt.jaxb.core.context;
+import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType;
+import org.eclipse.jpt.utility.internal.iterables.ListIterable;
+
/**
* Represents a JAXB persistent class.
* (A class with either an explicit or implicit @XmlType annotation)
@@ -23,11 +26,71 @@
* @since 3.0
*/
public interface JaxbPersistentClass
- extends JaxbContextNode {
+ extends
+ JaxbContextNode,
+ XmlAccessTypeHolder,
+ XmlAccessOrderHolder
+{
/**
* The fully qualified class name.
* This is unchanging in that, if a class name changes, a new JaxbType is created.
*/
String getName();
+
+ JavaResourceType getJaxbResourceType();
+
+ JaxbPersistentClass getSuperPersistentClass();
+ String SUPER_PERSISTENT_CLASS_PROPERTY = "superPersistentClass"; //$NON-NLS-1$
+
+
+ /**************** factory class *****************/
+
+ /**
+ * factory class corresponds to the XmlType annotation factoryClass element
+ */
+ String getFactoryClass();
+ void setFactoryClass(String factoryClass);
+ String FACTORY_CLASS_PROPERTY = "factoryClass"; //$NON-NLS-1$
+
+
+ /**************** factory method *****************/
+
+ /**
+ * factory method corresponds to the XmlType annotation factoryMethod element
+ */
+ String getFactoryMethod();
+ void setFactoryMethod(String factoryMethod);
+ String FACTORY_METHOD_PROPERTY = "factoryMethod"; //$NON-NLS-1$
+
+
+ /**************** name *****************/
+
+ /**
+ * Schema type name corresponds to the XmlType annotation name element
+ */
+ String getSchemaTypeName();
+ void setSchemaTypeName(String schemaTypeName);
+ String SCHEMA_TYPE_NAME_PROPERTY = "schemaTypeName"; //$NON-NLS-1$
+
+
+ /**************** namespace *****************/
+
+ /**
+ * namespace corresponds to the XmlType annotation namespace element
+ */
+ String getNamespace();
+ void setNamespace(String namespace);
+ String NAMESPACE_PROPERTY = "namespace"; //$NON-NLS-1$
+
+
+ // ********** propOrder **********
+
+ ListIterable<String> getPropOrder();
+ int getPropOrderSize();
+ void addProp(int index, String prop);
+ void removeProp(int index);
+ void removeProp(String prop);
+ void moveProp(int targetIndex, int sourceIndex);
+ String PROP_ORDER_LIST = "propOrder"; //$NON-NLS-1$
}
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 4de438e..cc198ce 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
@@ -1,35 +1,443 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.jpt.jaxb.core.context.JaxbPackageInfo;
import org.eclipse.jpt.jaxb.core.context.JaxbPersistentClass;
import org.eclipse.jpt.jaxb.core.context.JaxbRootContextNode;
+import org.eclipse.jpt.jaxb.core.context.XmlAccessOrder;
+import org.eclipse.jpt.jaxb.core.context.XmlAccessType;
import org.eclipse.jpt.jaxb.core.internal.context.AbstractJaxbContextNode;
import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType;
-
+import org.eclipse.jpt.jaxb.core.resource.java.XmlAccessorOrderAnnotation;
+import org.eclipse.jpt.jaxb.core.resource.java.XmlAccessorTypeAnnotation;
+import org.eclipse.jpt.jaxb.core.resource.java.XmlTypeAnnotation;
+import org.eclipse.jpt.utility.internal.iterables.ListIterable;
public class GenericJavaPersistentClass
- extends AbstractJaxbContextNode
- implements JaxbPersistentClass {
-
+ extends AbstractJaxbContextNode
+ implements JaxbPersistentClass
+{
+
protected final JavaResourceType resourceType;
-
+ protected String factoryClass;
+ protected String factoryMethod;
+ protected String schemaTypeName;
+ protected String namespace;
+
+ protected final PropOrderContainer propOrderContainer;
+
+ protected JaxbPersistentClass superPersistentClass;
+
+ protected XmlAccessType defaultAccessType;
+ protected XmlAccessType specifiedAccessType;
+
+ protected XmlAccessOrder defaultAccessOrder;
+ protected XmlAccessOrder specifiedAccessOrder;
+
public GenericJavaPersistentClass(JaxbRootContextNode parent, JavaResourceType resourceType) {
super(parent);
this.resourceType = resourceType;
+ this.factoryClass = this.getResourceFactoryClass();
+ this.factoryMethod = this.getResourceFactoryMethod();
+ this.schemaTypeName = this.getResourceSchemaTypeName();
+ this.namespace = this.getResourceNamespace();
+ this.propOrderContainer = new PropOrderContainer();
+ this.superPersistentClass = this.buildSuperPersistentClass();
+ this.specifiedAccessType = this.getResourceAccessType();
+ this.specifiedAccessOrder = this.getResourceAccessOrder();
+ this.defaultAccessType = this.buildDefaultAccessType();
+ this.defaultAccessOrder = this.buildDefaultAccessOrder();
}
-
-
+
+ @Override
+ public JaxbRootContextNode getParent() {
+ return (JaxbRootContextNode) super.getParent();
+ }
+
+ protected JaxbPackageInfo getPackageInfo() {
+ //TODO
+ return null;
+ //return this.getParent().getPackageInfo();
+ }
+
// ********** synchronize/update **********
-
+
public void synchronizeWithResourceModel() {
+ this.setFactoryClass_(this.getResourceFactoryClass());
+ this.setFactoryMethod_(this.getResourceFactoryMethod());
+ this.setSchemaTypeName_(this.getResourceSchemaTypeName());
+ this.setNamespace_(this.getResourceNamespace());
+ this.setSpecifiedAccessType_(this.getResourceAccessType());
+ this.setSpecifiedAccessOrder_(this.getResourceAccessOrder());
+ this.syncPropOrder();
}
-
+
public void update() {
+ this.setSuperPersistentClass(this.buildSuperPersistentClass());
+ this.setDefaultAccessType(this.buildDefaultAccessType());
+ this.setDefaultAccessOrder(this.buildDefaultAccessOrder());
}
-
- // ********** JaxbPersistentClass impl **********
+
+
+ // ********** JaxbPersistentClass implementation **********
+
+ public JavaResourceType getJaxbResourceType() {
+ return this.resourceType;
+ }
public String getName() {
return this.resourceType.getQualifiedName();
}
+
+ // ********** xml type annotation **********
+
+ protected XmlTypeAnnotation getXmlTypeAnnotation() {
+ return (XmlTypeAnnotation) this.getJaxbResourceType().getNonNullAnnotation(XmlTypeAnnotation.ANNOTATION_NAME);
+ }
+
+
+ // ********** factory class **********
+
+ public String getFactoryClass() {
+ return this.factoryClass;
+ }
+
+ public void setFactoryClass(String factoryClass) {
+ this.getXmlTypeAnnotation().setFactoryClass(factoryClass);
+ this.setFactoryClass_(factoryClass);
+ }
+
+ protected void setFactoryClass_(String factoryClass) {
+ String old = this.factoryClass;
+ this.factoryClass = factoryClass;
+ this.firePropertyChanged(FACTORY_CLASS_PROPERTY, old, factoryClass);
+ }
+
+ protected String getResourceFactoryClass() {
+ return this.getXmlTypeAnnotation().getFactoryClass();
+ }
+
+ // ********** factory method **********
+
+ public String getFactoryMethod() {
+ return this.factoryMethod;
+ }
+
+ public void setFactoryMethod(String factoryMethod) {
+ this.getXmlTypeAnnotation().setFactoryMethod(factoryMethod);
+ this.setFactoryMethod_(factoryMethod);
+ }
+
+ protected void setFactoryMethod_(String factoryMethod) {
+ String old = this.factoryMethod;
+ this.factoryMethod = factoryMethod;
+ this.firePropertyChanged(FACTORY_METHOD_PROPERTY, old, factoryMethod);
+ }
+
+ protected String getResourceFactoryMethod() {
+ return this.getXmlTypeAnnotation().getFactoryMethod();
+ }
+
+ // ********** name **********
+
+ public String getSchemaTypeName() {
+ return this.schemaTypeName;
+ }
+
+ public void setSchemaTypeName(String schemaTypeName) {
+ this.getXmlTypeAnnotation().setName(schemaTypeName);
+ this.setSchemaTypeName_(schemaTypeName);
+ }
+
+ protected void setSchemaTypeName_(String schemaTypeName) {
+ String old = this.schemaTypeName;
+ this.schemaTypeName = schemaTypeName;
+ this.firePropertyChanged(SCHEMA_TYPE_NAME_PROPERTY, old, schemaTypeName);
+ }
+
+ protected String getResourceSchemaTypeName() {
+ return this.getXmlTypeAnnotation().getName();
+ }
+
+ // ********** namespace **********
+
+ public String getNamespace() {
+ return this.namespace;
+ }
+
+ public void setNamespace(String namespace) {
+ this.getXmlTypeAnnotation().setNamespace(namespace);
+ this.setNamespace_(namespace);
+ }
+
+ protected void setNamespace_(String namespace) {
+ String old = this.namespace;
+ this.namespace = namespace;
+ this.firePropertyChanged(NAMESPACE_PROPERTY, old, namespace);
+ }
+
+ protected String getResourceNamespace() {
+ return this.getXmlTypeAnnotation().getNamespace();
+ }
+
+ // ********** prop order **********
+
+
+ public ListIterable<String> getPropOrder() {
+ return this.propOrderContainer.getContextElements();
+ }
+
+ public int getPropOrderSize() {
+ return this.propOrderContainer.getContextElementsSize();
+ }
+
+ public void addProp(int index, String prop) {
+ getXmlTypeAnnotation().addProp(index, prop);
+ this.propOrderContainer.addContextElement(index, prop);
+ }
+
+ public void removeProp(String prop) {
+ this.removeProp(this.propOrderContainer.indexOfContextElement(prop));
+ }
+
+ public void removeProp(int index) {
+ this.getXmlTypeAnnotation().removeProp(index);
+ this.propOrderContainer.removeContextElement(index);
+ }
+
+ public void moveProp(int targetIndex, int sourceIndex) {
+ this.getXmlTypeAnnotation().moveProp(targetIndex, sourceIndex);
+ this.propOrderContainer.moveContextElement(targetIndex, sourceIndex);
+ }
+
+ protected void syncPropOrder() {
+ this.propOrderContainer.synchronizeWithResourceModel();
+ }
+
+ protected ListIterable<String> getResourcePropOrder() {
+ return this.getXmlTypeAnnotation().getPropOrder();
+ }
+
+ // ********** super persistent class **********
+
+ public JaxbPersistentClass getSuperPersistentClass() {
+ return this.superPersistentClass;
+ }
+
+ protected void setSuperPersistentClass(JaxbPersistentClass superPersistentClass) {
+ JaxbPersistentClass old = this.superPersistentClass;
+ this.superPersistentClass = superPersistentClass;
+ this.firePropertyChanged(SUPER_PERSISTENT_CLASS_PROPERTY, old, superPersistentClass);
+ }
+
+ //TODO super persistent class
+ protected JaxbPersistentClass buildSuperPersistentClass() {
+ return null;
+// HashSet<JavaResourcePersistentType> visited = new HashSet<JavaResourcePersistentType>();
+// visited.add(this.resourcePersistentType);
+// PersistentType spt = this.getSuperPersistentType(this.resourcePersistentType.getSuperclassQualifiedName(), visited);
+// if (spt == null) {
+// return null;
+// }
+// if (CollectionTools.contains(spt.inheritanceHierarchy(), this)) {
+// return null; // short-circuit in this case, we have circular inheritance
+// }
+// return spt.isMapped() ? spt : spt.getSuperPersistentType();
+ }
+//
+// /**
+// * The JPA spec allows non-persistent types in a persistent type's
+// * inheritance hierarchy. We check for a persistent type with the
+// * specified name in the persistence unit. If it is not found we use
+// * resource persistent type and look for *its* super type.
+// *
+// * The 'visited' collection is used to detect a cycle in the *resource* type
+// * inheritance hierarchy and prevent the resulting stack overflow.
+// * Any cycles in the *context* type inheritance hierarchy are handled in
+// * #buildSuperPersistentType().
+// */
+// protected PersistentType getSuperPersistentType(String typeName, Collection<JavaResourcePersistentType> visited) {
+// if (typeName == null) {
+// return null;
+// }
+// JavaResourcePersistentType resourceType = this.getJpaProject().getJavaResourcePersistentType(typeName);
+// if ((resourceType == null) || visited.contains(resourceType)) {
+// return null;
+// }
+// visited.add(resourceType);
+// PersistentType spt = this.getPersistentType(typeName);
+// return (spt != null) ? spt : this.getSuperPersistentType(resourceType.getSuperclassQualifiedName(), visited); // recurse
+// }
+//
+// protected PersistentType getPersistentType(String typeName) {
+// return this.getPersistenceUnit().getPersistentType(typeName);
+// }
+
+ // ********** access type **********
+
+ public XmlAccessType getAccessType() {
+ return (this.specifiedAccessType != null) ? this.specifiedAccessType : this.defaultAccessType;
+ }
+
+ public XmlAccessType getSpecifiedAccessType() {
+ return this.specifiedAccessType;
+ }
+
+ public void setSpecifiedAccessType(XmlAccessType access) {
+ this.getAccessorTypeAnnotation().setValue(XmlAccessType.toJavaResourceModel(access));
+ this.setSpecifiedAccessType_(access);
+ }
+
+ protected void setSpecifiedAccessType_(XmlAccessType access) {
+ XmlAccessType old = this.specifiedAccessType;
+ this.specifiedAccessType = access;
+ this.firePropertyChanged(SPECIFIED_ACCESS_TYPE_PROPERTY, old, access);
+ }
+
+ public XmlAccessType getDefaultAccessType() {
+ return this.defaultAccessType;
+ }
+
+ protected void setDefaultAccessType(XmlAccessType access) {
+ XmlAccessType old = this.defaultAccessType;
+ this.defaultAccessType = access;
+ this.firePropertyChanged(DEFAULT_ACCESS_TYPE_PROPERTY, old, access);
+ }
+
+ protected XmlAccessType getResourceAccessType() {
+ return XmlAccessType.fromJavaResourceModel(this.getAccessorTypeAnnotation().getValue());
+ }
+
+ protected XmlAccessorTypeAnnotation getAccessorTypeAnnotation() {
+ return (XmlAccessorTypeAnnotation) this.resourceType.getNonNullAnnotation(XmlAccessorTypeAnnotation.ANNOTATION_NAME);
+ }
+
+ /**
+ * If there is a @XmlAccessorType on a class, then it is used.
+ * Otherwise, if a @XmlAccessorType exists on one of its super classes, then it is inherited.
+ * Otherwise, the @XmlAccessorType on a package is inherited.
+ */
+ protected XmlAccessType buildDefaultAccessType() {
+ XmlAccessType superAccessType = this.getSuperPersistentClassAccessType();
+ if (superAccessType != null) {
+ return superAccessType;
+ }
+ XmlAccessType packageAccessType = getPackageAccessType();
+ if (packageAccessType != null) {
+ return packageAccessType;
+ }
+ return XmlAccessType.PUBLIC_MEMBER;
+ }
+
+ protected XmlAccessType getSuperPersistentClassAccessType() {
+ JaxbPersistentClass superPersistentClass = this.getSuperPersistentClass();
+ return superPersistentClass == null ? null : superPersistentClass.getSpecifiedAccessType();
+ }
+
+ protected XmlAccessType getPackageAccessType() {
+ JaxbPackageInfo packageInfo = this.getPackageInfo();
+ return packageInfo == null ? null : packageInfo.getAccessType();
+ }
+
+
+ // ********** access order **********
+
+ public XmlAccessOrder getAccessOrder() {
+ return (this.specifiedAccessOrder != null) ? this.specifiedAccessOrder : this.defaultAccessOrder;
+ }
+
+ public XmlAccessOrder getSpecifiedAccessOrder() {
+ return this.specifiedAccessOrder;
+ }
+
+ public void setSpecifiedAccessOrder(XmlAccessOrder accessOrder) {
+ this.getAccessorOrderAnnotation().setValue(XmlAccessOrder.toJavaResourceModel(accessOrder));
+ this.setSpecifiedAccessOrder_(accessOrder);
+ }
+
+ protected void setSpecifiedAccessOrder_(XmlAccessOrder accessOrder) {
+ XmlAccessOrder old = this.specifiedAccessOrder;
+ this.specifiedAccessOrder = accessOrder;
+ this.firePropertyChanged(SPECIFIED_ACCESS_ORDER_PROPERTY, old, accessOrder);
+ }
+
+ public XmlAccessOrder getDefaultAccessOrder() {
+ return this.defaultAccessOrder;
+ }
+
+ protected void setDefaultAccessOrder(XmlAccessOrder accessOrder) {
+ XmlAccessOrder old = this.defaultAccessOrder;
+ this.defaultAccessOrder = accessOrder;
+ this.firePropertyChanged(DEFAULT_ACCESS_ORDER_PROPERTY, old, accessOrder);
+ }
+
+ protected XmlAccessOrder getResourceAccessOrder() {
+ return XmlAccessOrder.fromJavaResourceModel(this.getAccessorOrderAnnotation().getValue());
+ }
+
+ protected XmlAccessorOrderAnnotation getAccessorOrderAnnotation() {
+ return (XmlAccessorOrderAnnotation) this.resourceType.getNonNullAnnotation(XmlAccessorOrderAnnotation.ANNOTATION_NAME);
+ }
+
+ /**
+ * If there is a @XmlAccessorOrder on a class, then it is used.
+ * Otherwise, if a @XmlAccessorOrder exists on one of its super classes, then it is inherited (by the virtue of Inherited)
+ * Otherwise, the @XmlAccessorOrder on the package of the class is used, if it's there.
+ * Otherwise XmlAccessOrder.UNDEFINED.
+ */
+ protected XmlAccessOrder buildDefaultAccessOrder() {
+ XmlAccessOrder superAccessOrder = this.getSuperPersistentClassAccessOrder();
+ if (superAccessOrder != null) {
+ return superAccessOrder;
+ }
+ XmlAccessOrder packageAccessOrder = getPackageAccessOrder();
+ if (packageAccessOrder != null) {
+ return packageAccessOrder;
+ }
+ return XmlAccessOrder.UNDEFINED;
+ }
+
+ protected XmlAccessOrder getSuperPersistentClassAccessOrder() {
+ JaxbPersistentClass superPersistentClass = this.getSuperPersistentClass();
+ return superPersistentClass == null ? null : superPersistentClass.getSpecifiedAccessOrder();
+ }
+
+ protected XmlAccessOrder getPackageAccessOrder() {
+ JaxbPackageInfo packageInfo = this.getPackageInfo();
+ return packageInfo == null ? null : packageInfo.getAccessOrder();
+ }
+
+
+ /**
+ * xml java type adapter container
+ */
+ protected class PropOrderContainer
+ extends ListContainer<String, String>
+ {
+ @Override
+ protected String getContextElementsPropertyName() {
+ return PROP_ORDER_LIST;
+ }
+ @Override
+ protected String buildContextElement(String resourceElement) {
+ return resourceElement;
+ }
+ @Override
+ protected ListIterable<String> getResourceElements() {
+ return GenericJavaPersistentClass.this.getResourcePropOrder();
+ }
+ @Override
+ protected String getResourceElement(String contextElement) {
+ return contextElement;
+ }
+ }
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/NullXmlTypeAnnotation.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/NullXmlTypeAnnotation.java
new file mode 100644
index 0000000..f8d32d6
--- /dev/null
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/NullXmlTypeAnnotation.java
@@ -0,0 +1,135 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.resource.java;
+
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jpt.core.utility.TextRange;
+import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType;
+import org.eclipse.jpt.jaxb.core.resource.java.XmlTypeAnnotation;
+import org.eclipse.jpt.utility.internal.iterables.EmptyListIterable;
+import org.eclipse.jpt.utility.internal.iterables.ListIterable;
+
+/**
+ * javax.xml.bind.annotation.XmlType
+ */
+public final class NullXmlTypeAnnotation
+ extends NullAnnotation
+ implements XmlTypeAnnotation
+{
+ protected NullXmlTypeAnnotation(JavaResourceType parent) {
+ super(parent);
+ }
+
+ public String getAnnotationName() {
+ return ANNOTATION_NAME;
+ }
+
+ @Override
+ protected XmlTypeAnnotation addAnnotation() {
+ return (XmlTypeAnnotation) super.addAnnotation();
+ }
+
+
+ // ********** XmlTypeAnnotation implementation **********
+
+ // ***** factory class
+ public String getFactoryClass() {
+ return null;
+ }
+
+ public String getFullyQualifiedFactoryClassName() {
+ return null;
+ }
+
+ public void setFactoryClass(String factoryClass) {
+ if (factoryClass != null) {
+ this.addAnnotation().setFactoryClass(factoryClass);
+ }
+ }
+
+ public TextRange getFactoryClassTextRange(CompilationUnit astRoot) {
+ return null;
+ }
+
+ // ***** factory method
+ public String getFactoryMethod() {
+ return null;
+ }
+
+ public void setFactoryMethod(String factoryMethod) {
+ if (factoryMethod != null) {
+ this.addAnnotation().setFactoryMethod(factoryMethod);
+ }
+ }
+
+ public TextRange getFactoryMethodTextRange(CompilationUnit astRoot) {
+ return null;
+ }
+
+ // ***** name
+ public String getName() {
+ return null;
+ }
+
+ public void setName(String name) {
+ if (name != null) {
+ this.addAnnotation().setName(name);
+ }
+ }
+
+ public TextRange getNameTextRange(CompilationUnit astRoot) {
+ return null;
+ }
+
+ // ***** namespace
+ public String getNamespace() {
+ return null;
+ }
+
+ public void setNamespace(String namespace) {
+ if (namespace != null) {
+ this.addAnnotation().setNamespace(namespace);
+ }
+ }
+
+ public TextRange getNamespaceTextRange(CompilationUnit astRoot) {
+ return null;
+ }
+
+
+ public ListIterable<String> getPropOrder() {
+ return EmptyListIterable.instance();
+ }
+
+ public int getPropOrderSize() {
+ return 0;
+ }
+
+ public void addProp(int index, String prop) {
+ this.addAnnotation().addProp(index, prop);
+ }
+
+ public void addProp(String prop) {
+ this.addAnnotation().addProp(prop);
+ }
+
+ public void moveProp(int targetIndex, int sourceIndex) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void removeProp(int index) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void removeProp(String prop) {
+ throw new UnsupportedOperationException();
+ }
+
+}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/XmlTypeAnnotationDefinition.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/XmlTypeAnnotationDefinition.java
index 039f23f..c1d5287 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/XmlTypeAnnotationDefinition.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/XmlTypeAnnotationDefinition.java
@@ -48,7 +48,7 @@
}
public Annotation buildNullAnnotation(JavaResourceAnnotatedElement parent) {
- throw new UnsupportedOperationException();
+ return new NullXmlTypeAnnotation((JavaResourceType) parent);
}
public Annotation buildAnnotation(JavaResourceAnnotatedElement parent, IAnnotation jdtAnnotation) {
diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaPackageInfoTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaPackageInfoTests.java
index 06cf45d..a9cc3dc 100644
--- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaPackageInfoTests.java
+++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaPackageInfoTests.java
@@ -179,11 +179,6 @@
assertEquals(XmlAccessOrder.UNDEFINED, contextPackageInfo.getDefaultAccessOrder());
}
- protected void setEnumMemberValuePair(ModifiedDeclaration declaration, String annotationName, String enumValue) {
- this.setEnumMemberValuePair((NormalAnnotation) declaration.getAnnotationNamed(annotationName), "value", enumValue);
-
- }
-
//add another package annotation so that the context model object doesn't get removed when
//removing the XmlAccessorType annotation. Only "annotated" packages are added to the context model
protected void removeXmlAccessorTypeAnnotation(ModifiedDeclaration declaration) {
diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaPersistentClassTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaPersistentClassTests.java
new file mode 100644
index 0000000..8234ad4
--- /dev/null
+++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaPersistentClassTests.java
@@ -0,0 +1,699 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.tests.internal.context.java;
+
+import java.util.Iterator;
+import java.util.ListIterator;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.dom.Annotation;
+import org.eclipse.jdt.core.dom.MarkerAnnotation;
+import org.eclipse.jdt.core.dom.NormalAnnotation;
+import org.eclipse.jpt.core.utility.jdt.AnnotatedElement;
+import org.eclipse.jpt.core.utility.jdt.Member;
+import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration;
+import org.eclipse.jpt.jaxb.core.context.JaxbPersistentClass;
+import org.eclipse.jpt.jaxb.core.context.XmlAccessOrder;
+import org.eclipse.jpt.jaxb.core.context.XmlAccessType;
+import org.eclipse.jpt.jaxb.core.resource.java.JAXB;
+import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType;
+import org.eclipse.jpt.jaxb.core.resource.java.XmlAccessorOrderAnnotation;
+import org.eclipse.jpt.jaxb.core.resource.java.XmlAccessorTypeAnnotation;
+import org.eclipse.jpt.jaxb.core.resource.java.XmlTypeAnnotation;
+import org.eclipse.jpt.jaxb.core.tests.internal.context.JaxbContextModelTestCase;
+import org.eclipse.jpt.utility.internal.CollectionTools;
+import org.eclipse.jpt.utility.internal.iterators.ArrayIterator;
+
+
+@SuppressWarnings("nls")
+public class GenericJavaPersistentClassTests extends JaxbContextModelTestCase
+{
+
+ public GenericJavaPersistentClassTests(String name) {
+ super(name);
+ }
+
+ private ICompilationUnit createTypeWithXmlType() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JAXB.XML_TYPE);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@XmlType");
+ }
+ });
+ }
+
+ private ICompilationUnit createXmlTypeWithAccessorType() throws CoreException {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JAXB.XML_TYPE, JAXB.XML_ACCESS_TYPE, JAXB.XML_ACCESSOR_TYPE);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@XmlType").append(CR);
+ sb.append("@XmlAccessorType(value = XmlAccessType.PROPERTY)");
+ }
+ });
+ }
+
+ private ICompilationUnit createXmlTypeWithAccessorOrder() throws CoreException {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JAXB.XML_TYPE, JAXB.XML_ACCESS_ORDER, JAXB.XML_ACCESSOR_ORDER);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@XmlType").append(CR);
+ sb.append("@XmlAccessorOrder(value = XmlAccessOrder.ALPHABETICAL)");
+ }
+ });
+ }
+
+ public void testModifyFactoryClass() throws Exception {
+ createTypeWithXmlType();
+
+ JaxbPersistentClass persistentClass = CollectionTools.get(getRootContextNode().getPersistentClasses(), 0);
+ JavaResourceType resourceType = persistentClass.getJaxbResourceType();
+
+ assertNull(persistentClass.getFactoryClass());
+
+ persistentClass.setFactoryClass("foo");
+ XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME);
+ assertEquals("foo", xmlTypeAnnotation.getFactoryClass());
+ assertEquals("foo", persistentClass.getFactoryClass());
+
+ persistentClass.setFactoryClass(null);
+ xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME);
+ assertNull(xmlTypeAnnotation.getFactoryClass());
+ assertNull(persistentClass.getFactoryClass());
+
+ //add another annotation so that the context model does not get blown away
+ persistentClass.setSpecifiedAccessType(XmlAccessType.FIELD);
+ resourceType.removeAnnotation(XmlTypeAnnotation.ANNOTATION_NAME);
+
+ //set factoryClass again, this time starting with no XmlType annotation
+ persistentClass.setFactoryClass("foo");
+ xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME);
+ assertEquals("foo", xmlTypeAnnotation.getFactoryClass());
+ assertEquals("foo", persistentClass.getFactoryClass());
+ }
+
+ public void testUpdateFactoryClass() throws Exception {
+ createTypeWithXmlType();
+
+ JaxbPersistentClass persistentClass = CollectionTools.get(getRootContextNode().getPersistentClasses(), 0);
+ JavaResourceType resourceType = persistentClass.getJaxbResourceType();
+
+ assertNull(persistentClass.getFactoryClass());
+
+
+ //add a factoryClass member value pair
+ AnnotatedElement annotatedElement = this.annotatedElement(resourceType);
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaPersistentClassTests.this.addXmlTypeTypeMemberValuePair(declaration, JAXB.XML_TYPE__FACTORY_CLASS, "Foo");
+ }
+ });
+ assertEquals("Foo", persistentClass.getFactoryClass());
+
+ //remove the factoryClass member value pair
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ NormalAnnotation xmlTypeAnnotation = (NormalAnnotation) GenericJavaPersistentClassTests.this.getXmlTypeAnnotation(declaration);
+ GenericJavaPersistentClassTests.this.values(xmlTypeAnnotation).remove(0);
+ }
+ });
+ assertNull(persistentClass.getFactoryClass());
+ }
+
+ public void testModifyFactoryMethod() throws Exception {
+ createTypeWithXmlType();
+
+ JaxbPersistentClass persistentClass = CollectionTools.get(getRootContextNode().getPersistentClasses(), 0);
+ JavaResourceType resourceType = persistentClass.getJaxbResourceType();
+
+ assertNull(persistentClass.getFactoryMethod());
+
+ persistentClass.setFactoryMethod("foo");
+ XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME);
+ assertEquals("foo", xmlTypeAnnotation.getFactoryMethod());
+ assertEquals("foo", persistentClass.getFactoryMethod());
+
+ persistentClass.setFactoryMethod(null);
+ xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME);
+ assertNull(xmlTypeAnnotation.getFactoryMethod());
+ assertNull(persistentClass.getFactoryMethod());
+
+ //add another annotation so that the context model does not get blown away
+ persistentClass.setSpecifiedAccessType(XmlAccessType.FIELD);
+ resourceType.removeAnnotation(XmlTypeAnnotation.ANNOTATION_NAME);
+
+ //set factoryMethod again, this time starting with no XmlType annotation
+ persistentClass.setFactoryMethod("foo");
+ xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME);
+ assertEquals("foo", xmlTypeAnnotation.getFactoryMethod());
+ assertEquals("foo", persistentClass.getFactoryMethod());
+ }
+
+ public void testUpdateFactoryMethod() throws Exception {
+ createTypeWithXmlType();
+
+ JaxbPersistentClass persistentClass = CollectionTools.get(getRootContextNode().getPersistentClasses(), 0);
+ JavaResourceType resourceType = persistentClass.getJaxbResourceType();
+
+ assertNull(persistentClass.getFactoryMethod());
+
+
+ //add a factoryMethod member value pair
+ AnnotatedElement annotatedElement = this.annotatedElement(resourceType);
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaPersistentClassTests.this.addXmlTypeMemberValuePair(declaration, JAXB.XML_TYPE__FACTORY_METHOD, "foo");
+ }
+ });
+ assertEquals("foo", persistentClass.getFactoryMethod());
+
+ //remove the factoryMethod member value pair
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ NormalAnnotation xmlTypeAnnotation = (NormalAnnotation) GenericJavaPersistentClassTests.this.getXmlTypeAnnotation(declaration);
+ GenericJavaPersistentClassTests.this.values(xmlTypeAnnotation).remove(0);
+ }
+ });
+ assertNull(persistentClass.getFactoryMethod());
+ }
+
+ public void testModifySchemaTypeName() throws Exception {
+ createTypeWithXmlType();
+
+ JaxbPersistentClass persistentClass = CollectionTools.get(getRootContextNode().getPersistentClasses(), 0);
+ JavaResourceType resourceType = persistentClass.getJaxbResourceType();
+
+ assertNull(persistentClass.getSchemaTypeName());
+
+ persistentClass.setSchemaTypeName("foo");
+ XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME);
+ assertEquals("foo", xmlTypeAnnotation.getName());
+ assertEquals("foo", persistentClass.getSchemaTypeName());
+
+ persistentClass.setSchemaTypeName(null);
+ xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME);
+ assertNull(xmlTypeAnnotation.getName());
+ assertNull(persistentClass.getSchemaTypeName());
+
+ //add another annotation so that the context model does not get blown away
+ persistentClass.setSpecifiedAccessType(XmlAccessType.FIELD);
+ resourceType.removeAnnotation(XmlTypeAnnotation.ANNOTATION_NAME);
+
+ //set name again, this time starting with no XmlType annotation
+ persistentClass.setSchemaTypeName("foo");
+ xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME);
+ assertEquals("foo", xmlTypeAnnotation.getName());
+ assertEquals("foo", persistentClass.getSchemaTypeName());
+ }
+
+ public void testUpdateSchemaTypeName() throws Exception {
+ createTypeWithXmlType();
+
+ JaxbPersistentClass persistentClass = CollectionTools.get(getRootContextNode().getPersistentClasses(), 0);
+ JavaResourceType resourceType = persistentClass.getJaxbResourceType();
+
+ assertNull(persistentClass.getSchemaTypeName());
+
+
+ //add a namespace member value pair
+ AnnotatedElement annotatedElement = this.annotatedElement(resourceType);
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaPersistentClassTests.this.addXmlTypeMemberValuePair(declaration, JAXB.XML_TYPE__NAME, "foo");
+ }
+ });
+ assertEquals("foo", persistentClass.getSchemaTypeName());
+
+ //remove the namespace member value pair
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ NormalAnnotation xmlTypeAnnotation = (NormalAnnotation) GenericJavaPersistentClassTests.this.getXmlTypeAnnotation(declaration);
+ GenericJavaPersistentClassTests.this.values(xmlTypeAnnotation).remove(0);
+ }
+ });
+ assertNull(persistentClass.getSchemaTypeName());
+ }
+
+ public void testModifyNamespace() throws Exception {
+ createTypeWithXmlType();
+
+ JaxbPersistentClass persistentClass = CollectionTools.get(getRootContextNode().getPersistentClasses(), 0);
+ JavaResourceType resourceType = persistentClass.getJaxbResourceType();
+
+ assertNull(persistentClass.getNamespace());
+
+ persistentClass.setNamespace("foo");
+ XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME);
+ assertEquals("foo", xmlTypeAnnotation.getNamespace());
+ assertEquals("foo", persistentClass.getNamespace());
+
+ persistentClass.setNamespace(null);
+ xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME);
+ assertNull(xmlTypeAnnotation.getNamespace());
+ assertNull(persistentClass.getNamespace());
+
+ //add another annotation so that the context model does not get blown away
+ persistentClass.setSpecifiedAccessType(XmlAccessType.FIELD);
+ resourceType.removeAnnotation(XmlTypeAnnotation.ANNOTATION_NAME);
+
+ //set namespace again, this time starting with no XmlType annotation
+ persistentClass.setNamespace("foo");
+ xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME);
+ assertEquals("foo", xmlTypeAnnotation.getNamespace());
+ assertEquals("foo", persistentClass.getNamespace());
+ }
+
+ public void testUpdateNamespace() throws Exception {
+ createTypeWithXmlType();
+
+ JaxbPersistentClass persistentClass = CollectionTools.get(getRootContextNode().getPersistentClasses(), 0);
+ JavaResourceType resourceType = persistentClass.getJaxbResourceType();
+
+ assertNull(persistentClass.getNamespace());
+
+
+ //add a namespace member value pair
+ AnnotatedElement annotatedElement = this.annotatedElement(resourceType);
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaPersistentClassTests.this.addXmlTypeMemberValuePair(declaration, JAXB.XML_TYPE__NAMESPACE, "foo");
+ }
+ });
+ assertEquals("foo", persistentClass.getNamespace());
+
+ //remove the namespace member value pair
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ NormalAnnotation xmlTypeAnnotation = (NormalAnnotation) GenericJavaPersistentClassTests.this.getXmlTypeAnnotation(declaration);
+ GenericJavaPersistentClassTests.this.values(xmlTypeAnnotation).remove(0);
+ }
+ });
+ assertNull(persistentClass.getNamespace());
+ }
+
+ //TODO test super type with @XmlAccessorType
+ //TODO test package-info.java with @XmlAccessorType
+ public void testModifyAccessType() throws Exception {
+ createXmlTypeWithAccessorType();
+
+ JaxbPersistentClass persistentClass = CollectionTools.get(getRootContextNode().getPersistentClasses(), 0);
+ JavaResourceType resourceType = persistentClass.getJaxbResourceType();
+
+ assertEquals(XmlAccessType.PROPERTY, persistentClass.getSpecifiedAccessType());
+ assertEquals(XmlAccessType.PROPERTY, persistentClass.getAccessType());
+ assertEquals(XmlAccessType.PUBLIC_MEMBER, persistentClass.getDefaultAccessType());
+
+ persistentClass.setSpecifiedAccessType(XmlAccessType.FIELD);
+ XmlAccessorTypeAnnotation accessorTypeAnnotation = (XmlAccessorTypeAnnotation) resourceType.getAnnotation(XmlAccessorTypeAnnotation.ANNOTATION_NAME);
+ assertEquals(org.eclipse.jpt.jaxb.core.resource.java.XmlAccessType.FIELD, accessorTypeAnnotation.getValue());
+ assertEquals(XmlAccessType.FIELD, persistentClass.getAccessType());
+
+ persistentClass.setSpecifiedAccessType(XmlAccessType.PUBLIC_MEMBER);
+ assertEquals(org.eclipse.jpt.jaxb.core.resource.java.XmlAccessType.PUBLIC_MEMBER, accessorTypeAnnotation.getValue());
+ assertEquals(XmlAccessType.PUBLIC_MEMBER, persistentClass.getAccessType());
+
+ persistentClass.setSpecifiedAccessType(XmlAccessType.NONE);
+ assertEquals(org.eclipse.jpt.jaxb.core.resource.java.XmlAccessType.NONE, accessorTypeAnnotation.getValue());
+ assertEquals(XmlAccessType.NONE, persistentClass.getAccessType());
+
+ persistentClass.setSpecifiedAccessType(null);
+ accessorTypeAnnotation = (XmlAccessorTypeAnnotation) resourceType.getAnnotation(XmlAccessorTypeAnnotation.ANNOTATION_NAME);
+ assertNull(accessorTypeAnnotation);
+ assertNull(persistentClass.getSpecifiedAccessType());
+ assertEquals(XmlAccessType.PUBLIC_MEMBER, persistentClass.getAccessType());
+ assertEquals(XmlAccessType.PUBLIC_MEMBER, persistentClass.getDefaultAccessType());
+ }
+
+ public void testUpdateAccessType() throws Exception {
+ createXmlTypeWithAccessorType();
+
+ JaxbPersistentClass persistentClass = CollectionTools.get(getRootContextNode().getPersistentClasses(), 0);
+ JavaResourceType resourceType = persistentClass.getJaxbResourceType();
+
+ assertEquals(XmlAccessType.PROPERTY, persistentClass.getSpecifiedAccessType());
+ assertEquals(XmlAccessType.PROPERTY, persistentClass.getAccessType());
+ assertEquals(XmlAccessType.PUBLIC_MEMBER, persistentClass.getDefaultAccessType());
+
+ //set the accesser type value to FIELD
+ AnnotatedElement annotatedElement = this.annotatedElement(resourceType);
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaPersistentClassTests.this.setEnumMemberValuePair(declaration, XmlAccessorTypeAnnotation.ANNOTATION_NAME, JAXB.XML_ACCESS_TYPE__FIELD);
+ }
+ });
+ assertEquals(XmlAccessType.FIELD, persistentClass.getAccessType());
+
+ //set the accesser type value to PUBLIC_MEMBER
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaPersistentClassTests.this.setEnumMemberValuePair(declaration, XmlAccessorTypeAnnotation.ANNOTATION_NAME, JAXB.XML_ACCESS_TYPE__PUBLIC_MEMBER);
+ }
+ });
+ assertEquals(XmlAccessType.PUBLIC_MEMBER, persistentClass.getAccessType());
+
+ //set the accesser type value to NONE
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaPersistentClassTests.this.setEnumMemberValuePair(declaration, XmlAccessorTypeAnnotation.ANNOTATION_NAME, JAXB.XML_ACCESS_TYPE__NONE);
+ }
+ });
+ assertEquals(XmlAccessType.NONE, persistentClass.getAccessType());
+
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaPersistentClassTests.this.removeAnnotation(declaration, XmlAccessorTypeAnnotation.ANNOTATION_NAME);
+ }
+ });
+ assertNull(persistentClass.getSpecifiedAccessType());
+ assertEquals(XmlAccessType.PUBLIC_MEMBER, persistentClass.getAccessType());
+ assertEquals(XmlAccessType.PUBLIC_MEMBER, persistentClass.getDefaultAccessType());
+ }
+
+ public void testModifyAccessOrder() throws Exception {
+ createXmlTypeWithAccessorOrder();
+ JaxbPersistentClass persistentClass = CollectionTools.get(getRootContextNode().getPersistentClasses(), 0);
+ JavaResourceType resourceType = persistentClass.getJaxbResourceType();
+
+ assertEquals(XmlAccessOrder.ALPHABETICAL, persistentClass.getSpecifiedAccessOrder());
+ assertEquals(XmlAccessOrder.ALPHABETICAL, persistentClass.getAccessOrder());
+ assertEquals(XmlAccessOrder.UNDEFINED, persistentClass.getDefaultAccessOrder());
+
+ persistentClass.setSpecifiedAccessOrder(XmlAccessOrder.UNDEFINED);
+ XmlAccessorOrderAnnotation accessorOrderAnnotation = (XmlAccessorOrderAnnotation) resourceType.getAnnotation(XmlAccessorOrderAnnotation.ANNOTATION_NAME);
+ assertEquals(org.eclipse.jpt.jaxb.core.resource.java.XmlAccessOrder.UNDEFINED, accessorOrderAnnotation.getValue());
+ assertEquals(XmlAccessOrder.UNDEFINED, persistentClass.getAccessOrder());
+
+ persistentClass.setSpecifiedAccessOrder(null);
+ accessorOrderAnnotation = (XmlAccessorOrderAnnotation) resourceType.getAnnotation(XmlAccessorOrderAnnotation.ANNOTATION_NAME);
+ assertNull(accessorOrderAnnotation);
+ assertNull(persistentClass.getSpecifiedAccessOrder());
+ assertEquals(XmlAccessOrder.UNDEFINED, persistentClass.getAccessOrder());
+ assertEquals(XmlAccessOrder.UNDEFINED, persistentClass.getDefaultAccessOrder());
+ }
+
+ public void testUpdateAccessOrder() throws Exception {
+ createXmlTypeWithAccessorOrder();
+ JaxbPersistentClass persistentClass = CollectionTools.get(getRootContextNode().getPersistentClasses(), 0);
+ JavaResourceType resourceType = persistentClass.getJaxbResourceType();
+
+ assertEquals(XmlAccessOrder.ALPHABETICAL, persistentClass.getSpecifiedAccessOrder());
+ assertEquals(XmlAccessOrder.ALPHABETICAL, persistentClass.getAccessOrder());
+ assertEquals(XmlAccessOrder.UNDEFINED, persistentClass.getDefaultAccessOrder());
+
+ //set the access order value to UNDEFINED
+ AnnotatedElement annotatedElement = this.annotatedElement(resourceType);
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaPersistentClassTests.this.setEnumMemberValuePair(declaration, XmlAccessorOrderAnnotation.ANNOTATION_NAME, JAXB.XML_ACCESS_ORDER__UNDEFINED);
+ }
+ });
+ assertEquals(XmlAccessOrder.UNDEFINED, persistentClass.getAccessOrder());
+
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaPersistentClassTests.this.removeAnnotation(declaration, XmlAccessorOrderAnnotation.ANNOTATION_NAME);
+ }
+ });
+ assertNull(persistentClass.getSpecifiedAccessOrder());
+ assertEquals(XmlAccessOrder.UNDEFINED, persistentClass.getAccessOrder());
+ assertEquals(XmlAccessOrder.UNDEFINED, persistentClass.getDefaultAccessOrder());
+ }
+
+ public void testGetPropOrder() throws Exception {
+ this.createTypeWithXmlType();
+ JaxbPersistentClass persistentClass = CollectionTools.get(getRootContextNode().getPersistentClasses(), 0);
+ JavaResourceType resourceType = persistentClass.getJaxbResourceType();
+
+ ListIterator<String> props = persistentClass.getPropOrder().iterator();
+ assertFalse(props.hasNext());
+
+ //add 2 prop orders
+ AnnotatedElement annotatedElement = this.annotatedElement(resourceType);
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaPersistentClassTests.this.addProp(declaration, 0, "bar");
+ GenericJavaPersistentClassTests.this.addProp(declaration, 1, "foo");
+ }
+ });
+
+ props = persistentClass.getPropOrder().iterator();
+ assertEquals("bar", props.next());
+ assertEquals("foo", props.next());
+ assertFalse(props.hasNext());
+ }
+
+ protected void addProp(ModifiedDeclaration declaration, int index, String prop) {
+ this.addArrayElement(declaration, JAXB.XML_TYPE, index, JAXB.XML_TYPE__PROP_ORDER, this.newStringLiteral(declaration.getAst(), prop));
+ }
+
+ public void testGetPropOrderSize() throws Exception {
+ this.createTypeWithXmlType();
+ JaxbPersistentClass persistentClass = CollectionTools.get(getRootContextNode().getPersistentClasses(), 0);
+ JavaResourceType resourceType = persistentClass.getJaxbResourceType();
+
+ assertEquals(0, persistentClass.getPropOrderSize());
+
+ //add 2 prop orders
+ AnnotatedElement annotatedElement = this.annotatedElement(resourceType);
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaPersistentClassTests.this.addProp(declaration, 0, "bar");
+ GenericJavaPersistentClassTests.this.addProp(declaration, 1, "foo");
+ }
+ });
+ assertEquals(2, persistentClass.getPropOrderSize());
+ }
+
+ public void testAddProp() throws Exception {
+ this.createTypeWithXmlType();
+ JaxbPersistentClass persistentClass = CollectionTools.get(getRootContextNode().getPersistentClasses(), 0);
+ JavaResourceType resourceType = persistentClass.getJaxbResourceType();
+
+ persistentClass.addProp(0, "bar");
+ persistentClass.addProp(0, "foo");
+ persistentClass.addProp(0, "baz");
+
+ XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME);
+ ListIterator<String> props = xmlTypeAnnotation.getPropOrder().iterator();
+
+ assertEquals("baz", props.next());
+ assertEquals("foo", props.next());
+ assertEquals("bar", props.next());
+ assertFalse(props.hasNext());
+ }
+
+ public void testAddProp2() throws Exception {
+ this.createTypeWithXmlType();
+ JaxbPersistentClass persistentClass = CollectionTools.get(getRootContextNode().getPersistentClasses(), 0);
+ JavaResourceType resourceType = persistentClass.getJaxbResourceType();
+
+ persistentClass.addProp(0, "bar");
+ persistentClass.addProp(1, "foo");
+ persistentClass.addProp(0, "baz");
+
+ XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME);
+ ListIterator<String> props = xmlTypeAnnotation.getPropOrder().iterator();
+
+ assertEquals("baz", props.next());
+ assertEquals("bar", props.next());
+ assertEquals("foo", props.next());
+ assertFalse(props.hasNext());
+ }
+
+ public void testRemoveProp() throws Exception {
+ this.createTypeWithXmlType();
+ JaxbPersistentClass persistentClass = CollectionTools.get(getRootContextNode().getPersistentClasses(), 0);
+ JavaResourceType resourceType = persistentClass.getJaxbResourceType();
+
+ persistentClass.addProp(0, "bar");
+ persistentClass.addProp(1, "foo");
+ persistentClass.addProp(2, "baz");
+
+ XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME);
+
+ persistentClass.removeProp(1);
+
+ ListIterator<String> resourceProps = xmlTypeAnnotation.getPropOrder().iterator();
+ assertEquals("bar", resourceProps.next());
+ assertEquals("baz", resourceProps.next());
+ assertFalse(resourceProps.hasNext());
+
+ persistentClass.removeProp(1);
+ resourceProps = xmlTypeAnnotation.getPropOrder().iterator();
+ assertEquals("bar", resourceProps.next());
+ assertFalse(resourceProps.hasNext());
+
+ persistentClass.removeProp(0);
+ resourceProps = xmlTypeAnnotation.getPropOrder().iterator();
+ assertFalse(resourceProps.hasNext());
+ }
+
+ public void testMoveProp() throws Exception {
+ this.createTypeWithXmlType();
+ JaxbPersistentClass persistentClass = CollectionTools.get(getRootContextNode().getPersistentClasses(), 0);
+ JavaResourceType resourceType = persistentClass.getJaxbResourceType();
+
+ persistentClass.addProp(0, "bar");
+ persistentClass.addProp(1, "foo");
+ persistentClass.addProp(2, "baz");
+
+ XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME);
+
+ assertEquals(3, xmlTypeAnnotation.getPropOrderSize());
+
+ persistentClass.moveProp(2, 0);
+ ListIterator<String> props = persistentClass.getPropOrder().iterator();
+ assertEquals("foo", props.next());
+ assertEquals("baz", props.next());
+ assertEquals("bar", props.next());
+ assertFalse(props.hasNext());
+
+ ListIterator<String> resourceProps = xmlTypeAnnotation.getPropOrder().iterator();
+ assertEquals("foo", resourceProps.next());
+ assertEquals("baz", resourceProps.next());
+ assertEquals("bar", resourceProps.next());
+
+
+ persistentClass.moveProp(0, 1);
+ props = persistentClass.getPropOrder().iterator();
+ assertEquals("baz", props.next());
+ assertEquals("foo", props.next());
+ assertEquals("bar", props.next());
+ assertFalse(props.hasNext());
+
+ resourceProps = xmlTypeAnnotation.getPropOrder().iterator();
+ assertEquals("baz", resourceProps.next());
+ assertEquals("foo", resourceProps.next());
+ assertEquals("bar", resourceProps.next());
+ }
+
+ public void testSyncXmlNsPrefixes() throws Exception {
+ this.createTypeWithXmlType();
+ JaxbPersistentClass persistentClass = CollectionTools.get(getRootContextNode().getPersistentClasses(), 0);
+ JavaResourceType resourceType = persistentClass.getJaxbResourceType();
+
+ ListIterator<String> props = persistentClass.getPropOrder().iterator();
+ assertFalse(props.hasNext());
+
+ //add 3 prop orders
+ AnnotatedElement annotatedElement = this.annotatedElement(resourceType);
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaPersistentClassTests.this.addProp(declaration, 0, "bar");
+ GenericJavaPersistentClassTests.this.addProp(declaration, 1, "foo");
+ GenericJavaPersistentClassTests.this.addProp(declaration, 2, "baz");
+ }
+ });
+
+ props = persistentClass.getPropOrder().iterator();
+ assertTrue(props.hasNext());
+ assertEquals("bar", props.next());
+ assertEquals("foo", props.next());
+ assertEquals("baz", props.next());
+ assertFalse(props.hasNext());
+
+
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaPersistentClassTests.this.moveProp(declaration, 2, 0);
+ }
+ });
+
+ props = persistentClass.getPropOrder().iterator();
+ assertTrue(props.hasNext());
+ assertEquals("foo", props.next());
+ assertEquals("baz", props.next());
+ assertEquals("bar", props.next());
+ assertFalse(props.hasNext());
+
+
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaPersistentClassTests.this.moveProp(declaration, 0, 1);
+ }
+ });
+
+ props = persistentClass.getPropOrder().iterator();
+ assertTrue(props.hasNext());
+ assertEquals("baz", props.next());
+ assertEquals("foo", props.next());
+ assertEquals("bar", props.next());
+ assertFalse(props.hasNext());
+
+
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaPersistentClassTests.this.removeProp(declaration, 1);
+ }
+ });
+
+ props = persistentClass.getPropOrder().iterator();
+ assertTrue(props.hasNext());
+ assertEquals("baz", props.next());
+ assertEquals("bar", props.next());
+ assertFalse(props.hasNext());
+
+
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaPersistentClassTests.this.removeProp(declaration, 1);
+ }
+ });
+
+ props = persistentClass.getPropOrder().iterator();
+ assertTrue(props.hasNext());
+ assertEquals("baz", props.next());
+ assertFalse(props.hasNext());
+
+
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaPersistentClassTests.this.removeProp(declaration, 0);
+ }
+ });
+
+ props = persistentClass.getPropOrder().iterator();
+ assertFalse(props.hasNext());
+ }
+
+ protected void addXmlTypeMemberValuePair(ModifiedDeclaration declaration, String name, String value) {
+ this.addMemberValuePair((MarkerAnnotation) this.getXmlTypeAnnotation(declaration), name, value);
+ }
+
+ protected void addXmlTypeTypeMemberValuePair(ModifiedDeclaration declaration, String name, String typeName) {
+ this.addMemberValuePair(
+ (MarkerAnnotation) this.getXmlTypeAnnotation(declaration),
+ name,
+ this.newTypeLiteral(declaration.getAst(), typeName));
+ }
+
+ protected Annotation getXmlTypeAnnotation(ModifiedDeclaration declaration) {
+ return declaration.getAnnotationNamed(XmlTypeAnnotation.ANNOTATION_NAME);
+ }
+
+ protected void moveProp(ModifiedDeclaration declaration, int targetIndex, int sourceIndex) {
+ this.moveArrayElement((NormalAnnotation) getXmlTypeAnnotation(declaration), JAXB.XML_TYPE__PROP_ORDER, targetIndex, sourceIndex);
+ }
+
+ protected void removeProp(ModifiedDeclaration declaration, int index) {
+ this.removeArrayElement((NormalAnnotation) getXmlTypeAnnotation(declaration), JAXB.XML_TYPE__PROP_ORDER, index);
+ }
+}
diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlSchemaTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlSchemaTests.java
index 92dee09..6a62831 100644
--- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlSchemaTests.java
+++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlSchemaTests.java
@@ -532,7 +532,7 @@
assertEquals(3, schemaAnnotation.getXmlnsSize());
contextXmlSchema.moveXmlNsPrefix(2, 0);
- ListIterator<XmlNsAnnotation> xmlNsPrefixes = schemaAnnotation.getXmlns().iterator();
+ ListIterator<XmlNs> xmlNsPrefixes = contextXmlSchema.getXmlNsPrefixes().iterator();
assertEquals("foo", xmlNsPrefixes.next().getNamespaceURI());
assertEquals("baz", xmlNsPrefixes.next().getNamespaceURI());
assertEquals("bar", xmlNsPrefixes.next().getNamespaceURI());
@@ -545,7 +545,7 @@
contextXmlSchema.moveXmlNsPrefix(0, 1);
- xmlNsPrefixes = schemaAnnotation.getXmlns().iterator();
+ xmlNsPrefixes = contextXmlSchema.getXmlNsPrefixes().iterator();
assertEquals("baz", xmlNsPrefixes.next().getNamespaceURI());
assertEquals("foo", xmlNsPrefixes.next().getNamespaceURI());
assertEquals("bar", xmlNsPrefixes.next().getNamespaceURI());
diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/JaxbCoreJavaContextModelTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/JaxbCoreJavaContextModelTests.java
index 6935aa4..1f56884 100644
--- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/JaxbCoreJavaContextModelTests.java
+++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/JaxbCoreJavaContextModelTests.java
@@ -18,6 +18,7 @@
public static Test suite() {
TestSuite suite = new TestSuite(JaxbCoreJavaContextModelTests.class.getName());
suite.addTestSuite(GenericJavaPackageInfoTests.class);
+ suite.addTestSuite(GenericJavaPersistentClassTests.class);
suite.addTestSuite(GenericJavaXmlJavaTypeAdapterTests.class);
suite.addTestSuite(GenericJavaXmlSchemaTests.class);
suite.addTestSuite(GenericJavaXmlSchemaTypeTests.class);
diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/AnnotationTestCase.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/AnnotationTestCase.java
index e805842..53578f4 100644
--- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/AnnotationTestCase.java
+++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/AnnotationTestCase.java
@@ -581,6 +581,10 @@
return this.addMemberValuePair(normalAnnotation, pair);
}
+ protected void setEnumMemberValuePair(ModifiedDeclaration declaration, String annotationName, String enumValue) {
+ this.setEnumMemberValuePair((NormalAnnotation) declaration.getAnnotationNamed(annotationName), "value", enumValue);
+ }
+
protected void setEnumMemberValuePair(NormalAnnotation annotation, String elementName, String enumValue) {
MemberValuePair memberValuePair = this.memberValuePair(annotation, elementName);
memberValuePair.setValue(annotation.getAST().newName(enumValue));