Skip to main content
summaryrefslogtreecommitdiffstats
path: root/jaxb
diff options
context:
space:
mode:
authorkmoore2010-10-14 15:34:23 -0400
committerkmoore2010-10-14 15:34:23 -0400
commitca77a0ddd8abdef1ff267df7ab666b6100dc895a (patch)
tree2df27badf4eeeac85e294745e46e8ca903a373f6 /jaxb
parenta87a679c5a364444ffea3adabd6d28a1b823d586 (diff)
downloadwebtools.dali-ca77a0ddd8abdef1ff267df7ab666b6100dc895a.tar.gz
webtools.dali-ca77a0ddd8abdef1ff267df7ab666b6100dc895a.tar.xz
webtools.dali-ca77a0ddd8abdef1ff267df7ab666b6100dc895a.zip
JAXB java resource model for XmlType annotation
Diffstat (limited to 'jaxb')
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/.classpath2
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/META-INF/MANIFEST.MF19
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/GenericJaxbJpaAnnotationDefinitionProvider.java58
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/XmlTypeAnnotationDefinition.java62
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/binary/BinaryXmlTypeAnnotation.java203
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceXmlTypeAnnotation.java313
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/JAXB.java42
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/XmlTypeAnnotation.java163
8 files changed, 855 insertions, 7 deletions
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/.classpath b/jaxb/plugins/org.eclipse.jpt.jaxb.core/.classpath
index 5ee7c76127..dc10b33286 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/.classpath
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/.classpath
@@ -7,6 +7,8 @@
<accessrules>
<accessrule kind="accessible" pattern="org/eclipse/wst/**"/>
<accessrule kind="accessible" pattern="org/eclipse/jst/**"/>
+ <accessrule kind="accessible" pattern="org/eclipse/jpt/core/**"/>
+ <accessrule kind="accessible" pattern="org/eclipse/jpt/utility/**"/>
</accessrules>
</classpathentry>
<classpathentry kind="output" path="bin"/>
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/META-INF/MANIFEST.MF b/jaxb/plugins/org.eclipse.jpt.jaxb.core/META-INF/MANIFEST.MF
index dcdd25818f..28d4fa0768 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/META-INF/MANIFEST.MF
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/META-INF/MANIFEST.MF
@@ -19,10 +19,15 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.6.100,4.0.0)",
org.eclipse.wst.common.frameworks;bundle-version="[1.1.200,2.0.0)",
org.eclipse.wst.common.project.facet.core;bundle-version="[1.4.200,2.0.0)"
Export-Package: org.eclipse.jpt.jaxb.core,
- org.eclipse.jpt.jaxb.core.internal.facet,
- org.eclipse.jpt.jaxb.core.internal.gen,
- org.eclipse.jpt.jaxb.core.internal.jaxb22,
- org.eclipse.jpt.jaxb.core.internal.libprov,
- org.eclipse.jpt.jaxb.core.internal.operations,
- org.eclipse.jpt.jaxb.core.internal.platform,
- org.eclipse.jpt.jaxb.core.platform
+ org.eclipse.jpt.jaxb.core.internal;x-internal:=true,
+ org.eclipse.jpt.jaxb.core.internal.facet;x-internal:=true,
+ org.eclipse.jpt.jaxb.core.internal.gen;x-internal:=true,
+ org.eclipse.jpt.jaxb.core.internal.jaxb22;x-internal:=true,
+ org.eclipse.jpt.jaxb.core.internal.libprov;x-internal:=true,
+ org.eclipse.jpt.jaxb.core.internal.operations;x-internal:=true,
+ org.eclipse.jpt.jaxb.core.internal.platform;x-internal:=true,
+ org.eclipse.jpt.jaxb.core.internal.resource.java;x-internal:=true,
+ org.eclipse.jpt.jaxb.core.internal.resource.java.binary;x-internal:=true,
+ org.eclipse.jpt.jaxb.core.internal.resource.java.source;x-internal:=true,
+ org.eclipse.jpt.jaxb.core.platform,
+ org.eclipse.jpt.jaxb.core.resource.java
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/GenericJaxbJpaAnnotationDefinitionProvider.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/GenericJaxbJpaAnnotationDefinitionProvider.java
new file mode 100644
index 0000000000..11b3b7e51a
--- /dev/null
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/GenericJaxbJpaAnnotationDefinitionProvider.java
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * 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;
+
+import java.util.List;
+import org.eclipse.jpt.core.JpaAnnotationDefinitionProvider;
+import org.eclipse.jpt.core.internal.AbstractJpaAnnotationDefintionProvider;
+import org.eclipse.jpt.core.resource.java.AnnotationDefinition;
+import org.eclipse.jpt.jaxb.core.internal.resource.java.XmlTypeAnnotationDefinition;
+
+/**
+ * Support for JAXB annotations
+ */
+public class GenericJaxbJpaAnnotationDefinitionProvider
+ extends AbstractJpaAnnotationDefintionProvider
+{
+ // singleton
+ private static final JpaAnnotationDefinitionProvider INSTANCE =
+ new GenericJaxbJpaAnnotationDefinitionProvider();
+
+
+ /**
+ * Return the singleton
+ */
+ public static JpaAnnotationDefinitionProvider instance() {
+ return INSTANCE;
+ }
+
+
+ /**
+ * Enforce singleton usage
+ */
+ private GenericJaxbJpaAnnotationDefinitionProvider() {
+ super();
+ }
+
+
+ @Override
+ protected void addTypeAnnotationDefinitionsTo(List<AnnotationDefinition> definitions) {
+ definitions.add(XmlTypeAnnotationDefinition.instance());
+ }
+
+ @Override
+ protected void addTypeMappingAnnotationDefinitionsTo(List<AnnotationDefinition> definitions) {
+ definitions.add(XmlTypeAnnotationDefinition.instance());
+ }
+
+ @Override
+ protected void addAttributeAnnotationDefinitionsTo(List<AnnotationDefinition> definitions) {
+ }
+}
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
new file mode 100644
index 0000000000..475b763c1c
--- /dev/null
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/XmlTypeAnnotationDefinition.java
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * 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.IAnnotation;
+import org.eclipse.jpt.core.resource.java.Annotation;
+import org.eclipse.jpt.core.resource.java.AnnotationDefinition;
+import org.eclipse.jpt.core.resource.java.JavaResourceAnnotatedElement;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.core.utility.jdt.AnnotatedElement;
+import org.eclipse.jpt.core.utility.jdt.Type;
+import org.eclipse.jpt.jaxb.core.internal.resource.java.binary.BinaryXmlTypeAnnotation;
+import org.eclipse.jpt.jaxb.core.internal.resource.java.source.SourceXmlTypeAnnotation;
+import org.eclipse.jpt.jaxb.core.resource.java.XmlTypeAnnotation;
+
+/**
+ * javax.xml.bind.annotation.XmlType
+ */
+public final class XmlTypeAnnotationDefinition
+ implements AnnotationDefinition
+{
+ // singleton
+ private static final AnnotationDefinition INSTANCE = new XmlTypeAnnotationDefinition();
+
+ /**
+ * Return the singleton.
+ */
+ public static AnnotationDefinition instance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Ensure single instance.
+ */
+ private XmlTypeAnnotationDefinition() {
+ super();
+ }
+
+ public Annotation buildAnnotation(JavaResourceAnnotatedElement parent, AnnotatedElement annotatedElement) {
+ return new SourceXmlTypeAnnotation((JavaResourcePersistentType) parent, (Type) annotatedElement);
+ }
+
+ public Annotation buildNullAnnotation(JavaResourceAnnotatedElement parent) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Annotation buildAnnotation(JavaResourceAnnotatedElement parent, IAnnotation jdtAnnotation) {
+ return new BinaryXmlTypeAnnotation((JavaResourcePersistentType) parent, jdtAnnotation);
+ }
+
+ public String getAnnotationName() {
+ return XmlTypeAnnotation.ANNOTATION_NAME;
+ }
+
+}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/binary/BinaryXmlTypeAnnotation.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/binary/BinaryXmlTypeAnnotation.java
new file mode 100644
index 0000000000..2a6cd5fe35
--- /dev/null
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/binary/BinaryXmlTypeAnnotation.java
@@ -0,0 +1,203 @@
+/*******************************************************************************
+ * 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.binary;
+
+import java.util.Vector;
+import org.eclipse.jdt.core.IAnnotation;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jpt.core.internal.resource.java.binary.BinaryAnnotation;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.core.utility.TextRange;
+import org.eclipse.jpt.jaxb.core.resource.java.JAXB;
+import org.eclipse.jpt.jaxb.core.resource.java.XmlTypeAnnotation;
+import org.eclipse.jpt.utility.internal.iterables.ListIterable;
+import org.eclipse.jpt.utility.internal.iterables.LiveCloneListIterable;
+
+/**
+ * javax.xml.bind.annotation.XmlType
+ */
+public final class BinaryXmlTypeAnnotation
+ extends BinaryAnnotation
+ implements XmlTypeAnnotation
+{
+ private String factoryClass;
+ private String factoryMethod;
+ private String name;
+ private String namespace;
+ private final Vector<String> propOrder;
+
+
+ public BinaryXmlTypeAnnotation(JavaResourcePersistentType parent, IAnnotation jdtAnnotation) {
+ super(parent, jdtAnnotation);
+ this.factoryClass = this.buildFactoryClass();
+ this.factoryMethod = this.buildFactoryMethod();
+ this.name = this.buildName();
+ this.namespace = this.buildNamespace();
+ this.propOrder = this.buildPropOrder();
+ }
+
+ public String getAnnotationName() {
+ return ANNOTATION_NAME;
+ }
+
+ @Override
+ public void update() {
+ super.update();
+ this.setFactoryClass_(this.buildFactoryClass());
+ this.setFactoryMethod_(this.buildFactoryMethod());
+ this.setName_(this.buildName());
+ this.setNamespace_(this.buildNamespace());
+ }
+
+ @Override
+ public void toString(StringBuilder sb) {
+ sb.append(this.name);
+ }
+
+
+ // ********** XmlTypeAnnotation implementation **********
+
+ // ***** factoryClass
+ public String getFactoryClass() {
+ return this.factoryClass;
+ }
+
+ public void setFactoryClass(String factoryClass) {
+ throw new UnsupportedOperationException();
+ }
+
+ private void setFactoryClass_(String factoryClass) {
+ String old = this.factoryClass;
+ this.factoryClass = factoryClass;
+ this.firePropertyChanged(FACTORY_CLASS_PROPERTY, old, factoryClass);
+ this.firePropertyChanged(FULLY_QUALIFIED_FACTORY_CLASS_NAME_PROPERTY, old, factoryClass);
+ }
+
+ private String buildFactoryClass() {
+ return (String) this.getJdtMemberValue(JAXB.XML_TYPE__FACTORY_CLASS);
+ }
+
+ public TextRange getFactoryClassTextRange(CompilationUnit astRoot) {
+ throw new UnsupportedOperationException();
+ }
+
+ // ***** fully-qualified factory class name
+ public String getFullyQualifiedFactoryClassName() {
+ return this.factoryClass;
+ }
+
+ // ***** factoryMethod
+ public String getFactoryMethod() {
+ return this.factoryMethod;
+ }
+
+ public void setFactoryMethod(String factoryMethod) {
+ throw new UnsupportedOperationException();
+ }
+
+ private void setFactoryMethod_(String factoryMethod) {
+ String old = this.factoryMethod;
+ this.factoryMethod = factoryMethod;
+ this.firePropertyChanged(FACTORY_METHOD_PROPERTY, old, factoryMethod);
+ }
+
+ private String buildFactoryMethod() {
+ return (String) this.getJdtMemberValue(JAXB.XML_TYPE__FACTORY_METHOD);
+ }
+
+ public TextRange getFactoryMethodTextRange(CompilationUnit astRoot) {
+ throw new UnsupportedOperationException();
+ }
+
+ // ***** name
+ public String getName() {
+ return this.name;
+ }
+
+ public void setName(String name) {
+ throw new UnsupportedOperationException();
+ }
+
+ private void setName_(String name) {
+ String old = this.name;
+ this.name = name;
+ this.firePropertyChanged(NAME_PROPERTY, old, name);
+ }
+
+ private String buildName() {
+ return (String) this.getJdtMemberValue(JAXB.XML_TYPE__NAME);
+ }
+
+ public TextRange getNameTextRange(CompilationUnit astRoot) {
+ throw new UnsupportedOperationException();
+ }
+
+ // ***** namespace
+ public String getNamespace() {
+ return this.namespace;
+ }
+
+ public void setNamespace(String namespace) {
+ throw new UnsupportedOperationException();
+ }
+
+ private void setNamespace_(String namespace) {
+ String old = this.namespace;
+ this.namespace = namespace;
+ this.firePropertyChanged(NAMESPACE_PROPERTY, old, namespace);
+ }
+
+ private String buildNamespace() {
+ return (String) this.getJdtMemberValue(JAXB.XML_TYPE__NAMESPACE);
+ }
+
+ public TextRange getNamespaceTextRange(CompilationUnit astRoot) {
+ throw new UnsupportedOperationException();
+ }
+
+ // ***** prop order
+ public ListIterable<String> getPropOrder() {
+ return new LiveCloneListIterable<String>(this.propOrder);
+ }
+
+ public int getPropOrderSize() {
+ return this.propOrder.size();
+ }
+
+ private Vector<String> buildPropOrder() {
+ Object[] jdtPropOrder = this.getJdtMemberValues(JAXB.XML_TYPE__PROP_ORDER);
+ Vector<String> result = new Vector<String>(jdtPropOrder.length);
+ for (Object jdtProp : jdtPropOrder) {
+ result.add((String) jdtProp);
+ }
+ return result;
+ }
+
+ public void addProp(String propOrder) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void addProp(int index, String propOrder) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void moveProp(int targetIndex, int sourceIndex) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void removeProp(String propOrder) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void removeProp(int index) {
+ throw new UnsupportedOperationException();
+ }
+
+}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceXmlTypeAnnotation.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceXmlTypeAnnotation.java
new file mode 100644
index 0000000000..ea5391cd7e
--- /dev/null
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceXmlTypeAnnotation.java
@@ -0,0 +1,313 @@
+/*******************************************************************************
+ * 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.source;
+
+import java.util.Arrays;
+import java.util.Vector;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jpt.core.internal.resource.java.source.SourceAnnotation;
+import org.eclipse.jpt.core.internal.utility.jdt.ASTTools;
+import org.eclipse.jpt.core.internal.utility.jdt.AnnotationStringArrayExpressionConverter;
+import org.eclipse.jpt.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter;
+import org.eclipse.jpt.core.internal.utility.jdt.AnnotatedElementAnnotationElementAdapter;
+import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter;
+import org.eclipse.jpt.core.internal.utility.jdt.SimpleTypeStringExpressionConverter;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.core.utility.TextRange;
+import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter;
+import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter;
+import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter;
+import org.eclipse.jpt.core.utility.jdt.ExpressionConverter;
+import org.eclipse.jpt.core.utility.jdt.Type;
+import org.eclipse.jpt.jaxb.core.resource.java.JAXB;
+import org.eclipse.jpt.jaxb.core.resource.java.XmlTypeAnnotation;
+import org.eclipse.jpt.utility.internal.CollectionTools;
+import org.eclipse.jpt.utility.internal.iterables.ListIterable;
+import org.eclipse.jpt.utility.internal.iterables.LiveCloneListIterable;
+
+/**
+ * javax.xml.bind.annotation.XmlType
+ */
+public final class SourceXmlTypeAnnotation
+ extends SourceAnnotation<Type>
+ implements XmlTypeAnnotation
+{
+ public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME);
+
+ private static final DeclarationAnnotationElementAdapter<String> FACTORY_CLASS_ADAPTER = buildFactoryClassAdapter();
+ private final AnnotationElementAdapter<String> factoryClassAdapter;
+ private String factoryClass;
+
+ private String fullyQualifiedFactoryClassName;
+
+ private static final DeclarationAnnotationElementAdapter<String> FACTORY_METHOD_ADAPTER = buildFactoryMethodAdapter();
+ private final AnnotationElementAdapter<String> factoryMethodAdapter;
+ private String factoryMethod;
+
+ private static final DeclarationAnnotationElementAdapter<String> NAME_ADAPTER = buildNameAdapter();
+ private final AnnotationElementAdapter<String> nameAdapter;
+ private String name;
+
+ private static final DeclarationAnnotationElementAdapter<String> NAMESPACE_ADAPTER = buildNamespaceAdapter();
+ private final AnnotationElementAdapter<String> namespaceAdapter;
+ private String namespace;
+
+ private final DeclarationAnnotationElementAdapter<String[]> propOrderDeclarationAdapter;
+ private final AnnotationElementAdapter<String[]> propOrderAdapter;
+ private final Vector<String> propOrder = new Vector<String>();
+
+ public SourceXmlTypeAnnotation(JavaResourcePersistentType parent, Type type) {
+ super(parent, type, DECLARATION_ANNOTATION_ADAPTER);
+ this.factoryClassAdapter = this.buildAnnotationElementAdapter(FACTORY_CLASS_ADAPTER);
+ this.factoryMethodAdapter = this.buildAnnotationElementAdapter(FACTORY_METHOD_ADAPTER);
+ this.nameAdapter = this.buildAnnotationElementAdapter(NAME_ADAPTER);
+ this.namespaceAdapter = this.buildAnnotationElementAdapter(NAMESPACE_ADAPTER);
+ this.propOrderDeclarationAdapter = buildArrayAnnotationElementAdapter(DECLARATION_ANNOTATION_ADAPTER, JAXB.XML_TYPE__PROP_ORDER);
+ this.propOrderAdapter = this.buildArrayAnnotationElementAdapter(this.propOrderDeclarationAdapter);
+ }
+
+ protected AnnotationElementAdapter<String> buildAnnotationElementAdapter(DeclarationAnnotationElementAdapter<String> daea) {
+ return new AnnotatedElementAnnotationElementAdapter<String>(this.annotatedElement, daea);
+ }
+
+ private static DeclarationAnnotationElementAdapter<String[]> buildArrayAnnotationElementAdapter(DeclarationAnnotationAdapter annotationAdapter, String elementName) {
+ return buildArrayAnnotationElementAdapter(annotationAdapter, elementName, AnnotationStringArrayExpressionConverter.forStrings());
+ }
+
+ private static DeclarationAnnotationElementAdapter<String[]> buildArrayAnnotationElementAdapter(DeclarationAnnotationAdapter annotationAdapter, String elementName, ExpressionConverter<String[]> converter) {
+ return new ConversionDeclarationAnnotationElementAdapter<String[]>(annotationAdapter, elementName, false, converter);
+ }
+
+ private AnnotationElementAdapter<String[]> buildArrayAnnotationElementAdapter(DeclarationAnnotationElementAdapter<String[]> daea) {
+ return new AnnotatedElementAnnotationElementAdapter<String[]>(this.annotatedElement, daea);
+ }
+
+ public String getAnnotationName() {
+ return ANNOTATION_NAME;
+ }
+
+ public void initialize(CompilationUnit astRoot) {
+ this.factoryClass = this.buildFactoryClass(astRoot);
+ this.fullyQualifiedFactoryClassName = this.buildFullyQualifiedFactoryClassName(astRoot);
+ this.factoryMethod = this.buildFactoryMethod(astRoot);
+ this.name = this.buildName(astRoot);
+ this.namespace = this.buildNamespace(astRoot);
+ this.initializePropOrder(astRoot);
+ }
+
+ public void synchronizeWith(CompilationUnit astRoot) {
+ this.syncFactoryClass(this.buildFactoryClass(astRoot));
+ this.syncFullyQualifiedFactoryClassName(this.buildFullyQualifiedFactoryClassName(astRoot));
+ this.syncFactoryMethod(this.buildFactoryMethod(astRoot));
+ this.syncName(this.buildName(astRoot));
+ this.syncNamespace(this.buildNamespace(astRoot));
+ this.syncPropOrder(astRoot);
+ }
+
+ @Override
+ public void toString(StringBuilder sb) {
+ sb.append(this.name);
+ }
+
+
+ // ********** XmlTypeAnnotation implementation **********
+
+ // ***** factoryClass
+ public String getFactoryClass() {
+ return this.factoryClass;
+ }
+
+ public void setFactoryClass(String factoryClass) {
+ if (this.attributeValueHasChanged(this.factoryClass, factoryClass)) {
+ this.factoryClass = factoryClass;
+ this.factoryClassAdapter.setValue(factoryClass);
+ }
+ }
+
+ private void syncFactoryClass(String astFactoryClass) {
+ String old = this.factoryClass;
+ this.factoryClass = astFactoryClass;
+ this.firePropertyChanged(FACTORY_CLASS_PROPERTY, old, astFactoryClass);
+ }
+
+ private String buildFactoryClass(CompilationUnit astRoot) {
+ return this.factoryClassAdapter.getValue(astRoot);
+ }
+
+ public TextRange getFactoryClassTextRange(CompilationUnit astRoot) {
+ return this.getElementTextRange(FACTORY_CLASS_ADAPTER, astRoot);
+ }
+
+ // ***** fully-qualified factory class name
+ public String getFullyQualifiedFactoryClassName() {
+ return this.fullyQualifiedFactoryClassName;
+ }
+
+ private void syncFullyQualifiedFactoryClassName(String name) {
+ String old = this.fullyQualifiedFactoryClassName;
+ this.fullyQualifiedFactoryClassName = name;
+ this.firePropertyChanged(FULLY_QUALIFIED_FACTORY_CLASS_NAME_PROPERTY, old, name);
+ }
+
+ private String buildFullyQualifiedFactoryClassName(CompilationUnit astRoot) {
+ return (this.factoryClass == null) ? null : ASTTools.resolveFullyQualifiedName(this.factoryClassAdapter.getExpression(astRoot));
+ }
+
+ // ***** factoryMethod
+ public String getFactoryMethod() {
+ return this.factoryMethod;
+ }
+
+ public void setFactoryMethod(String factoryMethod) {
+ if (this.attributeValueHasChanged(this.factoryMethod, factoryMethod)) {
+ this.factoryMethod = factoryMethod;
+ this.factoryMethodAdapter.setValue(factoryMethod);
+ }
+ }
+
+ private void syncFactoryMethod(String astFactoryMethod) {
+ String old = this.factoryMethod;
+ this.factoryMethod = astFactoryMethod;
+ this.firePropertyChanged(FACTORY_METHOD_PROPERTY, old, astFactoryMethod);
+ }
+
+ private String buildFactoryMethod(CompilationUnit astRoot) {
+ return this.factoryMethodAdapter.getValue(astRoot);
+ }
+
+ public TextRange getFactoryMethodTextRange(CompilationUnit astRoot) {
+ return this.getElementTextRange(FACTORY_METHOD_ADAPTER, astRoot);
+ }
+
+ // ***** name
+ public String getName() {
+ return this.name;
+ }
+
+ public void setName(String name) {
+ if (this.attributeValueHasChanged(this.name, name)) {
+ this.name = name;
+ this.nameAdapter.setValue(name);
+ }
+ }
+
+ private void syncName(String astName) {
+ String old = this.name;
+ this.name = astName;
+ this.firePropertyChanged(NAME_PROPERTY, old, astName);
+ }
+
+ private String buildName(CompilationUnit astRoot) {
+ return this.nameAdapter.getValue(astRoot);
+ }
+
+ public TextRange getNameTextRange(CompilationUnit astRoot) {
+ return this.getElementTextRange(NAME_ADAPTER, astRoot);
+ }
+
+ // ***** name
+ public String getNamespace() {
+ return this.namespace;
+ }
+
+ public void setNamespace(String namespace) {
+ if (this.attributeValueHasChanged(this.namespace, namespace)) {
+ this.namespace = namespace;
+ this.namespaceAdapter.setValue(namespace);
+ }
+ }
+
+ private void syncNamespace(String astNamespace) {
+ String old = this.namespace;
+ this.namespace = astNamespace;
+ this.firePropertyChanged(NAMESPACE_PROPERTY, old, astNamespace);
+ }
+
+ private String buildNamespace(CompilationUnit astRoot) {
+ return this.namespaceAdapter.getValue(astRoot);
+ }
+
+ public TextRange getNamespaceTextRange(CompilationUnit astRoot) {
+ return this.getElementTextRange(NAMESPACE_ADAPTER, astRoot);
+ }
+
+ // ***** prop order
+ public ListIterable<String> getPropOrder() {
+ return new LiveCloneListIterable<String>(this.propOrder);
+ }
+
+ public int getPropOrderSize() {
+ return this.propOrder.size();
+ }
+
+ public void addProp(String prop) {
+ this.addProp(this.propOrder.size(), prop);
+ }
+
+ public void addProp(int index, String prop) {
+ this.propOrder.add(index, prop);
+ this.writePropOrder();
+ }
+
+ public void moveProp(int targetIndex, int sourceIndex) {
+ CollectionTools.move(this.propOrder, targetIndex, sourceIndex);
+ this.writePropOrder();
+ }
+
+ public void removeProp(String prop) {
+ this.propOrder.remove(prop);
+ this.writePropOrder();
+ }
+
+ public void removeProp(int index) {
+ this.propOrder.remove(index);
+ this.writePropOrder();
+ }
+
+ private void writePropOrder() {
+ this.propOrderAdapter.setValue(this.propOrder.toArray(new String[this.propOrder.size()]));
+ }
+
+ private void initializePropOrder(CompilationUnit astRoot) {
+ String[] astPropOrder = this.propOrderAdapter.getValue(astRoot);
+ for (int i = 0; i < astPropOrder.length; i++) {
+ this.propOrder.add(astPropOrder[i]);
+ }
+ }
+
+ private void syncPropOrder(CompilationUnit astRoot) {
+ String[] astPropOrder = this.propOrderAdapter.getValue(astRoot);
+ this.synchronizeList(Arrays.asList(astPropOrder), this.propOrder, PROP_ORDER_LIST);
+ }
+
+
+ //*********** static methods ****************
+
+ private static DeclarationAnnotationElementAdapter<String> buildFactoryClassAdapter() {
+ return buildAnnotationElementAdapter(DECLARATION_ANNOTATION_ADAPTER, JAXB.XML_TYPE__FACTORY_CLASS, SimpleTypeStringExpressionConverter.instance());
+ }
+
+ static DeclarationAnnotationElementAdapter<String> buildAnnotationElementAdapter(DeclarationAnnotationAdapter annotationAdapter, String elementName, ExpressionConverter<String> converter) {
+ return new ConversionDeclarationAnnotationElementAdapter<String>(annotationAdapter, elementName, false, converter);
+ }
+
+ private static DeclarationAnnotationElementAdapter<String> buildFactoryMethodAdapter() {
+ return ConversionDeclarationAnnotationElementAdapter.forStrings(DECLARATION_ANNOTATION_ADAPTER, JAXB.XML_TYPE__FACTORY_METHOD, false); // false = do not remove annotation when empty
+ }
+
+ private static DeclarationAnnotationElementAdapter<String> buildNameAdapter() {
+ return ConversionDeclarationAnnotationElementAdapter.forStrings(DECLARATION_ANNOTATION_ADAPTER, JAXB.XML_TYPE__NAME, false); // false = do not remove annotation when empty
+ }
+
+ private static DeclarationAnnotationElementAdapter<String> buildNamespaceAdapter() {
+ return ConversionDeclarationAnnotationElementAdapter.forStrings(DECLARATION_ANNOTATION_ADAPTER, JAXB.XML_TYPE__NAMESPACE, false); // false = do not remove annotation when empty
+ }
+
+}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/JAXB.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/JAXB.java
new file mode 100644
index 0000000000..fc8422bb91
--- /dev/null
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/JAXB.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * 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.resource.java;
+
+/**
+ * JAXB Java-related stuff (annotations etc.)
+ * <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
+ */
+@SuppressWarnings("nls")
+public interface JAXB {
+
+ // JAXB package
+ String PACKAGE = "javax.xml.bind.annotation";
+ String PACKAGE_ = PACKAGE + '.';
+
+
+ // ********** API **********
+
+ // JAXB annotations
+ String XML_TYPE = PACKAGE_ + "XmlType";
+ String XML_TYPE__FACTORY_CLASS = "factoryClass";
+ String XML_TYPE__FACTORY_METHOD = "factoryMethod";
+ String XML_TYPE__NAME = "name";
+ String XML_TYPE__NAMESPACE = "namespace";
+ String XML_TYPE__PROP_ORDER = "propOrder";
+
+}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/XmlTypeAnnotation.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/XmlTypeAnnotation.java
new file mode 100644
index 0000000000..e00dc88701
--- /dev/null
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/XmlTypeAnnotation.java
@@ -0,0 +1,163 @@
+/*******************************************************************************
+ * 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.resource.java;
+
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jpt.core.resource.java.Annotation;
+import org.eclipse.jpt.core.utility.TextRange;
+import org.eclipse.jpt.utility.internal.iterables.ListIterable;
+
+/**
+ * Corresponds to the JAXB annotation
+ * javax.xml.bind.annotation.XmlType
+ *
+ * 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 XmlTypeAnnotation
+ extends Annotation
+{
+ String ANNOTATION_NAME = JAXB.XML_TYPE;
+
+ /**
+ * Corresponds to the 'factoryClass' element of the XmlType annotation.
+ * Return null if the element does not exist in Java.
+ * Return the portion of the value preceding ".class".
+ * <pre>
+ * &#64;XmlType(name="USAddressType", factoryClass=USAddressFactory.class)
+ * </pre>
+ * will return "USAddressFactory"
+ */
+ String getFactoryClass();
+ String FACTORY_CLASS_PROPERTY = "factoryClass"; //$NON-NLS-1$
+
+ /**
+ * Corresponds to the 'factoryClass' element of the XmlType annotation.
+ * Set to null to remove the element.
+ */
+ void setFactoryClass(String factoryClass);
+ /**
+ * Return the {@link TextRange} for the 'factoryClass' element. If the element
+ * does not exist return the {@link TextRange} for the XmlType annotation.
+ */
+ TextRange getFactoryClassTextRange(CompilationUnit astRoot);
+
+ /**
+ * Return the fully-qualified factory class name as resolved by the AST's bindings.
+ * <pre>
+ * &#64;XmlType(name="USAddressType", factoryClass=USAddressFactory.class)
+ * </pre>
+ * will return "model.USAddressFactory" if there is an import for model.USAddressFactory.
+ * @return
+ */
+ String getFullyQualifiedFactoryClassName();
+ String FULLY_QUALIFIED_FACTORY_CLASS_NAME_PROPERTY = "fullyQualifiedFactoryClassName"; //$NON-NLS-1$
+
+ /**
+ * Corresponds to the 'factoryMethod' element of the XmlType annotation.
+ * Return null if the element does not exist in Java.
+ */
+ String getFactoryMethod();
+ String FACTORY_METHOD_PROPERTY = "factoryMethod"; //$NON-NLS-1$
+
+ /**
+ * Corresponds to the 'factoryMethod' element of the XmlType annotation.
+ * Set to null to remove the element.
+ */
+ void setFactoryMethod(String factoryMethod);
+
+ /**
+ * Return the {@link TextRange} for the 'factoryMethod' element. If the element
+ * does not exist return the {@link TextRange} for the XmlType annotation.
+ */
+ TextRange getFactoryMethodTextRange(CompilationUnit astRoot);
+
+ /**
+ * Corresponds to the 'name' element of the XmlType annotation.
+ * Return null if the element does not exist in Java.
+ */
+ String getName();
+ String NAME_PROPERTY = "name"; //$NON-NLS-1$
+
+ /**
+ * Corresponds to the 'name' element of the XmlType annotation.
+ * Set to null to remove the element.
+ */
+ void setName(String name);
+
+ /**
+ * Return the {@link TextRange} for the 'name' element. If the element
+ * does not exist return the {@link TextRange} for the XmlType annotation.
+ */
+ TextRange getNameTextRange(CompilationUnit astRoot);
+
+ /**
+ * Corresponds to the 'namespace' element of the XmlType annotation.
+ * Return null if the element does not exist in Java.
+ */
+ String getNamespace();
+ String NAMESPACE_PROPERTY = "namespace"; //$NON-NLS-1$
+
+ /**
+ * Corresponds to the 'namespace' element of the XmlType annotation.
+ * Set to null to remove the element.
+ */
+ void setNamespace(String namespace);
+
+ /**
+ * Return the {@link TextRange} for the 'namespace' element. If the element
+ * does not exist return the {@link TextRange} for the XmlType annotation.
+ */
+ TextRange getNamespaceTextRange(CompilationUnit astRoot);
+
+ /**
+ * Corresponds to the 'propOrder' element of the XmlType annotation.
+ * Return an empty iterator if the element does not exist in Java.
+ */
+ ListIterable<String> getPropOrder();
+ String PROP_ORDER_LIST = "propOrder"; //$NON-NLS-1$
+
+ /**
+ * Corresponds to the 'propOrder' element of the XmlType annotation.
+ */
+ int getPropOrderSize();
+
+ /**
+ * Corresponds to the 'propOrder' element of the XmlType annotation.
+ */
+ void addProp(String prop);
+
+ /**
+ * Corresponds to the 'propOrder' element of the XmlType annotation.
+ */
+ void addProp(int index, String prop);
+
+ /**
+ * Corresponds to the 'propOrder' element of the XmlType annotation.
+ */
+ void moveProp(int targetIndex, int sourceIndex);
+
+ /**
+ * Corresponds to the 'propOrder' element of the XmlType annotation.
+ */
+ void removeProp(String prop);
+
+ /**
+ * Corresponds to the 'propOrder' element of the XmlType annotation.
+ */
+ void removeProp(int index);
+
+}

Back to the top