diff options
author | kmoore | 2010-10-18 17:44:21 +0000 |
---|---|---|
committer | kmoore | 2010-10-18 17:44:21 +0000 |
commit | 88327752a0023a4c4cfd768cfff74ea71ef2629e (patch) | |
tree | 6f7b003e54171afb6508bc94e1b079c05cfbabee | |
parent | 3a44458dc063734b1c99f667af2c5c1a198040e3 (diff) | |
download | webtools.dali-88327752a0023a4c4cfd768cfff74ea71ef2629e.tar.gz webtools.dali-88327752a0023a4c4cfd768cfff74ea71ef2629e.tar.xz webtools.dali-88327752a0023a4c4cfd768cfff74ea71ef2629e.zip |
327914 - JAXB java resource model and tests for XmlRegistry annotation
8 files changed, 225 insertions, 0 deletions
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 index a3d7ce2278..e2e802042c 100644 --- 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 @@ -19,6 +19,7 @@ import org.eclipse.jpt.jaxb.core.internal.resource.java.XmlEnumAnnotationDefinit import org.eclipse.jpt.jaxb.core.internal.resource.java.XmlInlineBinaryDataAnnotationDefinition; import org.eclipse.jpt.jaxb.core.internal.resource.java.XmlJavaTypeAdapterAnnotationDefinition; import org.eclipse.jpt.jaxb.core.internal.resource.java.XmlJavaTypeAdaptersAnnotationDefinition; +import org.eclipse.jpt.jaxb.core.internal.resource.java.XmlRegistryAnnotationDefinition; import org.eclipse.jpt.jaxb.core.internal.resource.java.XmlRootElementAnnotationDefinition; import org.eclipse.jpt.jaxb.core.internal.resource.java.XmlSeeAlsoAnnotationDefinition; import org.eclipse.jpt.jaxb.core.internal.resource.java.XmlTransientAnnotationDefinition; @@ -67,6 +68,7 @@ public class GenericJaxbJpaAnnotationDefinitionProvider definitions.add(XmlInlineBinaryDataAnnotationDefinition.instance()); definitions.add(XmlJavaTypeAdapterAnnotationDefinition.instance()); definitions.add(XmlJavaTypeAdaptersAnnotationDefinition.instance()); + definitions.add(XmlRegistryAnnotationDefinition.instance()); definitions.add(XmlRootElementAnnotationDefinition.instance()); definitions.add(XmlSeeAlsoAnnotationDefinition.instance()); definitions.add(XmlTransientAnnotationDefinition.instance()); @@ -75,6 +77,7 @@ public class GenericJaxbJpaAnnotationDefinitionProvider @Override protected void addTypeMappingAnnotationDefinitionsTo(List<AnnotationDefinition> definitions) { + definitions.add(XmlRegistryAnnotationDefinition.instance()); definitions.add(XmlTransientAnnotationDefinition.instance()); definitions.add(XmlTypeAnnotationDefinition.instance()); } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/XmlRegistryAnnotationDefinition.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/XmlRegistryAnnotationDefinition.java new file mode 100644 index 0000000000..863a86388f --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/XmlRegistryAnnotationDefinition.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.BinaryXmlRegistryAnnotation; +import org.eclipse.jpt.jaxb.core.internal.resource.java.source.SourceXmlRegistryAnnotation; +import org.eclipse.jpt.jaxb.core.resource.java.XmlRegistryAnnotation; + +/** + * javax.xml.bind.annotation.XmlRegistry + */ +public final class XmlRegistryAnnotationDefinition + implements AnnotationDefinition +{ + // singleton + private static final AnnotationDefinition INSTANCE = new XmlRegistryAnnotationDefinition(); + + /** + * Return the singleton. + */ + public static AnnotationDefinition instance() { + return INSTANCE; + } + + /** + * Ensure single instance. + */ + private XmlRegistryAnnotationDefinition() { + super(); + } + + public Annotation buildAnnotation(JavaResourceAnnotatedElement parent, AnnotatedElement annotatedElement) { + return new SourceXmlRegistryAnnotation((JavaResourcePersistentType) parent, (Type) annotatedElement); + } + + public Annotation buildNullAnnotation(JavaResourceAnnotatedElement parent) { + throw new UnsupportedOperationException(); + } + + public Annotation buildAnnotation(JavaResourceAnnotatedElement parent, IAnnotation jdtAnnotation) { + return new BinaryXmlRegistryAnnotation((JavaResourcePersistentType) parent, jdtAnnotation); + } + + public String getAnnotationName() { + return XmlRegistryAnnotation.ANNOTATION_NAME; + } + +} diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/binary/BinaryXmlRegistryAnnotation.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/binary/BinaryXmlRegistryAnnotation.java new file mode 100644 index 0000000000..c1a77342af --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/binary/BinaryXmlRegistryAnnotation.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * 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 org.eclipse.jdt.core.IAnnotation; +import org.eclipse.jpt.core.internal.resource.java.binary.BinaryAnnotation; +import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; +import org.eclipse.jpt.jaxb.core.resource.java.XmlRegistryAnnotation; + +/** + * javax.xml.bind.annotation.XmlRegistry + */ +public final class BinaryXmlRegistryAnnotation + extends BinaryAnnotation + implements XmlRegistryAnnotation +{ + + public BinaryXmlRegistryAnnotation(JavaResourcePersistentType parent, IAnnotation jdtAnnotation) { + super(parent, jdtAnnotation); + } + + public String getAnnotationName() { + return ANNOTATION_NAME; + } +} diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceXmlRegistryAnnotation.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceXmlRegistryAnnotation.java new file mode 100644 index 0000000000..17abb6be80 --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceXmlRegistryAnnotation.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * 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 org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jpt.core.internal.resource.java.source.SourceAnnotation; +import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; +import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; +import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; +import org.eclipse.jpt.core.utility.jdt.Type; +import org.eclipse.jpt.jaxb.core.resource.java.XmlRegistryAnnotation; + +/** + * javax.xml.bind.annotation.XmlRegistry + */ +public final class SourceXmlRegistryAnnotation + extends SourceAnnotation<Type> + implements XmlRegistryAnnotation +{ + public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); + + public SourceXmlRegistryAnnotation(JavaResourcePersistentType parent, Type type) { + super(parent, type, DECLARATION_ANNOTATION_ADAPTER); + } + + public String getAnnotationName() { + return ANNOTATION_NAME; + } + + public void initialize(CompilationUnit astRoot) { + //no-op + } + + public void synchronizeWith(CompilationUnit astRoot) { + //no-op + } +} 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 index 5686281b52..857e967bcc 100644 --- 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 @@ -45,6 +45,8 @@ public interface JAXB { String XML_INLINE_BINARY_DATA = PACKAGE_ + "XmlInlineBinaryData"; + String XML_REGISTRY = PACKAGE_ + "XmlRegistry"; + String XML_ROOT_ELEMENT = PACKAGE_ + "XmlRootElement"; String XML_ROOT_ELEMENT__NAME = "name"; String XML_ROOT_ELEMENT__NAMESPACE = "namespace"; diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/XmlRegistryAnnotation.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/XmlRegistryAnnotation.java new file mode 100644 index 0000000000..6f3aceac16 --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/XmlRegistryAnnotation.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * 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.jpt.core.resource.java.Annotation; + +/** + * Corresponds to the JAXB annotation + * javax.xml.bind.annotation.XmlRegistry + * + * 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 XmlRegistryAnnotation + extends Annotation +{ + String ANNOTATION_NAME = JAXB.XML_REGISTRY; + +} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/JaxbJavaResourceModelTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/JaxbJavaResourceModelTests.java index 6dd0aed85c..6efa59a9fd 100644 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/JaxbJavaResourceModelTests.java +++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/JaxbJavaResourceModelTests.java @@ -21,6 +21,7 @@ public class JaxbJavaResourceModelTests { suite.addTestSuite(XmlEnumAnnotationTests.class); suite.addTestSuite(XmlInlineBinaryDataAnnotationTests.class); suite.addTestSuite(XmlJavaTypeAdapterAnnotationTests.class); + suite.addTestSuite(XmlRegistryAnnotationTests.class); suite.addTestSuite(XmlRootElementAnnotationTests.class); suite.addTestSuite(XmlSeeAlsoAnnotationTests.class); suite.addTestSuite(XmlTransientAnnotationTests.class); diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlRegistryAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlRegistryAnnotationTests.java new file mode 100644 index 0000000000..c11f4ef9ce --- /dev/null +++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlRegistryAnnotationTests.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * 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.resource.java; + +import java.util.Iterator; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; +import org.eclipse.jpt.jaxb.core.resource.java.JAXB; +import org.eclipse.jpt.jaxb.core.resource.java.XmlRegistryAnnotation; +import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; + +@SuppressWarnings("nls") +public class XmlRegistryAnnotationTests extends JaxbJavaResourceModelTestCase { + + public XmlRegistryAnnotationTests(String name) { + super(name); + } + + private ICompilationUnit createTestXmlRegistry() throws Exception { + return this.createTestType(new DefaultAnnotationWriter() { + @Override + public Iterator<String> imports() { + return new ArrayIterator<String>(JAXB.XML_REGISTRY); + } + @Override + public void appendTypeAnnotationTo(StringBuilder sb) { + sb.append("@XmlRegistry"); + } + }); + } + + public void testGetXmlRegistry() throws Exception { + ICompilationUnit cu = this.createTestXmlRegistry(); + JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); + + XmlRegistryAnnotation xmlRegistryAnnotation = (XmlRegistryAnnotation) typeResource.getAnnotation(JAXB.XML_REGISTRY); + assertTrue(xmlRegistryAnnotation != null); + + typeResource.removeAnnotation(JAXB.XML_REGISTRY); + assertSourceDoesNotContain("@XmlRegistry", cu); + } +} |