Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkmoore2010-11-04 11:47:16 -0400
committerkmoore2010-11-04 11:47:16 -0400
commit6dcb16de65f4b5f3acac07ce89f4a0e537c202e9 (patch)
treedd8d35ce9440386340e4cf6671061449b44e269f
parentf063d1782518a2dd821e929e107088aa04c65e9c (diff)
downloadwebtools.dali-6dcb16de65f4b5f3acac07ce89f4a0e537c202e9.tar.gz
webtools.dali-6dcb16de65f4b5f3acac07ce89f4a0e537c202e9.tar.xz
webtools.dali-6dcb16de65f4b5f3acac07ce89f4a0e537c202e9.zip
added context model XmlSchemaType support to JaxbPackageInfo
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/JaxbFactory.java4
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbPackageInfo.java15
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/XmlSchemaType.java69
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbFactory.java7
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbNode.java14
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/GenericRootContextNode.java2
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaPackageInfo.java75
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlSchema.java7
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlSchemaType.java137
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/JavaResourceAnnotatedElement.java2
-rw-r--r--jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaPackageInfoTests.java264
-rw-r--r--jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlSchemaTests.java2
-rw-r--r--jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlSchemaTypeTests.java219
-rw-r--r--jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/JaxbCoreJavaContextModelTests.java1
-rw-r--r--jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/AnnotationTestCase.java30
15 files changed, 830 insertions, 18 deletions
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/JaxbFactory.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/JaxbFactory.java
index 74a7fafd62..1db0d4a83c 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/JaxbFactory.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/JaxbFactory.java
@@ -20,8 +20,10 @@ import org.eclipse.jpt.jaxb.core.context.JaxbPackageInfo;
import org.eclipse.jpt.jaxb.core.context.JaxbRootContextNode;
import org.eclipse.jpt.jaxb.core.context.XmlNs;
import org.eclipse.jpt.jaxb.core.context.XmlSchema;
+import org.eclipse.jpt.jaxb.core.context.XmlSchemaType;
import org.eclipse.jpt.jaxb.core.resource.java.JavaResourcePackage;
import org.eclipse.jpt.jaxb.core.resource.java.XmlNsAnnotation;
+import org.eclipse.jpt.jaxb.core.resource.java.XmlSchemaTypeAnnotation;
/**
* Use a JAXB factory to build any core (e.g. {@link JaxbProject})
@@ -89,6 +91,8 @@ public interface JaxbFactory
JaxbPackageInfo buildJavaPackageInfo(JaxbPackage parent, JavaResourcePackage resourcePackage);
XmlSchema buildJavaXmlSchema(JaxbPackageInfo parent);
+
+ XmlSchemaType buildJavaXmlSchemaType(JaxbPackageInfo parent, XmlSchemaTypeAnnotation xmlSchemaTypeAnnotation);
XmlNs buildJavaXmlNs(XmlSchema parent, XmlNsAnnotation xmlNsAnnotation);
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbPackageInfo.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbPackageInfo.java
index d81a5c5e7a..46ad3ddec9 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbPackageInfo.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbPackageInfo.java
@@ -10,6 +10,7 @@
package org.eclipse.jpt.jaxb.core.context;
import org.eclipse.jpt.jaxb.core.resource.java.JavaResourcePackage;
+import org.eclipse.jpt.utility.internal.iterables.ListIterable;
/**
*
@@ -32,8 +33,22 @@ public interface JaxbPackageInfo
JavaResourcePackage getResourcePackage();
+
+ /**************** xml schema *****************/
+
/**
* Return the XML schema for this package info, this will not be null.
*/
XmlSchema getXmlSchema();
+
+ // ********** xml schema types **********
+
+ ListIterable<XmlSchemaType> getXmlSchemaTypes();
+ int getXmlSchemaTypesSize();
+ XmlSchemaType addXmlSchemaType(int index);
+ void removeXmlSchemaType(int index);
+ void removeXmlSchemaType(XmlSchemaType xmlSchemaType);
+ void moveXmlSchemaType(int targetIndex, int sourceIndex);
+ String XML_SCHEMA_TYPES_LIST = "xmlSchemaTypes"; //$NON-NLS-1$
+
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/XmlSchemaType.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/XmlSchemaType.java
new file mode 100644
index 0000000000..e7c5793466
--- /dev/null
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/XmlSchemaType.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * 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.context;
+
+import org.eclipse.jpt.jaxb.core.resource.java.XmlSchemaTypeAnnotation;
+
+/**
+ *
+ * <p>
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ *
+ * @version 3.0
+ * @since 3.0
+ */
+public interface XmlSchemaType
+ extends
+ JaxbContextNode
+{
+
+ XmlSchemaTypeAnnotation getResourceXmlSchemaType();
+
+
+ /**************** name *****************/
+
+ String getName();
+ void setName(String name);
+ String NAME_PROPERTY = "name"; //$NON-NLS-1$
+
+
+ /**************** namespace *****************/
+
+ /**
+ * Return the namespace, whether specified or defaulted.
+ * This should never return null since at least the default will be set
+ */
+ String getNamespace();
+
+ String getSpecifiedNamespace();
+ void setSpecifiedNamespace(String specifiedNamespace);
+ String SPECIFIED_NAMESPACE_PROPERTY = "specifiedNamespace"; //$NON-NLS-1$
+
+ String getDefaultNamespace();
+ String DEFAULT_NAMEPSACE_PROPERTY = "defaultNamespace"; //$NON-NLS-1$
+ String DEFAULT_NAMESPACE = "http://www.w3.org/2001/XMLSchema"; //$NON-NLS-1$
+
+
+ /**************** type *****************/
+
+ String getType();
+
+ String getSpecifiedType();
+ void setSpecifiedType(String type);
+ String SPECIFIED_TYPE_PROPERTY = "specifiedType"; //$NON-NLS-1$
+
+ String getDefaultType();
+ String DEFAULT_TYPE_PROPERTY = "defaultType"; //$NON-NLS-1$
+ String DEFAULT_TYPE = "javax.xml.bind.annotation.XmlSchemaType.DEFAULT"; //$NON-NLS-1$
+}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbFactory.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbFactory.java
index ffc294a62c..6545f9f2d1 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbFactory.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbFactory.java
@@ -21,13 +21,16 @@ import org.eclipse.jpt.jaxb.core.context.JaxbPackageInfo;
import org.eclipse.jpt.jaxb.core.context.JaxbRootContextNode;
import org.eclipse.jpt.jaxb.core.context.XmlNs;
import org.eclipse.jpt.jaxb.core.context.XmlSchema;
+import org.eclipse.jpt.jaxb.core.context.XmlSchemaType;
import org.eclipse.jpt.jaxb.core.internal.context.GenericPackage;
import org.eclipse.jpt.jaxb.core.internal.context.GenericRootContextNode;
import org.eclipse.jpt.jaxb.core.internal.context.java.GenericJavaPackageInfo;
import org.eclipse.jpt.jaxb.core.internal.context.java.GenericJavaXmlNs;
import org.eclipse.jpt.jaxb.core.internal.context.java.GenericJavaXmlSchema;
+import org.eclipse.jpt.jaxb.core.internal.context.java.GenericJavaXmlSchemaType;
import org.eclipse.jpt.jaxb.core.resource.java.JavaResourcePackage;
import org.eclipse.jpt.jaxb.core.resource.java.XmlNsAnnotation;
+import org.eclipse.jpt.jaxb.core.resource.java.XmlSchemaTypeAnnotation;
/**
* Central class that allows extenders to easily replace implementations of
@@ -71,6 +74,10 @@ public abstract class AbstractJaxbFactory
return new GenericJavaXmlSchema(parent);
}
+ public XmlSchemaType buildJavaXmlSchemaType(JaxbPackageInfo parent, XmlSchemaTypeAnnotation xmlSchemaTypeAnnotation) {
+ return new GenericJavaXmlSchemaType(parent, xmlSchemaTypeAnnotation);
+ }
+
public XmlNs buildJavaXmlNs(XmlSchema parent, XmlNsAnnotation xmlNsAnnotation) {
return new GenericJavaXmlNs(parent, xmlNsAnnotation);
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbNode.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbNode.java
index 748eab59a1..2723279592 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbNode.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbNode.java
@@ -187,16 +187,16 @@ public abstract class AbstractJaxbNode
/**
- * Adapter used to synchronize a context container with its corresponding
+ * Adapter used to synchronize a context collection container with its corresponding
* resource container.
* @param <C> the type of context elements
* @param <R> the type of resource elements
*/
- protected abstract class ContextCollectionContainer<C extends JaxbContextNode, R> {
+ protected abstract class CollectionContainer<C extends JaxbContextNode, R> {
protected final Vector<C> contextElements = new Vector<C>();
- protected ContextCollectionContainer() {
+ protected CollectionContainer() {
super();
this.initializeContextElements();
}
@@ -338,15 +338,15 @@ public abstract class AbstractJaxbNode
}
/**
- * Adapter used to synchronize a context container with its corresponding
+ * Adapter used to synchronize a context list container with its corresponding
* resource container.
* @param <C> the type of context elements
* @param <R> the type of resource elements
*/
- protected abstract class ContextListContainer<C extends JaxbContextNode, R> extends ContextCollectionContainer<C, R> {
-
+ protected abstract class ListContainer<C extends JaxbContextNode, R>
+ extends CollectionContainer<C, R> {
- protected ContextListContainer() {
+ protected ListContainer() {
super();
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/GenericRootContextNode.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/GenericRootContextNode.java
index b50906ebe2..b4418fe387 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/GenericRootContextNode.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/GenericRootContextNode.java
@@ -113,7 +113,7 @@ public class GenericRootContextNode
* package container adapter
*/
protected class PackageContainer
- extends ContextCollectionContainer<JaxbPackage, JavaResourcePackage>
+ extends CollectionContainer<JaxbPackage, JavaResourcePackage>
{
@Override
protected String getContextElementsPropertyName() {
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaPackageInfo.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaPackageInfo.java
index a8ba25f9ac..938cbf2545 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaPackageInfo.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaPackageInfo.java
@@ -14,10 +14,14 @@ import org.eclipse.jpt.jaxb.core.context.JaxbPackageInfo;
import org.eclipse.jpt.jaxb.core.context.XmlAccessOrder;
import org.eclipse.jpt.jaxb.core.context.XmlAccessType;
import org.eclipse.jpt.jaxb.core.context.XmlSchema;
+import org.eclipse.jpt.jaxb.core.context.XmlSchemaType;
import org.eclipse.jpt.jaxb.core.internal.context.AbstractJaxbContextNode;
import org.eclipse.jpt.jaxb.core.resource.java.JavaResourcePackage;
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.XmlSchemaTypeAnnotation;
+import org.eclipse.jpt.jaxb.core.resource.java.XmlSchemaTypesAnnotation;
+import org.eclipse.jpt.utility.internal.iterables.ListIterable;
public class GenericJavaPackageInfo
extends AbstractJaxbContextNode
@@ -32,12 +36,15 @@ public class GenericJavaPackageInfo
protected XmlAccessOrder specifiedAccessOrder;
+ protected final XmlSchemaTypeContainer xmlSchemaTypeContainer;
+
public GenericJavaPackageInfo(JaxbPackage parent, JavaResourcePackage resourcePackage) {
super(parent);
this.resourcePackage = resourcePackage;
this.xmlSchema = getFactory().buildJavaXmlSchema(this);
this.specifiedAccessType = getResourceAccessType();
this.specifiedAccessOrder = getResourceAccessOrder();
+ this.xmlSchemaTypeContainer = new XmlSchemaTypeContainer();
}
@@ -47,6 +54,7 @@ public class GenericJavaPackageInfo
this.xmlSchema.synchronizeWithResourceModel();
this.setSpecifiedAccessType_(this.getResourceAccessType());
this.setSpecifiedAccessOrder_(this.getResourceAccessOrder());
+ this.syncXmlSchemaTypes();
}
public void update() {
@@ -133,4 +141,71 @@ public class GenericJavaPackageInfo
return (XmlAccessorOrderAnnotation) this.resourcePackage.getNonNullAnnotation(XmlAccessorOrderAnnotation.ANNOTATION_NAME);
}
+
+ // ********** xml schema types **********
+
+ public ListIterable<XmlSchemaType> getXmlSchemaTypes() {
+ return this.xmlSchemaTypeContainer.getContextElements();
+ }
+
+ public int getXmlSchemaTypesSize() {
+ return this.xmlSchemaTypeContainer.getContextElementsSize();
+ }
+
+ public XmlSchemaType addXmlSchemaType(int index) {
+ XmlSchemaTypeAnnotation annotation = (XmlSchemaTypeAnnotation) this.resourcePackage.addAnnotation(index, XmlSchemaTypeAnnotation.ANNOTATION_NAME, XmlSchemaTypesAnnotation.ANNOTATION_NAME);
+ return this.xmlSchemaTypeContainer.addContextElement(index, annotation);
+ }
+
+ public void removeXmlSchemaType(XmlSchemaType xmlSchemaType) {
+ this.removeXmlSchemaType(this.xmlSchemaTypeContainer.indexOfContextElement(xmlSchemaType));
+ }
+
+ public void removeXmlSchemaType(int index) {
+ this.resourcePackage.removeAnnotation(index, XmlSchemaTypeAnnotation.ANNOTATION_NAME, XmlSchemaTypesAnnotation.ANNOTATION_NAME);
+ this.xmlSchemaTypeContainer.removeContextElement(index);
+ }
+
+ public void moveXmlSchemaType(int targetIndex, int sourceIndex) {
+ this.resourcePackage.moveAnnotation(targetIndex, sourceIndex, XmlSchemaTypesAnnotation.ANNOTATION_NAME);
+ this.xmlSchemaTypeContainer.moveContextElement(targetIndex, sourceIndex);
+ }
+
+ protected XmlSchemaType buildXmlSchemaType(XmlSchemaTypeAnnotation xmlSchemaTypeAnnotation) {
+ return this.getFactory().buildJavaXmlSchemaType(this, xmlSchemaTypeAnnotation);
+ }
+
+ protected void syncXmlSchemaTypes() {
+ this.xmlSchemaTypeContainer.synchronizeWithResourceModel();
+ }
+
+ @SuppressWarnings("unchecked")
+ protected Iterable<XmlSchemaTypeAnnotation> getXmlSchemaTypeAnnotations() {
+ return (Iterable<XmlSchemaTypeAnnotation>) this.resourcePackage.getAnnotations(XmlSchemaTypeAnnotation.ANNOTATION_NAME, XmlSchemaTypesAnnotation.ANNOTATION_NAME);
+ }
+
+
+ /**
+ * xml schema type container
+ */
+ protected class XmlSchemaTypeContainer
+ extends ListContainer<XmlSchemaType, XmlSchemaTypeAnnotation>
+ {
+ @Override
+ protected String getContextElementsPropertyName() {
+ return XML_SCHEMA_TYPES_LIST;
+ }
+ @Override
+ protected XmlSchemaType buildContextElement(XmlSchemaTypeAnnotation resourceElement) {
+ return GenericJavaPackageInfo.this.buildXmlSchemaType(resourceElement);
+ }
+ @Override
+ protected Iterable<XmlSchemaTypeAnnotation> getResourceElements() {
+ return GenericJavaPackageInfo.this.getXmlSchemaTypeAnnotations();
+ }
+ @Override
+ protected XmlSchemaTypeAnnotation getResourceElement(XmlSchemaType contextElement) {
+ return contextElement.getResourceXmlSchemaType();
+ }
+ }
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlSchema.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlSchema.java
index 184720f7b8..b91dfcd4e2 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlSchema.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlSchema.java
@@ -194,10 +194,6 @@ public class GenericJavaXmlSchema
return this.xmlNsPrefixContainer.getContextElementsSize();
}
- public XmlNs addXmlNsPrefix() {
- return this.addXmlNsPrefix(this.getXmlNsPrefixesSize());
- }
-
public XmlNs addXmlNsPrefix(int index) {
XmlNsAnnotation annotation = this.getXmlSchemaAnnotation().addXmlns(index);
return this.xmlNsPrefixContainer.addContextElement(index, annotation);
@@ -234,9 +230,8 @@ public class GenericJavaXmlSchema
* xml ns prefix container adapter
*/
protected class XmlNsPrefixContainer
- extends ContextListContainer<XmlNs, XmlNsAnnotation>
+ extends ListContainer<XmlNs, XmlNsAnnotation>
{
-
@Override
protected String getContextElementsPropertyName() {
return XML_NS_PREFIXES_LIST;
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlSchemaType.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlSchemaType.java
new file mode 100644
index 0000000000..4f6c3aa940
--- /dev/null
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlSchemaType.java
@@ -0,0 +1,137 @@
+/*******************************************************************************
+ * 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.JaxbContextNode;
+import org.eclipse.jpt.jaxb.core.context.XmlSchemaType;
+import org.eclipse.jpt.jaxb.core.internal.context.AbstractJaxbContextNode;
+import org.eclipse.jpt.jaxb.core.resource.java.XmlSchemaTypeAnnotation;
+
+public class GenericJavaXmlSchemaType
+ extends AbstractJaxbContextNode
+ implements XmlSchemaType
+{
+
+ protected final XmlSchemaTypeAnnotation xmlSchemaTypeAnnotation;
+
+ protected String name;
+
+ protected String specifiedNamespace;
+
+ protected String specifiedType;
+
+ public GenericJavaXmlSchemaType(JaxbContextNode parent, XmlSchemaTypeAnnotation xmlSchemaTypeAnnotation) {
+ super(parent);
+ this.xmlSchemaTypeAnnotation = xmlSchemaTypeAnnotation;
+ this.name = this.getResourceName();
+ this.specifiedNamespace = this.getResourceNamespace();
+ this.specifiedType = this.getResourceTypeString();
+ }
+
+
+ // ********** synchronize/update **********
+
+ public void synchronizeWithResourceModel() {
+ this.setName_(this.getResourceName());
+ this.setSpecifiedNamespace_(this.getResourceNamespace());
+ this.setSpecifiedType_(this.getResourceTypeString());
+ }
+
+ public void update() {
+ //nothing yet
+ }
+
+
+ // ********** xml schema type annotation **********
+
+ public XmlSchemaTypeAnnotation getResourceXmlSchemaType() {
+ return this.xmlSchemaTypeAnnotation;
+ }
+
+ // ********** name **********
+
+ public String getName() {
+ return this.name;
+ }
+
+ public void setName(String name) {
+ this.xmlSchemaTypeAnnotation.setName(name);
+ this.setName_(name);
+ }
+
+ protected void setName_(String name) {
+ String old = this.name;
+ this.name = name;
+ this.firePropertyChanged(NAME_PROPERTY, old, name);
+ }
+
+ protected String getResourceName() {
+ return this.xmlSchemaTypeAnnotation.getName();
+ }
+
+ // ********** namespace **********
+
+ public String getNamespace() {
+ return (this.specifiedNamespace != null) ? this.specifiedNamespace : this.getDefaultNamespace();
+ }
+
+ public String getSpecifiedNamespace() {
+ return this.specifiedNamespace;
+ }
+
+ public void setSpecifiedNamespace(String location) {
+ this.xmlSchemaTypeAnnotation.setNamespace(location);
+ this.setSpecifiedNamespace_(location);
+ }
+
+ protected void setSpecifiedNamespace_(String namespace) {
+ String old = this.specifiedNamespace;
+ this.specifiedNamespace = namespace;
+ this.firePropertyChanged(SPECIFIED_NAMESPACE_PROPERTY, old, namespace);
+ }
+
+ public String getDefaultNamespace() {
+ return DEFAULT_NAMESPACE;
+ }
+
+ protected String getResourceNamespace() {
+ return this.xmlSchemaTypeAnnotation.getNamespace();
+ }
+
+ // ********** type **********
+
+ public String getType() {
+ return (this.specifiedType != null) ? this.specifiedType : this.getDefaultType();
+ }
+
+ public String getSpecifiedType() {
+ return this.specifiedType;
+ }
+
+ public void setSpecifiedType(String location) {
+ this.xmlSchemaTypeAnnotation.setType(location);
+ this.setSpecifiedType_(location);
+ }
+
+ protected void setSpecifiedType_(String type) {
+ String old = this.specifiedType;
+ this.specifiedType = type;
+ this.firePropertyChanged(SPECIFIED_NAMESPACE_PROPERTY, old, type);
+ }
+
+ public String getDefaultType() {
+ return DEFAULT_TYPE;
+ }
+
+ protected String getResourceTypeString() {
+ return this.xmlSchemaTypeAnnotation.getType();
+ }
+
+}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/JavaResourceAnnotatedElement.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/JavaResourceAnnotatedElement.java
index d248d5b6bb..61d0d22b07 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/JavaResourceAnnotatedElement.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/JavaResourceAnnotatedElement.java
@@ -69,7 +69,7 @@ public interface JavaResourceAnnotatedElement
*/
// TODO tie the singular and plural annotations together so we can generate
// a validation error when both are specified
- Iterable<NestableAnnotation> getAnnotations(String nestableAnnotationName, String containerAnnotationName);
+ Iterable<? extends NestableAnnotation> getAnnotations(String nestableAnnotationName, String containerAnnotationName);
/**
* Add an annotation with the specified name.
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 af2f733b60..f3c3f4f767 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
@@ -9,8 +9,11 @@
******************************************************************************/
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.AST;
import org.eclipse.jdt.core.dom.NormalAnnotation;
import org.eclipse.jpt.core.utility.jdt.AnnotatedElement;
import org.eclipse.jpt.core.utility.jdt.Member;
@@ -18,13 +21,16 @@ import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration;
import org.eclipse.jpt.jaxb.core.context.JaxbPackageInfo;
import org.eclipse.jpt.jaxb.core.context.XmlAccessOrder;
import org.eclipse.jpt.jaxb.core.context.XmlAccessType;
+import org.eclipse.jpt.jaxb.core.context.XmlSchemaType;
import org.eclipse.jpt.jaxb.core.resource.java.JAXB;
import org.eclipse.jpt.jaxb.core.resource.java.JavaResourcePackage;
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.XmlSchemaAnnotation;
+import org.eclipse.jpt.jaxb.core.resource.java.XmlSchemaTypeAnnotation;
import org.eclipse.jpt.jaxb.core.tests.internal.context.JaxbContextModelTestCase;
import org.eclipse.jpt.utility.internal.CollectionTools;
+import org.eclipse.jpt.utility.internal.iterables.ListIterable;
@SuppressWarnings("nls")
@@ -189,4 +195,262 @@ public class GenericJavaPackageInfoTests extends JaxbContextModelTestCase
this.addMarkerAnnotation(declaration.getDeclaration(), XmlSchemaAnnotation.ANNOTATION_NAME);
this.removeAnnotation(declaration, XmlAccessorOrderAnnotation.ANNOTATION_NAME);
}
+
+ public void testGetXmlSchemaTypes() throws Exception {
+ this.createPackageInfoWithAccessorOrder();
+ JaxbPackageInfo contextPackageInfo = CollectionTools.get(getRootContextNode().getPackages(), 0).getPackageInfo();
+ JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage();
+
+ ListIterable<XmlSchemaType> xmlSchemaTypes = contextPackageInfo.getXmlSchemaTypes();
+ assertFalse(xmlSchemaTypes.iterator().hasNext());
+
+ //add 2 XmlSchemaTypes
+ AnnotatedElement annotatedElement = this.annotatedElement(resourcePackage);
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaPackageInfoTests.this.addXmlSchemaType(declaration, 0, "bar");
+ GenericJavaPackageInfoTests.this.addXmlSchemaType(declaration, 1, "foo");
+ }
+ });
+
+ xmlSchemaTypes = contextPackageInfo.getXmlSchemaTypes();
+ ListIterator<XmlSchemaType> xmlSchemaTypesIterator = xmlSchemaTypes.iterator();
+ assertTrue(xmlSchemaTypesIterator.hasNext());
+ assertEquals("bar", xmlSchemaTypesIterator.next().getName());
+ assertEquals("foo", xmlSchemaTypesIterator.next().getName());
+ assertFalse(xmlSchemaTypesIterator.hasNext());
+ }
+
+ protected void addXmlSchemaType(ModifiedDeclaration declaration, int index, String name) {
+ NormalAnnotation arrayElement = this.newXmlSchemaTypeAnnotation(declaration.getAst(), name);
+ this.addArrayElement(declaration, JAXB.XML_SCHEMA_TYPES, index, JAXB.XML_SCHEMA_TYPES__VALUE, arrayElement);
+ }
+
+ protected NormalAnnotation newXmlSchemaTypeAnnotation(AST ast, String name) {
+ NormalAnnotation annotation = this.newNormalAnnotation(ast, JAXB.XML_SCHEMA_TYPE);
+ this.addMemberValuePair(annotation, JAXB.XML_SCHEMA_TYPE__NAME, name);
+ return annotation;
+ }
+
+ public void testGetXmlSchemaTypesSize() throws Exception {
+ this.createPackageInfoWithAccessorOrder();
+ JaxbPackageInfo contextPackageInfo = CollectionTools.get(getRootContextNode().getPackages(), 0).getPackageInfo();
+ JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage();
+
+ assertEquals(0, contextPackageInfo.getXmlSchemaTypesSize());
+
+ //add 2 XmlSchemaTypes
+ AnnotatedElement annotatedElement = this.annotatedElement(resourcePackage);
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaPackageInfoTests.this.addXmlSchemaType(declaration, 0, "bar");
+ GenericJavaPackageInfoTests.this.addXmlSchemaType(declaration, 1, "foo");
+ }
+ });
+ assertEquals(2, contextPackageInfo.getXmlSchemaTypesSize());
+ }
+
+ public void testAddXmlSchemaType() throws Exception {
+ //create a package info with an annotation other than XmlSchema to test
+ //adding things to the null schema annotation
+ this.createPackageInfoWithAccessorType();
+ JaxbPackageInfo contextPackageInfo = CollectionTools.get(getRootContextNode().getPackages(), 0).getPackageInfo();
+ JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage();
+
+ contextPackageInfo.addXmlSchemaType(0).setName("bar");
+ contextPackageInfo.addXmlSchemaType(0).setName("foo");
+ contextPackageInfo.addXmlSchemaType(0).setName("baz");
+
+ Iterator<XmlSchemaTypeAnnotation> xmlSchemaTypes = this.getSchemaTypeAnnotations(resourcePackage);
+
+ assertEquals("baz", xmlSchemaTypes.next().getName());
+ assertEquals("foo", xmlSchemaTypes.next().getName());
+ assertEquals("bar", xmlSchemaTypes.next().getName());
+ assertFalse(xmlSchemaTypes.hasNext());
+ }
+
+ @SuppressWarnings("unchecked")
+ protected Iterator<XmlSchemaTypeAnnotation> getSchemaTypeAnnotations(JavaResourcePackage resourcePackage) {
+ return (Iterator<XmlSchemaTypeAnnotation>) resourcePackage.getAnnotations(JAXB.XML_SCHEMA_TYPE, JAXB.XML_SCHEMA_TYPES).iterator();
+ }
+
+ public void testAddXmlSchemaType2() throws Exception {
+ //create a package info with an annotation other than XmlSchema to test
+ //adding things to the null schema annotation
+ this.createPackageInfoWithAccessorType();
+ JaxbPackageInfo contextPackageInfo = CollectionTools.get(getRootContextNode().getPackages(), 0).getPackageInfo();
+ JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage();
+
+ contextPackageInfo.addXmlSchemaType(0).setName("bar");
+ contextPackageInfo.addXmlSchemaType(1).setName("foo");
+ contextPackageInfo.addXmlSchemaType(0).setName("baz");
+
+ Iterator<XmlSchemaTypeAnnotation> xmlSchemaTypes = this.getSchemaTypeAnnotations(resourcePackage);
+
+ assertEquals("baz", xmlSchemaTypes.next().getName());
+ assertEquals("bar", xmlSchemaTypes.next().getName());
+ assertEquals("foo", xmlSchemaTypes.next().getName());
+ assertFalse(xmlSchemaTypes.hasNext());
+ }
+
+ public void testRemoveXmlSchemaType() throws Exception {
+ this.createPackageInfoWithAccessorType();
+ JaxbPackageInfo contextPackageInfo = CollectionTools.get(getRootContextNode().getPackages(), 0).getPackageInfo();
+ JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage();
+
+ contextPackageInfo.addXmlSchemaType(0).setName("bar");
+ contextPackageInfo.addXmlSchemaType(1).setName("foo");
+ contextPackageInfo.addXmlSchemaType(2).setName("baz");
+
+ Iterator<XmlSchemaTypeAnnotation> xmlSchemaTypes = this.getSchemaTypeAnnotations(resourcePackage);
+ assertEquals("bar", xmlSchemaTypes.next().getName());
+ assertEquals("foo", xmlSchemaTypes.next().getName());
+ assertEquals("baz", xmlSchemaTypes.next().getName());
+ assertFalse(xmlSchemaTypes.hasNext());
+
+ contextPackageInfo.removeXmlSchemaType(1);
+
+ xmlSchemaTypes = this.getSchemaTypeAnnotations(resourcePackage);
+ assertEquals("bar", xmlSchemaTypes.next().getName());
+ assertEquals("baz", xmlSchemaTypes.next().getName());
+ assertFalse(xmlSchemaTypes.hasNext());
+
+ contextPackageInfo.removeXmlSchemaType(1);
+ xmlSchemaTypes = this.getSchemaTypeAnnotations(resourcePackage);
+ assertEquals("bar", xmlSchemaTypes.next().getName());
+ assertFalse(xmlSchemaTypes.hasNext());
+
+ contextPackageInfo.removeXmlSchemaType(0);
+ xmlSchemaTypes = this.getSchemaTypeAnnotations(resourcePackage);
+ assertFalse(xmlSchemaTypes.hasNext());
+ }
+
+ public void testMoveXmlSchemaType() throws Exception {
+ this.createPackageInfoWithAccessorType();
+ JaxbPackageInfo contextPackageInfo = CollectionTools.get(getRootContextNode().getPackages(), 0).getPackageInfo();
+ JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage();
+
+ contextPackageInfo.addXmlSchemaType(0).setName("bar");
+ contextPackageInfo.addXmlSchemaType(1).setName("foo");
+ contextPackageInfo.addXmlSchemaType(2).setName("baz");
+
+ Iterator<XmlSchemaTypeAnnotation> xmlSchemaTypes = this.getSchemaTypeAnnotations(resourcePackage);
+ assertEquals("bar", xmlSchemaTypes.next().getName());
+ assertEquals("foo", xmlSchemaTypes.next().getName());
+ assertEquals("baz", xmlSchemaTypes.next().getName());
+ assertFalse(xmlSchemaTypes.hasNext());
+
+ contextPackageInfo.moveXmlSchemaType(2, 0);
+ xmlSchemaTypes = this.getSchemaTypeAnnotations(resourcePackage);
+ assertEquals("foo", xmlSchemaTypes.next().getName());
+ assertEquals("baz", xmlSchemaTypes.next().getName());
+ assertEquals("bar", xmlSchemaTypes.next().getName());
+ assertFalse(xmlSchemaTypes.hasNext());
+
+ contextPackageInfo.moveXmlSchemaType(0, 1);
+ xmlSchemaTypes = this.getSchemaTypeAnnotations(resourcePackage);
+ assertEquals("baz", xmlSchemaTypes.next().getName());
+ assertEquals("foo", xmlSchemaTypes.next().getName());
+ assertEquals("bar", xmlSchemaTypes.next().getName());
+ assertFalse(xmlSchemaTypes.hasNext());
+ }
+
+ public void testSyncXmlSchemaTypes() throws Exception {
+ this.createPackageInfoWithAccessorType();
+ JaxbPackageInfo contextPackageInfo = CollectionTools.get(getRootContextNode().getPackages(), 0).getPackageInfo();
+ JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage();
+
+ ListIterable<XmlSchemaType> xmlSchemaTypes = contextPackageInfo.getXmlSchemaTypes();
+ assertFalse(xmlSchemaTypes.iterator().hasNext());
+
+ //add 3 XmlSchemaTypes
+ AnnotatedElement annotatedElement = this.annotatedElement(resourcePackage);
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaPackageInfoTests.this.addXmlSchemaType(declaration, 0, "bar");
+ GenericJavaPackageInfoTests.this.addXmlSchemaType(declaration, 1, "foo");
+ GenericJavaPackageInfoTests.this.addXmlSchemaType(declaration, 2, "baz");
+ }
+ });
+
+ xmlSchemaTypes = contextPackageInfo.getXmlSchemaTypes();
+ ListIterator<XmlSchemaType> xmlSchemaTypesIterator = xmlSchemaTypes.iterator();
+ assertTrue(xmlSchemaTypesIterator.hasNext());
+ assertEquals("bar", xmlSchemaTypesIterator.next().getName());
+ assertEquals("foo", xmlSchemaTypesIterator.next().getName());
+ assertEquals("baz", xmlSchemaTypesIterator.next().getName());
+ assertFalse(xmlSchemaTypesIterator.hasNext());
+
+
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaPackageInfoTests.this.moveXmlSchemaType(declaration, 2, 0);
+ }
+ });
+
+ xmlSchemaTypesIterator = xmlSchemaTypes.iterator();
+ assertTrue(xmlSchemaTypesIterator.hasNext());
+ assertEquals("foo", xmlSchemaTypesIterator.next().getName());
+ assertEquals("baz", xmlSchemaTypesIterator.next().getName());
+ assertEquals("bar", xmlSchemaTypesIterator.next().getName());
+ assertFalse(xmlSchemaTypesIterator.hasNext());
+
+
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaPackageInfoTests.this.moveXmlSchemaType(declaration, 0, 1);
+ }
+ });
+
+ xmlSchemaTypesIterator = xmlSchemaTypes.iterator();
+ assertTrue(xmlSchemaTypesIterator.hasNext());
+ assertEquals("baz", xmlSchemaTypesIterator.next().getName());
+ assertEquals("foo", xmlSchemaTypesIterator.next().getName());
+ assertEquals("bar", xmlSchemaTypesIterator.next().getName());
+ assertFalse(xmlSchemaTypesIterator.hasNext());
+
+
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaPackageInfoTests.this.removeXmlSchemaType(declaration, 1);
+ }
+ });
+
+ xmlSchemaTypesIterator = xmlSchemaTypes.iterator();
+ assertTrue(xmlSchemaTypesIterator.hasNext());
+ assertEquals("baz", xmlSchemaTypesIterator.next().getName());
+ assertEquals("bar", xmlSchemaTypesIterator.next().getName());
+ assertFalse(xmlSchemaTypesIterator.hasNext());
+
+
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaPackageInfoTests.this.removeXmlSchemaType(declaration, 1);
+ }
+ });
+
+ xmlSchemaTypesIterator = xmlSchemaTypes.iterator();
+ assertTrue(xmlSchemaTypesIterator.hasNext());
+ assertEquals("baz", xmlSchemaTypesIterator.next().getName());
+ assertFalse(xmlSchemaTypesIterator.hasNext());
+
+
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaPackageInfoTests.this.removeXmlSchemaType(declaration, 0);
+ }
+ });
+
+ xmlSchemaTypesIterator = xmlSchemaTypes.iterator();
+ assertFalse(xmlSchemaTypesIterator.hasNext());
+ }
+
+
+ protected void moveXmlSchemaType(ModifiedDeclaration declaration, int targetIndex, int sourceIndex) {
+ this.moveArrayElement((NormalAnnotation) declaration.getAnnotationNamed(JAXB.XML_SCHEMA_TYPES), JAXB.XML_SCHEMA_TYPES__VALUE, targetIndex, sourceIndex);
+ }
+
+ protected void removeXmlSchemaType(ModifiedDeclaration declaration, int index) {
+ this.removeArrayElement((NormalAnnotation) declaration.getAnnotationNamed(JAXB.XML_SCHEMA_TYPES), JAXB.XML_SCHEMA_TYPES__VALUE, 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 98fd49d045..92dee0982f 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
@@ -393,7 +393,7 @@ public class GenericJavaXmlSchemaTests extends JaxbContextModelTestCase
protected void addXmlNs(ModifiedDeclaration declaration, int index, String namespaceURI, String prefix) {
NormalAnnotation arrayElement = this.newXmlNsAnnotation(declaration.getAst(), namespaceURI, prefix);
- this.addArrayElement(declaration.getAnnotationNamed(XmlSchemaAnnotation.ANNOTATION_NAME), index, JAXB.XML_SCHEMA__XMLNS, arrayElement);
+ this.addArrayElement(declaration, JAXB.XML_SCHEMA, index, JAXB.XML_SCHEMA__XMLNS, arrayElement);
}
protected NormalAnnotation newXmlNsAnnotation(AST ast, String namespaceURI, String prefix) {
diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlSchemaTypeTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlSchemaTypeTests.java
new file mode 100644
index 0000000000..951d789750
--- /dev/null
+++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlSchemaTypeTests.java
@@ -0,0 +1,219 @@
+/*******************************************************************************
+ * 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 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.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.JaxbPackageInfo;
+import org.eclipse.jpt.jaxb.core.context.XmlSchemaType;
+import org.eclipse.jpt.jaxb.core.resource.java.JAXB;
+import org.eclipse.jpt.jaxb.core.resource.java.JavaResourcePackage;
+import org.eclipse.jpt.jaxb.core.resource.java.XmlAccessorOrderAnnotation;
+import org.eclipse.jpt.jaxb.core.resource.java.XmlSchemaTypeAnnotation;
+import org.eclipse.jpt.jaxb.core.tests.internal.context.JaxbContextModelTestCase;
+import org.eclipse.jpt.utility.internal.CollectionTools;
+
+
+@SuppressWarnings("nls")
+public class GenericJavaXmlSchemaTypeTests extends JaxbContextModelTestCase
+{
+
+ public GenericJavaXmlSchemaTypeTests(String name) {
+ super(name);
+ }
+
+ private ICompilationUnit createPackageInfoWithXmlSchemaType() throws CoreException {
+ return createTestPackageInfo(
+ "@XmlSchemaType",
+ JAXB.XML_SCHEMA_TYPE);
+ }
+
+ public void testModifyName() throws Exception {
+ this.createPackageInfoWithXmlSchemaType();
+ JaxbPackageInfo contextPackageInfo = CollectionTools.get(getRootContextNode().getPackages(), 0).getPackageInfo();
+ XmlSchemaType contextXmlSchemaType = contextPackageInfo.getXmlSchemaTypes().iterator().next();
+ JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage();
+
+ assertNull(contextXmlSchemaType.getName());
+
+ contextXmlSchemaType.setName("foo");
+ XmlSchemaTypeAnnotation schemaTypeAnnotation = (XmlSchemaTypeAnnotation) resourcePackage.getAnnotation(XmlSchemaTypeAnnotation.ANNOTATION_NAME);
+ assertEquals("foo", schemaTypeAnnotation.getName());
+ assertEquals("foo", contextXmlSchemaType.getName());
+
+ //verify the xml schema type annotation is not removed when the name is set to null
+ contextXmlSchemaType.setName(null);
+ schemaTypeAnnotation = (XmlSchemaTypeAnnotation) resourcePackage.getAnnotation(XmlSchemaTypeAnnotation.ANNOTATION_NAME);
+ assertNull(schemaTypeAnnotation.getName());
+ assertNull(contextXmlSchemaType.getName());
+ }
+
+ public void testUpdateName() throws Exception {
+ this.createPackageInfoWithXmlSchemaType();
+ JaxbPackageInfo contextPackageInfo = CollectionTools.get(getRootContextNode().getPackages(), 0).getPackageInfo();
+ XmlSchemaType contextXmlSchemaType = contextPackageInfo.getXmlSchemaTypes().iterator().next();
+ JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage();
+
+ assertNull(contextXmlSchemaType.getName());
+
+ //add a name member value pair
+ AnnotatedElement annotatedElement = this.annotatedElement(resourcePackage);
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaXmlSchemaTypeTests.this.addXmlSchemaTypeMemberValuePair(declaration, JAXB.XML_SCHEMA_TYPE__NAME, "foo");
+ }
+ });
+ assertEquals("foo", contextXmlSchemaType.getName());
+
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaXmlSchemaTypeTests.this.removeXmlSchemaTypeAnnotation(declaration);
+ }
+ });
+ assertFalse(contextPackageInfo.getXmlSchemaTypes().iterator().hasNext());
+ }
+
+ public void testModifyNamespace() throws Exception {
+ this.createPackageInfoWithXmlSchemaType();
+ JaxbPackageInfo contextPackageInfo = CollectionTools.get(getRootContextNode().getPackages(), 0).getPackageInfo();
+ XmlSchemaType contextXmlSchemaType = contextPackageInfo.getXmlSchemaTypes().iterator().next();
+ JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage();
+
+ assertEquals(XmlSchemaType.DEFAULT_NAMESPACE, contextXmlSchemaType.getDefaultNamespace());
+ assertEquals(XmlSchemaType.DEFAULT_NAMESPACE, contextXmlSchemaType.getNamespace());
+ assertNull(contextXmlSchemaType.getSpecifiedNamespace());
+
+ contextXmlSchemaType.setSpecifiedNamespace("foo");
+ XmlSchemaTypeAnnotation schemaTypeAnnotation = (XmlSchemaTypeAnnotation) resourcePackage.getAnnotation(XmlSchemaTypeAnnotation.ANNOTATION_NAME);
+ assertEquals("foo", schemaTypeAnnotation.getNamespace());
+ assertEquals(XmlSchemaType.DEFAULT_NAMESPACE, contextXmlSchemaType.getDefaultNamespace());
+ assertEquals("foo", contextXmlSchemaType.getNamespace());
+ assertEquals("foo", contextXmlSchemaType.getSpecifiedNamespace());
+
+ //verify the xml schema type annotation is not removed when the namespace is set to null
+ contextXmlSchemaType.setSpecifiedNamespace(null);
+ schemaTypeAnnotation = (XmlSchemaTypeAnnotation) resourcePackage.getAnnotation(XmlSchemaTypeAnnotation.ANNOTATION_NAME);
+ assertNull(schemaTypeAnnotation.getNamespace());
+ assertEquals(XmlSchemaType.DEFAULT_NAMESPACE, contextXmlSchemaType.getDefaultNamespace());
+ assertEquals(XmlSchemaType.DEFAULT_NAMESPACE, contextXmlSchemaType.getNamespace());
+ assertNull(contextXmlSchemaType.getSpecifiedNamespace());
+ }
+
+ public void testUpdateNamespace() throws Exception {
+ this.createPackageInfoWithXmlSchemaType();
+ JaxbPackageInfo contextPackageInfo = CollectionTools.get(getRootContextNode().getPackages(), 0).getPackageInfo();
+ XmlSchemaType contextXmlSchemaType = contextPackageInfo.getXmlSchemaTypes().iterator().next();
+ JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage();
+
+ assertEquals(XmlSchemaType.DEFAULT_NAMESPACE, contextXmlSchemaType.getDefaultNamespace());
+ assertEquals(XmlSchemaType.DEFAULT_NAMESPACE, contextXmlSchemaType.getNamespace());
+ assertNull(contextXmlSchemaType.getSpecifiedNamespace());
+
+ //add a namespace member value pair
+ AnnotatedElement annotatedElement = this.annotatedElement(resourcePackage);
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaXmlSchemaTypeTests.this.addXmlSchemaTypeMemberValuePair(declaration, JAXB.XML_SCHEMA_TYPE__NAMESPACE, "foo");
+ }
+ });
+ assertEquals(XmlSchemaType.DEFAULT_NAMESPACE, contextXmlSchemaType.getDefaultNamespace());
+ assertEquals("foo", contextXmlSchemaType.getNamespace());
+ assertEquals("foo", contextXmlSchemaType.getSpecifiedNamespace());
+
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaXmlSchemaTypeTests.this.removeXmlSchemaTypeAnnotation(declaration);
+ }
+ });
+ assertFalse(contextPackageInfo.getXmlSchemaTypes().iterator().hasNext());
+ }
+
+ public void testModifyType() throws Exception {
+ this.createPackageInfoWithXmlSchemaType();
+ JaxbPackageInfo contextPackageInfo = CollectionTools.get(getRootContextNode().getPackages(), 0).getPackageInfo();
+ XmlSchemaType contextXmlSchemaType = contextPackageInfo.getXmlSchemaTypes().iterator().next();
+ JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage();
+
+ assertEquals(XmlSchemaType.DEFAULT_TYPE, contextXmlSchemaType.getDefaultType());
+ assertEquals(XmlSchemaType.DEFAULT_TYPE, contextXmlSchemaType.getType());
+ assertNull(contextXmlSchemaType.getSpecifiedType());
+
+ contextXmlSchemaType.setSpecifiedType("foo");
+ XmlSchemaTypeAnnotation schemaTypeAnnotation = (XmlSchemaTypeAnnotation) resourcePackage.getAnnotation(XmlSchemaTypeAnnotation.ANNOTATION_NAME);
+ assertEquals("foo", schemaTypeAnnotation.getType());
+ assertEquals(XmlSchemaType.DEFAULT_TYPE, contextXmlSchemaType.getDefaultType());
+ assertEquals("foo", contextXmlSchemaType.getType());
+ assertEquals("foo", contextXmlSchemaType.getSpecifiedType());
+
+ //verify the xml schema type annotation is not removed when the type is set to null
+ contextXmlSchemaType.setSpecifiedType(null);
+ schemaTypeAnnotation = (XmlSchemaTypeAnnotation) resourcePackage.getAnnotation(XmlSchemaTypeAnnotation.ANNOTATION_NAME);
+ assertNull(schemaTypeAnnotation.getType());
+ assertEquals(XmlSchemaType.DEFAULT_TYPE, contextXmlSchemaType.getDefaultType());
+ assertEquals(XmlSchemaType.DEFAULT_TYPE, contextXmlSchemaType.getType());
+ assertNull(contextXmlSchemaType.getSpecifiedType());
+ }
+
+ public void testUpdateType() throws Exception {
+ this.createPackageInfoWithXmlSchemaType();
+ JaxbPackageInfo contextPackageInfo = CollectionTools.get(getRootContextNode().getPackages(), 0).getPackageInfo();
+ XmlSchemaType contextXmlSchemaType = contextPackageInfo.getXmlSchemaTypes().iterator().next();
+ JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage();
+
+ assertEquals(XmlSchemaType.DEFAULT_TYPE, contextXmlSchemaType.getDefaultType());
+ assertEquals(XmlSchemaType.DEFAULT_TYPE, contextXmlSchemaType.getType());
+ assertNull(contextXmlSchemaType.getSpecifiedType());
+
+ //add a type member value pair
+ AnnotatedElement annotatedElement = this.annotatedElement(resourcePackage);
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaXmlSchemaTypeTests.this.addXmlSchemaTypeTypeMemberValuePair(declaration, JAXB.XML_SCHEMA_TYPE__TYPE, "String");
+ }
+ });
+ assertEquals(XmlSchemaType.DEFAULT_TYPE, contextXmlSchemaType.getDefaultType());
+ assertEquals("String", contextXmlSchemaType.getType());
+ assertEquals("String", contextXmlSchemaType.getSpecifiedType());
+
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaXmlSchemaTypeTests.this.removeXmlSchemaTypeAnnotation(declaration);
+ }
+ });
+ assertFalse(contextPackageInfo.getXmlSchemaTypes().iterator().hasNext());
+ }
+
+ protected void addXmlSchemaTypeTypeMemberValuePair(ModifiedDeclaration declaration, String name, String typeName) {
+ this.addMemberValuePair(
+ (MarkerAnnotation) this.getXmlSchemaTypeAnnotation(declaration),
+ name,
+ this.newTypeLiteral(declaration.getAst(), typeName));
+ }
+
+ protected void addXmlSchemaTypeMemberValuePair(ModifiedDeclaration declaration, String name, String value) {
+ this.addMemberValuePair((MarkerAnnotation) this.getXmlSchemaTypeAnnotation(declaration), name, value);
+ }
+
+ //add another package annotation so that the context model object doesn't get removed when
+ //removing the XmlSchema annotation. Only "annotated" packages are added to the context model
+ protected void removeXmlSchemaTypeAnnotation(ModifiedDeclaration declaration) {
+ this.addMarkerAnnotation(declaration.getDeclaration(), XmlAccessorOrderAnnotation.ANNOTATION_NAME);
+ this.removeAnnotation(declaration, XmlSchemaTypeAnnotation.ANNOTATION_NAME);
+ }
+
+ protected Annotation getXmlSchemaTypeAnnotation(ModifiedDeclaration declaration) {
+ return declaration.getAnnotationNamed(XmlSchemaTypeAnnotation.ANNOTATION_NAME);
+ }
+}
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 4a4bcdf2e2..ac91ffaec7 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
@@ -19,6 +19,7 @@ public class JaxbCoreJavaContextModelTests extends TestCase
TestSuite suite = new TestSuite(JaxbCoreJavaContextModelTests.class.getName());
suite.addTestSuite(GenericJavaPackageInfoTests.class);
suite.addTestSuite(GenericJavaXmlSchemaTests.class);
+ suite.addTestSuite(GenericJavaXmlSchemaTypeTests.class);
return suite;
}
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 f4187f42cf..4520c25877 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
@@ -29,12 +29,15 @@ import org.eclipse.jdt.core.dom.Expression;
import org.eclipse.jdt.core.dom.IExtendedModifier;
import org.eclipse.jdt.core.dom.MarkerAnnotation;
import org.eclipse.jdt.core.dom.MemberValuePair;
+import org.eclipse.jdt.core.dom.Name;
import org.eclipse.jdt.core.dom.NormalAnnotation;
import org.eclipse.jdt.core.dom.NumberLiteral;
import org.eclipse.jdt.core.dom.PackageDeclaration;
import org.eclipse.jdt.core.dom.SimpleName;
+import org.eclipse.jdt.core.dom.SimpleType;
import org.eclipse.jdt.core.dom.SingleMemberAnnotation;
import org.eclipse.jdt.core.dom.StringLiteral;
+import org.eclipse.jdt.core.dom.TypeLiteral;
import org.eclipse.jpt.core.internal.utility.jdt.ASTTools;
import org.eclipse.jpt.core.internal.utility.jdt.JDTFieldAttribute;
import org.eclipse.jpt.core.internal.utility.jdt.JDTMethodAttribute;
@@ -484,6 +487,20 @@ public abstract class AnnotationTestCase extends TestCase {
return stringLiteral;
}
+ protected TypeLiteral newTypeLiteral(AST ast, String typeName) {
+ TypeLiteral typeLiteral = ast.newTypeLiteral();
+ typeLiteral.setType(this.newSimpleType(ast, typeName));
+ return typeLiteral;
+ }
+
+ protected SimpleType newSimpleType(AST ast, String typeName) {
+ return this.newSimpleType(ast, ast.newName(typeName));
+ }
+
+ protected SimpleType newSimpleType(AST ast, Name typeName) {
+ return ast.newSimpleType(typeName);
+ }
+
protected MemberValuePair newMemberValuePair(AST ast, SimpleName name, Expression value) {
MemberValuePair pair = ast.newMemberValuePair();
pair.setName(name);
@@ -567,13 +584,22 @@ public abstract class AnnotationTestCase extends TestCase {
this.addMemberValuePair(annotation, memberValuePair);
}
+ protected void addMemberValuePair(MarkerAnnotation annotation, String elementName, Expression value) {
+ MemberValuePair memberValuePair = this.newMemberValuePair(annotation.getAST(), elementName, value);
+ this.addMemberValuePair(annotation, memberValuePair);
+ }
+
/**
* Add the array element to an annotation that is either a normal annotation or a marker annotation.
* If it is a marker annotation first make it a normal annotation.
*/
- protected void addArrayElement(Annotation annotation, int index, String elementName, Expression arrayElement) {
+ protected void addArrayElement(ModifiedDeclaration declaration, String annotationName, int index, String elementName, Expression arrayElement) {
+ Annotation annotation = declaration.getAnnotationNamed(annotationName);
NormalAnnotation normalAnnotation;
- if (annotation.getNodeType() == ASTNode.MARKER_ANNOTATION) {
+ if (annotation == null) {
+ normalAnnotation = this.addNormalAnnotation(declaration.getDeclaration(), annotationName);
+ }
+ else if (annotation.getNodeType() == ASTNode.MARKER_ANNOTATION) {
normalAnnotation = this.replaceMarkerAnnotation((MarkerAnnotation) annotation);
}
else {

Back to the top