Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkmoore2010-11-04 16:53:05 -0400
committerkmoore2010-11-04 16:53:05 -0400
commit3a502599fbbb84e5a8f178e19fa0f87d99181549 (patch)
treea89db0d13fdbfd1d42d50c00544f0aeb6de914d1
parentebcde16b8cd7b503e1c196b90990c2d8a9a1972f (diff)
downloadwebtools.dali-3a502599fbbb84e5a8f178e19fa0f87d99181549.tar.gz
webtools.dali-3a502599fbbb84e5a8f178e19fa0f87d99181549.tar.xz
webtools.dali-3a502599fbbb84e5a8f178e19fa0f87d99181549.zip
added XmlJavaTypeAdapter context model support
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/JaxbFactory.java9
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbPackageInfo.java14
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/XmlJavaTypeAdapter.java51
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbFactory.java12
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaPackageInfo.java73
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlJavaTypeAdapter.java105
-rw-r--r--jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlJavaTypeAdapterTests.java165
-rw-r--r--jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlSchemaTypeTests.java2
-rw-r--r--jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/JaxbCoreJavaContextModelTests.java1
9 files changed, 426 insertions, 6 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 1db0d4a83c..de065a1ad1 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
@@ -15,13 +15,16 @@ import org.eclipse.jpt.core.JpaResourceModel;
import org.eclipse.jpt.core.context.java.JavaEntity;
import org.eclipse.jpt.core.context.orm.EntityMappings;
import org.eclipse.jpt.core.context.persistence.PersistenceUnit;
+import org.eclipse.jpt.jaxb.core.context.JaxbContextNode;
import org.eclipse.jpt.jaxb.core.context.JaxbPackage;
import org.eclipse.jpt.jaxb.core.context.JaxbPackageInfo;
import org.eclipse.jpt.jaxb.core.context.JaxbRootContextNode;
+import org.eclipse.jpt.jaxb.core.context.XmlJavaTypeAdapter;
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.XmlJavaTypeAdapterAnnotation;
import org.eclipse.jpt.jaxb.core.resource.java.XmlNsAnnotation;
import org.eclipse.jpt.jaxb.core.resource.java.XmlSchemaTypeAnnotation;
@@ -92,7 +95,9 @@ public interface JaxbFactory
XmlSchema buildJavaXmlSchema(JaxbPackageInfo parent);
- XmlSchemaType buildJavaXmlSchemaType(JaxbPackageInfo parent, XmlSchemaTypeAnnotation xmlSchemaTypeAnnotation);
-
+ XmlSchemaType buildJavaXmlSchemaType(JaxbContextNode parent, XmlSchemaTypeAnnotation xmlSchemaTypeAnnotation);
+
+ XmlJavaTypeAdapter buildJavaXmlJavaTypeAdapter(JaxbContextNode parent, XmlJavaTypeAdapterAnnotation xmlJavaTypeAdapterAnnotation);
+
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 46ad3ddec9..17398c0e52 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
@@ -34,13 +34,14 @@ public interface JaxbPackageInfo
JavaResourcePackage getResourcePackage();
- /**************** xml schema *****************/
+ // ********** xml schema **********
/**
* Return the XML schema for this package info, this will not be null.
*/
XmlSchema getXmlSchema();
+
// ********** xml schema types **********
ListIterable<XmlSchemaType> getXmlSchemaTypes();
@@ -51,4 +52,15 @@ public interface JaxbPackageInfo
void moveXmlSchemaType(int targetIndex, int sourceIndex);
String XML_SCHEMA_TYPES_LIST = "xmlSchemaTypes"; //$NON-NLS-1$
+
+ // ********** xml java type adapters **********
+
+ ListIterable<XmlJavaTypeAdapter> getXmlJavaTypeAdapters();
+ int getXmlJavaTypeAdaptersSize();
+ XmlJavaTypeAdapter addXmlJavaTypeAdapter(int index);
+ void removeXmlJavaTypeAdapter(int index);
+ void removeXmlJavaTypeAdapter(XmlJavaTypeAdapter xmlJavaTypeAdapter);
+ void moveXmlJavaTypeAdapter(int targetIndex, int sourceIndex);
+ String XML_JAVA_TYPE_ADAPTERS_LIST = "xmlJavaTypeAdapters"; //$NON-NLS-1$
+
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/XmlJavaTypeAdapter.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/XmlJavaTypeAdapter.java
new file mode 100644
index 0000000000..00abcc3ca3
--- /dev/null
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/XmlJavaTypeAdapter.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * 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.XmlJavaTypeAdapterAnnotation;
+
+/**
+ *
+ * <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 XmlJavaTypeAdapter
+ extends
+ JaxbContextNode
+{
+
+ XmlJavaTypeAdapterAnnotation getResourceXmlJavaTypeAdapter();
+
+ /**************** value *****************/
+
+ String getValue();
+
+ void setValue(String value);
+ String VALUE_PROPERTY = "value"; //$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.adapters.XmlJavaTypeAdapter.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 6545f9f2d1..09962215c9 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
@@ -16,19 +16,23 @@ import org.eclipse.jpt.jaxb.core.JaxbFactory;
import org.eclipse.jpt.jaxb.core.JaxbFile;
import org.eclipse.jpt.jaxb.core.JaxbProject;
import org.eclipse.jpt.jaxb.core.JaxbProject.Config;
+import org.eclipse.jpt.jaxb.core.context.JaxbContextNode;
import org.eclipse.jpt.jaxb.core.context.JaxbPackage;
import org.eclipse.jpt.jaxb.core.context.JaxbPackageInfo;
import org.eclipse.jpt.jaxb.core.context.JaxbRootContextNode;
+import org.eclipse.jpt.jaxb.core.context.XmlJavaTypeAdapter;
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.GenericJavaXmlJavaTypeAdapter;
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.XmlJavaTypeAdapterAnnotation;
import org.eclipse.jpt.jaxb.core.resource.java.XmlNsAnnotation;
import org.eclipse.jpt.jaxb.core.resource.java.XmlSchemaTypeAnnotation;
@@ -74,8 +78,12 @@ public abstract class AbstractJaxbFactory
return new GenericJavaXmlSchema(parent);
}
- public XmlSchemaType buildJavaXmlSchemaType(JaxbPackageInfo parent, XmlSchemaTypeAnnotation xmlSchemaTypeAnnotation) {
- return new GenericJavaXmlSchemaType(parent, xmlSchemaTypeAnnotation);
+ public XmlSchemaType buildJavaXmlSchemaType(JaxbContextNode parent, XmlSchemaTypeAnnotation resourceXmlSchemaType) {
+ return new GenericJavaXmlSchemaType(parent, resourceXmlSchemaType);
+ }
+
+ public XmlJavaTypeAdapter buildJavaXmlJavaTypeAdapter(JaxbContextNode parent, XmlJavaTypeAdapterAnnotation resourceXmlJavaTypeAdapter) {
+ return new GenericJavaXmlJavaTypeAdapter(parent, resourceXmlJavaTypeAdapter);
}
public XmlNs buildJavaXmlNs(XmlSchema parent, XmlNsAnnotation xmlNsAnnotation) {
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 938cbf2545..f37bd8060e 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
@@ -13,12 +13,15 @@ import org.eclipse.jpt.jaxb.core.context.JaxbPackage;
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.XmlJavaTypeAdapter;
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.XmlJavaTypeAdapterAnnotation;
+import org.eclipse.jpt.jaxb.core.resource.java.XmlJavaTypeAdaptersAnnotation;
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;
@@ -38,6 +41,8 @@ public class GenericJavaPackageInfo
protected final XmlSchemaTypeContainer xmlSchemaTypeContainer;
+ protected final XmlJavaTypeAdapterContainer xmlJavaTypeAdapterContainer;
+
public GenericJavaPackageInfo(JaxbPackage parent, JavaResourcePackage resourcePackage) {
super(parent);
this.resourcePackage = resourcePackage;
@@ -45,6 +50,7 @@ public class GenericJavaPackageInfo
this.specifiedAccessType = getResourceAccessType();
this.specifiedAccessOrder = getResourceAccessOrder();
this.xmlSchemaTypeContainer = new XmlSchemaTypeContainer();
+ this.xmlJavaTypeAdapterContainer = new XmlJavaTypeAdapterContainer();
}
@@ -55,6 +61,7 @@ public class GenericJavaPackageInfo
this.setSpecifiedAccessType_(this.getResourceAccessType());
this.setSpecifiedAccessOrder_(this.getResourceAccessOrder());
this.syncXmlSchemaTypes();
+ this.syncXmlJavaTypeAdapters();
}
public void update() {
@@ -185,6 +192,48 @@ public class GenericJavaPackageInfo
}
+ // ********** xml java type adapters **********
+
+ public ListIterable<XmlJavaTypeAdapter> getXmlJavaTypeAdapters() {
+ return this.xmlJavaTypeAdapterContainer.getContextElements();
+ }
+
+ public int getXmlJavaTypeAdaptersSize() {
+ return this.xmlJavaTypeAdapterContainer.getContextElementsSize();
+ }
+
+ public XmlJavaTypeAdapter addXmlJavaTypeAdapter(int index) {
+ XmlJavaTypeAdapterAnnotation annotation = (XmlJavaTypeAdapterAnnotation) this.resourcePackage.addAnnotation(index, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME, XmlJavaTypeAdaptersAnnotation.ANNOTATION_NAME);
+ return this.xmlJavaTypeAdapterContainer.addContextElement(index, annotation);
+ }
+
+ public void removeXmlJavaTypeAdapter(XmlJavaTypeAdapter xmlSchemaType) {
+ this.removeXmlJavaTypeAdapter(this.xmlJavaTypeAdapterContainer.indexOfContextElement(xmlSchemaType));
+ }
+
+ public void removeXmlJavaTypeAdapter(int index) {
+ this.resourcePackage.removeAnnotation(index, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME, XmlJavaTypeAdaptersAnnotation.ANNOTATION_NAME);
+ this.xmlJavaTypeAdapterContainer.removeContextElement(index);
+ }
+
+ public void moveXmlJavaTypeAdapter(int targetIndex, int sourceIndex) {
+ this.resourcePackage.moveAnnotation(targetIndex, sourceIndex, XmlJavaTypeAdaptersAnnotation.ANNOTATION_NAME);
+ this.xmlJavaTypeAdapterContainer.moveContextElement(targetIndex, sourceIndex);
+ }
+
+ protected XmlJavaTypeAdapter buildXmlJavaTypeAdapter(XmlJavaTypeAdapterAnnotation xmlSchemaTypeAnnotation) {
+ return this.getFactory().buildJavaXmlJavaTypeAdapter(this, xmlSchemaTypeAnnotation);
+ }
+
+ protected void syncXmlJavaTypeAdapters() {
+ this.xmlJavaTypeAdapterContainer.synchronizeWithResourceModel();
+ }
+
+ @SuppressWarnings("unchecked")
+ protected Iterable<XmlJavaTypeAdapterAnnotation> getXmlJavaTypeAdapterAnnotations() {
+ return (Iterable<XmlJavaTypeAdapterAnnotation>) this.resourcePackage.getAnnotations(XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME, XmlJavaTypeAdaptersAnnotation.ANNOTATION_NAME);
+ }
+
/**
* xml schema type container
*/
@@ -208,4 +257,28 @@ public class GenericJavaPackageInfo
return contextElement.getResourceXmlSchemaType();
}
}
+
+ /**
+ * xml java type adapter container
+ */
+ protected class XmlJavaTypeAdapterContainer
+ extends ListContainer<XmlJavaTypeAdapter, XmlJavaTypeAdapterAnnotation>
+ {
+ @Override
+ protected String getContextElementsPropertyName() {
+ return XML_JAVA_TYPE_ADAPTERS_LIST;
+ }
+ @Override
+ protected XmlJavaTypeAdapter buildContextElement(XmlJavaTypeAdapterAnnotation resourceElement) {
+ return GenericJavaPackageInfo.this.buildXmlJavaTypeAdapter(resourceElement);
+ }
+ @Override
+ protected Iterable<XmlJavaTypeAdapterAnnotation> getResourceElements() {
+ return GenericJavaPackageInfo.this.getXmlJavaTypeAdapterAnnotations();
+ }
+ @Override
+ protected XmlJavaTypeAdapterAnnotation getResourceElement(XmlJavaTypeAdapter contextElement) {
+ return contextElement.getResourceXmlJavaTypeAdapter();
+ }
+ }
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlJavaTypeAdapter.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlJavaTypeAdapter.java
new file mode 100644
index 0000000000..5d4661428b
--- /dev/null
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlJavaTypeAdapter.java
@@ -0,0 +1,105 @@
+/*******************************************************************************
+ * 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.XmlJavaTypeAdapter;
+import org.eclipse.jpt.jaxb.core.internal.context.AbstractJaxbContextNode;
+import org.eclipse.jpt.jaxb.core.resource.java.XmlJavaTypeAdapterAnnotation;
+
+public class GenericJavaXmlJavaTypeAdapter
+ extends AbstractJaxbContextNode
+ implements XmlJavaTypeAdapter
+{
+
+ protected final XmlJavaTypeAdapterAnnotation resourceXmlJavaTypeAdapter;
+
+ protected String value;
+
+ protected String specifiedType;
+
+ public GenericJavaXmlJavaTypeAdapter(JaxbContextNode parent, XmlJavaTypeAdapterAnnotation resource) {
+ super(parent);
+ this.resourceXmlJavaTypeAdapter = resource;
+ this.value = this.getResourceValue();
+ this.specifiedType = this.getResourceTypeString();
+ }
+
+
+ // ********** synchronize/update **********
+
+ public void synchronizeWithResourceModel() {
+ this.setValue_(this.getResourceValue());
+ this.setSpecifiedType_(this.getResourceTypeString());
+ }
+
+ public void update() {
+ //nothing yet
+ }
+
+
+ // ********** xml java type adapter annotation **********
+
+ public XmlJavaTypeAdapterAnnotation getResourceXmlJavaTypeAdapter() {
+ return this.resourceXmlJavaTypeAdapter;
+ }
+
+ // ********** value **********
+
+ public String getValue() {
+ return this.value;
+ }
+
+ public void setValue(String value) {
+ this.resourceXmlJavaTypeAdapter.setValue(value);
+ this.setValue_(value);
+ }
+
+ protected void setValue_(String value) {
+ String old = this.value;
+ this.value = value;
+ this.firePropertyChanged(VALUE_PROPERTY, old, value);
+ }
+
+ protected String getResourceValue() {
+ return this.resourceXmlJavaTypeAdapter.getValue();
+ }
+
+
+ // ********** type **********
+
+ public String getType() {
+ return (this.specifiedType != null) ? this.specifiedType : this.getDefaultType();
+ }
+
+ public String getSpecifiedType() {
+ return this.specifiedType;
+ }
+
+ public void setSpecifiedType(String location) {
+ this.resourceXmlJavaTypeAdapter.setType(location);
+ this.setSpecifiedType_(location);
+ }
+
+ protected void setSpecifiedType_(String type) {
+ String old = this.specifiedType;
+ this.specifiedType = type;
+ this.firePropertyChanged(SPECIFIED_TYPE_PROPERTY, old, type);
+ }
+
+ public String getDefaultType() {
+ return DEFAULT_TYPE;
+ }
+
+ protected String getResourceTypeString() {
+ return this.resourceXmlJavaTypeAdapter.getType();
+ }
+
+}
diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlJavaTypeAdapterTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlJavaTypeAdapterTests.java
new file mode 100644
index 0000000000..f5fad7377e
--- /dev/null
+++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlJavaTypeAdapterTests.java
@@ -0,0 +1,165 @@
+/*******************************************************************************
+ * 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.XmlJavaTypeAdapter;
+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.XmlJavaTypeAdapterAnnotation;
+import org.eclipse.jpt.jaxb.core.tests.internal.context.JaxbContextModelTestCase;
+import org.eclipse.jpt.utility.internal.CollectionTools;
+
+
+@SuppressWarnings("nls")
+public class GenericJavaXmlJavaTypeAdapterTests extends JaxbContextModelTestCase
+{
+
+ public GenericJavaXmlJavaTypeAdapterTests(String name) {
+ super(name);
+ }
+
+ private ICompilationUnit createPackageInfoWithXmlJavaTypeAdapter() throws CoreException {
+ return createTestPackageInfo(
+ "@XmlJavaTypeAdapter",
+ JAXB.XML_JAVA_TYPE_ADAPTER);
+ }
+
+
+ public void testModifyValue() throws Exception {
+ this.createPackageInfoWithXmlJavaTypeAdapter();
+ JaxbPackageInfo contextPackageInfo = CollectionTools.get(getRootContextNode().getPackages(), 0).getPackageInfo();
+ XmlJavaTypeAdapter contextXmlJavaTypeAdapter = contextPackageInfo.getXmlJavaTypeAdapters().iterator().next();
+ JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage();
+
+ assertNull(contextXmlJavaTypeAdapter.getValue());
+
+ contextXmlJavaTypeAdapter.setValue("foo");
+ XmlJavaTypeAdapterAnnotation javaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourcePackage.getAnnotation(XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME);
+ assertEquals("foo", javaTypeAdapterAnnotation.getValue());
+ assertEquals("foo", contextXmlJavaTypeAdapter.getValue());
+
+ //verify the xml schema type annotation is not removed when the value is set to null
+ contextXmlJavaTypeAdapter.setValue(null);
+ javaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourcePackage.getAnnotation(XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME);
+ assertNull(javaTypeAdapterAnnotation.getValue());
+ assertNull(contextXmlJavaTypeAdapter.getValue());
+ }
+
+ public void testUpdateValue() throws Exception {
+ this.createPackageInfoWithXmlJavaTypeAdapter();
+ JaxbPackageInfo contextPackageInfo = CollectionTools.get(getRootContextNode().getPackages(), 0).getPackageInfo();
+ XmlJavaTypeAdapter contextXmlJavaTypeAdapter = contextPackageInfo.getXmlJavaTypeAdapters().iterator().next();
+ JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage();
+
+ assertNull(contextXmlJavaTypeAdapter.getValue());
+
+ //add a value member value pair
+ AnnotatedElement annotatedElement = this.annotatedElement(resourcePackage);
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaXmlJavaTypeAdapterTests.this.addXmlJavaTypeAdapterTypeMemberValuePair(declaration, JAXB.XML_JAVA_TYPE_ADAPTER__VALUE, "String");
+ }
+ });
+ assertEquals("String", contextXmlJavaTypeAdapter.getValue());
+
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaXmlJavaTypeAdapterTests.this.removeXmlJavaTypeAdapterAnnotation(declaration);
+ }
+ });
+ assertFalse(contextPackageInfo.getXmlJavaTypeAdapters().iterator().hasNext());
+ }
+
+ public void testModifyType() throws Exception {
+ this.createPackageInfoWithXmlJavaTypeAdapter();
+ JaxbPackageInfo contextPackageInfo = CollectionTools.get(getRootContextNode().getPackages(), 0).getPackageInfo();
+ XmlJavaTypeAdapter contextXmlJavaTypeAdapter = contextPackageInfo.getXmlJavaTypeAdapters().iterator().next();
+ JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage();
+
+ assertEquals(XmlJavaTypeAdapter.DEFAULT_TYPE, contextXmlJavaTypeAdapter.getDefaultType());
+ assertEquals(XmlJavaTypeAdapter.DEFAULT_TYPE, contextXmlJavaTypeAdapter.getType());
+ assertNull(contextXmlJavaTypeAdapter.getSpecifiedType());
+
+ contextXmlJavaTypeAdapter.setSpecifiedType("foo");
+ XmlJavaTypeAdapterAnnotation javaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourcePackage.getAnnotation(XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME);
+ assertEquals("foo", javaTypeAdapterAnnotation.getType());
+ assertEquals(XmlJavaTypeAdapter.DEFAULT_TYPE, contextXmlJavaTypeAdapter.getDefaultType());
+ assertEquals("foo", contextXmlJavaTypeAdapter.getType());
+ assertEquals("foo", contextXmlJavaTypeAdapter.getSpecifiedType());
+
+ //verify the xml schema type annotation is not removed when the type is set to null
+ contextXmlJavaTypeAdapter.setSpecifiedType(null);
+ javaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourcePackage.getAnnotation(XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME);
+ assertNull(javaTypeAdapterAnnotation.getType());
+ assertEquals(XmlJavaTypeAdapter.DEFAULT_TYPE, contextXmlJavaTypeAdapter.getDefaultType());
+ assertEquals(XmlJavaTypeAdapter.DEFAULT_TYPE, contextXmlJavaTypeAdapter.getType());
+ assertNull(contextXmlJavaTypeAdapter.getSpecifiedType());
+ }
+
+ public void testUpdateType() throws Exception {
+ this.createPackageInfoWithXmlJavaTypeAdapter();
+ JaxbPackageInfo contextPackageInfo = CollectionTools.get(getRootContextNode().getPackages(), 0).getPackageInfo();
+ XmlJavaTypeAdapter contextXmlJavaTypeAdapter = contextPackageInfo.getXmlJavaTypeAdapters().iterator().next();
+ JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage();
+
+ assertEquals(XmlJavaTypeAdapter.DEFAULT_TYPE, contextXmlJavaTypeAdapter.getDefaultType());
+ assertEquals(XmlJavaTypeAdapter.DEFAULT_TYPE, contextXmlJavaTypeAdapter.getType());
+ assertNull(contextXmlJavaTypeAdapter.getSpecifiedType());
+
+ //add a type member value pair
+ AnnotatedElement annotatedElement = this.annotatedElement(resourcePackage);
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaXmlJavaTypeAdapterTests.this.addXmlJavaTypeAdapterTypeMemberValuePair(declaration, JAXB.XML_JAVA_TYPE_ADAPTER__TYPE, "String");
+ }
+ });
+ assertEquals(XmlJavaTypeAdapter.DEFAULT_TYPE, contextXmlJavaTypeAdapter.getDefaultType());
+ assertEquals("String", contextXmlJavaTypeAdapter.getType());
+ assertEquals("String", contextXmlJavaTypeAdapter.getSpecifiedType());
+
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaXmlJavaTypeAdapterTests.this.removeXmlJavaTypeAdapterAnnotation(declaration);
+ }
+ });
+ assertFalse(contextPackageInfo.getXmlJavaTypeAdapters().iterator().hasNext());
+ }
+
+ protected void addXmlJavaTypeAdapterTypeMemberValuePair(ModifiedDeclaration declaration, String name, String typeName) {
+ this.addMemberValuePair(
+ (MarkerAnnotation) this.getXmlJavaTypeAdapterAnnotation(declaration),
+ name,
+ this.newTypeLiteral(declaration.getAst(), typeName));
+ }
+
+ protected void addXmlJavaTypeAdapterMemberValuePair(ModifiedDeclaration declaration, String name, String value) {
+ this.addMemberValuePair((MarkerAnnotation) this.getXmlJavaTypeAdapterAnnotation(declaration), name, value);
+ }
+
+ //add another package annotation so that the context model object doesn't get removed when
+ //removing the XmlJavaTypeAdapter annotation. Only "annotated" packages are added to the context model
+ protected void removeXmlJavaTypeAdapterAnnotation(ModifiedDeclaration declaration) {
+ this.addMarkerAnnotation(declaration.getDeclaration(), XmlAccessorOrderAnnotation.ANNOTATION_NAME);
+ this.removeAnnotation(declaration, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME);
+ }
+
+ protected Annotation getXmlJavaTypeAdapterAnnotation(ModifiedDeclaration declaration) {
+ return declaration.getAnnotationNamed(XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME);
+ }
+}
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
index 951d789750..5c9a0ba418 100644
--- 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
@@ -207,7 +207,7 @@ public class GenericJavaXmlSchemaTypeTests extends JaxbContextModelTestCase
}
//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
+ //removing the XmlSchemaType 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);
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 ac91ffaec7..6935aa4445 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 class JaxbCoreJavaContextModelTests extends TestCase
public static Test suite() {
TestSuite suite = new TestSuite(JaxbCoreJavaContextModelTests.class.getName());
suite.addTestSuite(GenericJavaPackageInfoTests.class);
+ suite.addTestSuite(GenericJavaXmlJavaTypeAdapterTests.class);
suite.addTestSuite(GenericJavaXmlSchemaTests.class);
suite.addTestSuite(GenericJavaXmlSchemaTypeTests.class);
return suite;

Back to the top