Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkmoore2010-12-15 13:33:38 -0500
committerkmoore2010-12-15 13:33:38 -0500
commit62e8d72310608aa8005178dc619ded65f811e6c2 (patch)
treea537cd75aaa6073d3928358c95256ea6b9c1fe73
parentdb9d06daf61484f9b5f06819b486a1aa7757ba83 (diff)
downloadwebtools.dali-62e8d72310608aa8005178dc619ded65f811e6c2.tar.gz
webtools.dali-62e8d72310608aa8005178dc619ded65f811e6c2.tar.xz
webtools.dali-62e8d72310608aa8005178dc619ded65f811e6c2.zip
added Xml registry and enum context model support
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/JaxbFactory.java20
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbFactory.java26
-rw-r--r--jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaRegistryTests.java209
-rw-r--r--jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/JaxbCoreJavaContextModelTests.java3
4 files changed, 253 insertions, 5 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 35ab8f4040..c602b3ca13 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
@@ -17,15 +17,22 @@ 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.JaxbContextRoot;
+import org.eclipse.jpt.jaxb.core.context.JaxbElementFactoryMethod;
+import org.eclipse.jpt.jaxb.core.context.JaxbEnumConstant;
import org.eclipse.jpt.jaxb.core.context.JaxbPackage;
import org.eclipse.jpt.jaxb.core.context.JaxbPackageInfo;
import org.eclipse.jpt.jaxb.core.context.JaxbPersistentClass;
+import org.eclipse.jpt.jaxb.core.context.JaxbPersistentEnum;
+import org.eclipse.jpt.jaxb.core.context.JaxbPersistentType;
import org.eclipse.jpt.jaxb.core.context.JaxbRegistry;
import org.eclipse.jpt.jaxb.core.context.XmlJavaTypeAdapter;
import org.eclipse.jpt.jaxb.core.context.XmlNs;
import org.eclipse.jpt.jaxb.core.context.XmlRootElement;
import org.eclipse.jpt.jaxb.core.context.XmlSchema;
import org.eclipse.jpt.jaxb.core.context.XmlSchemaType;
+import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceEnum;
+import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceEnumConstant;
+import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceMethod;
import org.eclipse.jpt.jaxb.core.resource.java.JavaResourcePackage;
import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType;
import org.eclipse.jpt.jaxb.core.resource.java.XmlJavaTypeAdapterAnnotation;
@@ -100,8 +107,10 @@ public interface JaxbFactory {
JaxbRegistry buildRegistry(JaxbContextRoot parent, JavaResourceType resourceType);
- JaxbPersistentClass buildPersistentClass(JaxbContextRoot parent, JavaResourceType resourceType);
-
+ JaxbPersistentClass buildJavaPersistentClass(JaxbContextRoot parent, JavaResourceType resourceType);
+
+ JaxbPersistentEnum buildJavaPersistentEnum(JaxbContextRoot parent, JavaResourceEnum resourceEnum);
+
XmlSchema buildJavaXmlSchema(JaxbPackageInfo parent);
XmlSchemaType buildJavaXmlSchemaType(JaxbContextNode parent, XmlSchemaTypeAnnotation xmlSchemaTypeAnnotation);
@@ -110,5 +119,10 @@ public interface JaxbFactory {
XmlNs buildJavaXmlNs(XmlSchema parent, XmlNsAnnotation xmlNsAnnotation);
- XmlRootElement buildJavaXmlRootElement(JaxbPersistentClass parent, XmlRootElementAnnotation xmlRootElementAnnotation);
+ XmlRootElement buildJavaXmlRootElement(JaxbPersistentType parent, XmlRootElementAnnotation xmlRootElementAnnotation);
+
+ JaxbEnumConstant buildJavaEnumConstant(JaxbPersistentEnum parent, JavaResourceEnumConstant resourceEnumConstant);
+
+ JaxbElementFactoryMethod buildJavaElementFactoryMethod(JaxbRegistry parent, JavaResourceMethod resourceMethod);
+
}
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 a8751b49c1..467bd95c69 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
@@ -18,9 +18,13 @@ 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.JaxbContextRoot;
+import org.eclipse.jpt.jaxb.core.context.JaxbElementFactoryMethod;
+import org.eclipse.jpt.jaxb.core.context.JaxbEnumConstant;
import org.eclipse.jpt.jaxb.core.context.JaxbPackage;
import org.eclipse.jpt.jaxb.core.context.JaxbPackageInfo;
import org.eclipse.jpt.jaxb.core.context.JaxbPersistentClass;
+import org.eclipse.jpt.jaxb.core.context.JaxbPersistentEnum;
+import org.eclipse.jpt.jaxb.core.context.JaxbPersistentType;
import org.eclipse.jpt.jaxb.core.context.JaxbRegistry;
import org.eclipse.jpt.jaxb.core.context.XmlJavaTypeAdapter;
import org.eclipse.jpt.jaxb.core.context.XmlNs;
@@ -29,14 +33,20 @@ import org.eclipse.jpt.jaxb.core.context.XmlSchema;
import org.eclipse.jpt.jaxb.core.context.XmlSchemaType;
import org.eclipse.jpt.jaxb.core.internal.context.GenericContextRoot;
import org.eclipse.jpt.jaxb.core.internal.context.GenericPackage;
+import org.eclipse.jpt.jaxb.core.internal.context.java.GenericJavaElementFactoryMethod;
+import org.eclipse.jpt.jaxb.core.internal.context.java.GenericJavaEnumConstant;
import org.eclipse.jpt.jaxb.core.internal.context.java.GenericJavaPackageInfo;
import org.eclipse.jpt.jaxb.core.internal.context.java.GenericJavaPersistentClass;
+import org.eclipse.jpt.jaxb.core.internal.context.java.GenericJavaPersistentEnum;
import org.eclipse.jpt.jaxb.core.internal.context.java.GenericJavaRegistry;
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.GenericJavaXmlRootElement;
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.JavaResourceEnum;
+import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceEnumConstant;
+import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceMethod;
import org.eclipse.jpt.jaxb.core.resource.java.JavaResourcePackage;
import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType;
import org.eclipse.jpt.jaxb.core.resource.java.XmlJavaTypeAdapterAnnotation;
@@ -88,10 +98,14 @@ public abstract class AbstractJaxbFactory
return new GenericJavaRegistry(parent, resourceType);
}
- public JaxbPersistentClass buildPersistentClass(JaxbContextRoot parent, JavaResourceType resourceType) {
+ public JaxbPersistentClass buildJavaPersistentClass(JaxbContextRoot parent, JavaResourceType resourceType) {
return new GenericJavaPersistentClass(parent, resourceType);
}
+ public JaxbPersistentEnum buildJavaPersistentEnum(JaxbContextRoot parent, JavaResourceEnum resourceEnum) {
+ return new GenericJavaPersistentEnum(parent, resourceEnum);
+ }
+
public XmlSchema buildJavaXmlSchema(JaxbPackageInfo parent) {
return new GenericJavaXmlSchema(parent);
}
@@ -104,11 +118,19 @@ public abstract class AbstractJaxbFactory
return new GenericJavaXmlJavaTypeAdapter(parent, resourceXmlJavaTypeAdapter);
}
+ public JaxbEnumConstant buildJavaEnumConstant(JaxbPersistentEnum parent, JavaResourceEnumConstant resourceEnumConstant) {
+ return new GenericJavaEnumConstant(parent, resourceEnumConstant);
+ }
+
public XmlNs buildJavaXmlNs(XmlSchema parent, XmlNsAnnotation xmlNsAnnotation) {
return new GenericJavaXmlNs(parent, xmlNsAnnotation);
}
- public XmlRootElement buildJavaXmlRootElement(JaxbPersistentClass parent, XmlRootElementAnnotation xmlRootElementAnnotation) {
+ public XmlRootElement buildJavaXmlRootElement(JaxbPersistentType parent, XmlRootElementAnnotation xmlRootElementAnnotation) {
return new GenericJavaXmlRootElement(parent, xmlRootElementAnnotation);
}
+
+ public JaxbElementFactoryMethod buildJavaElementFactoryMethod(JaxbRegistry parent, JavaResourceMethod resourceMethod) {
+ return new GenericJavaElementFactoryMethod(parent, resourceMethod);
+ }
}
diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaRegistryTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaRegistryTests.java
new file mode 100644
index 0000000000..6caf780cee
--- /dev/null
+++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaRegistryTests.java
@@ -0,0 +1,209 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jaxb.core.tests.internal.context.java;
+
+import java.util.Iterator;
+import java.util.List;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.Block;
+import org.eclipse.jdt.core.dom.BodyDeclaration;
+import org.eclipse.jdt.core.dom.IExtendedModifier;
+import org.eclipse.jdt.core.dom.MethodDeclaration;
+import org.eclipse.jdt.core.dom.NormalAnnotation;
+import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
+import org.eclipse.jdt.core.dom.TypeDeclaration;
+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.JaxbElementFactoryMethod;
+import org.eclipse.jpt.jaxb.core.context.JaxbRegistry;
+import org.eclipse.jpt.jaxb.core.resource.java.JAXB;
+import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType;
+import org.eclipse.jpt.jaxb.core.tests.internal.context.JaxbContextModelTestCase;
+import org.eclipse.jpt.utility.internal.CollectionTools;
+import org.eclipse.jpt.utility.internal.iterators.ArrayIterator;
+
+
+@SuppressWarnings("nls")
+public class GenericJavaRegistryTests extends JaxbContextModelTestCase
+{
+
+ public GenericJavaRegistryTests(String name) {
+ super(name);
+ }
+
+ private ICompilationUnit createTypeWithXmlRegistry() throws Exception {
+ return this.createTestType(PACKAGE_NAME, "ObjectFactory.java", "ObjectFactory", new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JAXB.XML_REGISTRY, JAXB.XML_ELEMENT_DECL, "javax.xml.bind.JAXBElement");
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@XmlRegistry");
+ }
+
+ @Override
+ public void appendGetNameMethodAnnotationTo(StringBuilder sb) {
+ sb.append("@XmlElementDecl(name=\"foo\"").append(CR);
+ sb.append(" JAXBElement<AnnotationTestType> createFoo(AnnotationTestType value) {return null}").append(CR);
+ sb.append(CR);
+ sb.append(" @XmlElementDecl(name=\"bar\"").append(CR);
+ sb.append(" JAXBElement createBar(Object value) {return null}").append(CR);
+ sb.append(CR);
+ }
+ });
+ }
+
+ private ICompilationUnit createTypeWithXmlType() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JAXB.XML_TYPE);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@XmlType").append(CR);
+ }
+ });
+ }
+
+
+ protected void addElementFactoryMethod(TypeDeclaration typeDeclaration, String methodName) {
+ AST ast = typeDeclaration.getAST();
+ MethodDeclaration methodDeclaration = this.newMethodDeclaration(ast, methodName);
+ Block body = ast.newBlock();
+ methodDeclaration.setBody(body);
+ methodDeclaration.setReturnType2(ast.newSimpleType(ast.newName("JAXBElement")));
+ SingleVariableDeclaration parameter = ast.newSingleVariableDeclaration();
+ parameter.setName(ast.newSimpleName("value"));
+ parameter.setType(ast.newSimpleType(ast.newName("Object")));
+ parameters(methodDeclaration).add(parameter);
+ NormalAnnotation elementDeclAnnotation = this.newNormalAnnotation(ast, "XmlElementDecl");
+ modifiers(methodDeclaration).add(elementDeclAnnotation);
+ this.bodyDeclarations(typeDeclaration).add(methodDeclaration);
+ }
+
+ protected MethodDeclaration newMethodDeclaration(AST ast, String methodName) {
+ MethodDeclaration methodDeclaration = ast.newMethodDeclaration();
+ methodDeclaration.setName(ast.newSimpleName(methodName));
+ return methodDeclaration;
+ }
+
+ /**
+ * minimize the scope of the suppressed warnings
+ */
+ @SuppressWarnings("unchecked")
+ protected List<BodyDeclaration> bodyDeclarations(TypeDeclaration td) {
+ return td.bodyDeclarations();
+ }
+
+ @SuppressWarnings("unchecked")
+ protected List<SingleVariableDeclaration> parameters(MethodDeclaration md) {
+ return md.parameters();
+ }
+
+ @SuppressWarnings("unchecked")
+ protected List<IExtendedModifier> modifiers(MethodDeclaration md) {
+ return md.modifiers();
+ }
+
+ protected void removeMethodDeclaration(TypeDeclaration typeDeclaration, String methodName) {
+ for (MethodDeclaration md : typeDeclaration.getMethods()) {
+ if (md.getName().getFullyQualifiedName().equals(methodName)) {
+ this.bodyDeclarations(typeDeclaration).remove(md);
+ break;
+ }
+ }
+ }
+
+ public void testUpdateElementFactoryMethods() throws Exception {
+ createTypeWithXmlType();
+ createTypeWithXmlRegistry();
+
+ JaxbRegistry contextRegistry = CollectionTools.get(getContextRoot().getRegistries(), 0);
+ JavaResourceType resourceType = contextRegistry.getJavaResourceType();
+
+ assertEquals(2, contextRegistry.getElementFactoryMethodsSize());
+ Iterator<JaxbElementFactoryMethod> elementFactoryMethods = contextRegistry.getElementFactoryMethods().iterator();
+ JaxbElementFactoryMethod elementFactoryMethod = elementFactoryMethods.next();
+ assertEquals("createFoo", elementFactoryMethod.getName());
+ assertEquals("foo", elementFactoryMethod.getElementName());
+ elementFactoryMethod = elementFactoryMethods.next();
+ assertEquals("createBar", elementFactoryMethod.getName());
+ assertEquals("bar", elementFactoryMethod.getElementName());
+ assertFalse(elementFactoryMethods.hasNext());
+
+
+ AnnotatedElement annotatedElement = this.annotatedElement(resourceType);
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaRegistryTests.this.addElementFactoryMethod((TypeDeclaration) declaration.getDeclaration(), "createFoo2");
+ GenericJavaRegistryTests.this.addElementFactoryMethod((TypeDeclaration) declaration.getDeclaration(), "createBar2");
+ }
+ });
+ assertEquals(4, contextRegistry.getElementFactoryMethodsSize());
+ elementFactoryMethods = contextRegistry.getElementFactoryMethods().iterator();
+ elementFactoryMethod = elementFactoryMethods.next();
+ assertEquals("createFoo", elementFactoryMethod.getName());
+ assertEquals("foo", elementFactoryMethod.getElementName());
+ elementFactoryMethod = elementFactoryMethods.next();
+ assertEquals("createBar", elementFactoryMethod.getName());
+ assertEquals("bar", elementFactoryMethod.getElementName());
+ elementFactoryMethod = elementFactoryMethods.next();
+ assertEquals("createFoo2", elementFactoryMethod.getName());
+ assertEquals(null, elementFactoryMethod.getElementName());
+ elementFactoryMethod = elementFactoryMethods.next();
+ assertEquals("createBar2", elementFactoryMethod.getName());
+ assertEquals(null, elementFactoryMethod.getElementName());
+ assertFalse(elementFactoryMethods.hasNext());
+
+
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaRegistryTests.this.removeMethodDeclaration((TypeDeclaration) declaration.getDeclaration(), "createFoo");
+ }
+ });
+ assertEquals(3, contextRegistry.getElementFactoryMethodsSize());
+ elementFactoryMethods = contextRegistry.getElementFactoryMethods().iterator();
+ elementFactoryMethod = elementFactoryMethods.next();
+ assertEquals("createBar", elementFactoryMethod.getName());
+ assertEquals("bar", elementFactoryMethod.getElementName());
+ elementFactoryMethod = elementFactoryMethods.next();
+ assertEquals("createFoo2", elementFactoryMethod.getName());
+ assertEquals(null, elementFactoryMethod.getElementName());
+ elementFactoryMethod = elementFactoryMethods.next();
+ assertEquals("createBar2", elementFactoryMethod.getName());
+ assertEquals(null, elementFactoryMethod.getElementName());
+ assertFalse(elementFactoryMethods.hasNext());
+
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaRegistryTests.this.removeMethodDeclaration((TypeDeclaration) declaration.getDeclaration(), "createFoo2");
+ GenericJavaRegistryTests.this.removeMethodDeclaration((TypeDeclaration) declaration.getDeclaration(), "createBar2");
+ }
+ });
+ assertEquals(1, contextRegistry.getElementFactoryMethodsSize());
+ elementFactoryMethods = contextRegistry.getElementFactoryMethods().iterator();
+ elementFactoryMethod = elementFactoryMethods.next();
+ assertEquals("createBar", elementFactoryMethod.getName());
+ assertEquals("bar", elementFactoryMethod.getElementName());
+ assertFalse(elementFactoryMethods.hasNext());
+
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaRegistryTests.this.removeMethodDeclaration((TypeDeclaration) declaration.getDeclaration(), "createBar");
+ }
+ });
+ assertEquals(0, contextRegistry.getElementFactoryMethodsSize());
+ assertFalse(contextRegistry.getElementFactoryMethods().iterator().hasNext());
+ }
+} \ No newline at end of file
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 d5c07f4aaf..eb74a4705d 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
@@ -17,8 +17,11 @@ public class JaxbCoreJavaContextModelTests extends TestCase
{
public static Test suite() {
TestSuite suite = new TestSuite(JaxbCoreJavaContextModelTests.class.getName());
+ suite.addTestSuite(GenericJavaEnumConstantTests.class);
suite.addTestSuite(GenericJavaPackageInfoTests.class);
suite.addTestSuite(GenericJavaPersistentClassTests.class);
+ suite.addTestSuite(GenericJavaPersistentEnumTests.class);
+ suite.addTestSuite(GenericJavaRegistryTests.class);
suite.addTestSuite(GenericJavaXmlJavaTypeAdapterTests.class);
suite.addTestSuite(GenericJavaXmlRootElementTests.class);
suite.addTestSuite(GenericJavaXmlSchemaTests.class);

Back to the top