diff options
author | kmoore | 2010-12-15 18:34:11 +0000 |
---|---|---|
committer | kmoore | 2010-12-15 18:34:11 +0000 |
commit | 728c7be6b20ffc787f96c2c98f8170e16586b4f4 (patch) | |
tree | bdd8674700011a1e7b1a7c1f5af763193e475865 | |
parent | 8c7f16015d32d607ddbaf310a32ec1954a618ff3 (diff) | |
download | webtools.dali-728c7be6b20ffc787f96c2c98f8170e16586b4f4.tar.gz webtools.dali-728c7be6b20ffc787f96c2c98f8170e16586b4f4.tar.xz webtools.dali-728c7be6b20ffc787f96c2c98f8170e16586b4f4.zip |
added support for registries and element factory methods in the context model
5 files changed, 368 insertions, 6 deletions
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbElementFactoryMethod.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbElementFactoryMethod.java new file mode 100644 index 0000000000..22c51e914a --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbElementFactoryMethod.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * 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.JavaResourceMethod; + +/** + * Represents a JAXB element factory method + * (A method inside an object factory (@XmlRegistry) with an explicit @XmlElementDecl annotation) + * <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 JaxbElementFactoryMethod + extends JaxbContextNode { + + JavaResourceMethod getResourceMethod(); + + String getName(); + + /** + * Corresponds to the XmlElementDecl annotation 'name' element + */ + String getElementName(); + void setElementName(String elementName); + String ELEMENT_NAME_PROPERTY = "elementName"; //$NON-NLS-1$ + + + //String defaultValue + //String namespace + //Class scope + //String substitutionHeadName + //String substitutionHeadNamespace + +// String getValue(); +// String getDefaultValue(); +// String getSpecifiedValue(); +// void setSpecifiedValue(String value); +// String SPECIFIED_VALUE_PROPERTY = "specifiedValue"; //$NON-NLS-1$ + +} diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbRegistry.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbRegistry.java index b6cb7aa82e..2e187c89ff 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbRegistry.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbRegistry.java @@ -9,6 +9,8 @@ *******************************************************************************/ package org.eclipse.jpt.jaxb.core.context; +import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType; + /** * Represents a JAXB registry * (A class with an explicit @XmlRegistry annotation) @@ -24,4 +26,16 @@ package org.eclipse.jpt.jaxb.core.context; */ public interface JaxbRegistry extends JaxbType { + /** + * covariant override + */ + JavaResourceType getJavaResourceType(); + + + /********** element factory methods **********/ + + Iterable<JaxbElementFactoryMethod> getElementFactoryMethods(); + int getElementFactoryMethodsSize(); + String ELEMENT_FACTORY_METHODS_COLLECTION = "elementFactoryMethods"; //$NON-NLS-1$ + } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaElementFactoryMethod.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaElementFactoryMethod.java new file mode 100644 index 0000000000..0e2839eecb --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaElementFactoryMethod.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * 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.JaxbElementFactoryMethod; +import org.eclipse.jpt.jaxb.core.context.JaxbRegistry; +import org.eclipse.jpt.jaxb.core.internal.context.AbstractJaxbContextNode; +import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceMethod; +import org.eclipse.jpt.jaxb.core.resource.java.XmlElementDeclAnnotation; + +public class GenericJavaElementFactoryMethod + extends AbstractJaxbContextNode + implements JaxbElementFactoryMethod { + + protected final JavaResourceMethod resourceMethod; + + protected String elementName; + + public GenericJavaElementFactoryMethod(JaxbRegistry parent, JavaResourceMethod resourceMethod) { + super(parent); + this.resourceMethod = resourceMethod; + this.elementName = this.getResourceElementName(); + } + + public JavaResourceMethod getResourceMethod() { + return this.resourceMethod; + } + + // ********** synchronize/update ********** + + public void synchronizeWithResourceModel() { + this.setElementName_(this.getResourceElementName()); + } + + public void update() { + // nothing yet + } + + // ********** xml enum value annotation ********** + + protected XmlElementDeclAnnotation getXmlElementDeclAnnotation() { + return (XmlElementDeclAnnotation) this.getResourceMethod().getNonNullAnnotation(XmlElementDeclAnnotation.ANNOTATION_NAME); + } + + + // ************** JaxbElementFactoryMethod impl *********** + + public String getName() { + return this.resourceMethod.getName(); + } + + // ********** element name ********** + + public String getElementName() { + return this.elementName; + } + + + public void setElementName(String elementName) { + this.getXmlElementDeclAnnotation().setName(elementName); + this.setElementName_(elementName); + } + + protected void setElementName_(String elementName) { + String old = this.elementName; + this.elementName = elementName; + this.firePropertyChanged(ELEMENT_NAME_PROPERTY, old, elementName); + } + + protected String getResourceElementName() { + return this.getXmlElementDeclAnnotation().getName(); + } +} diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaRegistry.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaRegistry.java index be34c56ad3..fe87a0c494 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaRegistry.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaRegistry.java @@ -10,18 +10,31 @@ package org.eclipse.jpt.jaxb.core.internal.context.java; import org.eclipse.jpt.jaxb.core.context.JaxbContextRoot; +import org.eclipse.jpt.jaxb.core.context.JaxbElementFactoryMethod; import org.eclipse.jpt.jaxb.core.context.JaxbRegistry; +import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceMethod; import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType; +import org.eclipse.jpt.jaxb.core.resource.java.XmlElementDeclAnnotation; +import org.eclipse.jpt.utility.internal.iterables.FilteringIterable; public class GenericJavaRegistry extends AbstractJavaType implements JaxbRegistry { - + + protected final ElementFactoryMethodContainer elementFactoryMethodContainer; + + private static final String ELEMENT_FACTORY_METHOD_CREATE_PREFIX = "create"; //$NON-NLS-1$ + public GenericJavaRegistry(JaxbContextRoot parent, JavaResourceType resourceType) { super(parent, resourceType); + this.elementFactoryMethodContainer = new ElementFactoryMethodContainer(); + } + + @Override + public JavaResourceType getJavaResourceType() { + return (JavaResourceType) super.getJavaResourceType(); } - // ********** JaxbType impl ********** @@ -29,14 +42,81 @@ public class GenericJavaRegistry return Kind.REGISTRY; } + // ********** synchronize/update ********** public void synchronizeWithResourceModel() { - // TODO Auto-generated method stub - + this.elementFactoryMethodContainer.synchronizeWithResourceModel(); } public void update() { - // TODO Auto-generated method stub - + this.elementFactoryMethodContainer.update(); } + + public Iterable<JaxbElementFactoryMethod> getElementFactoryMethods() { + return this.elementFactoryMethodContainer.getContextElements(); + } + + public int getElementFactoryMethodsSize() { + return this.elementFactoryMethodContainer.getContextElementsSize(); + } + + private JaxbElementFactoryMethod buildElementFactoryMethod(JavaResourceMethod resourceMethod) { + return getFactory().buildJavaElementFactoryMethod(this, resourceMethod); + } + + private Iterable<JavaResourceMethod> getResourceElementFactoryMethods() { + return new FilteringIterable<JavaResourceMethod>(getJavaResourceType().getMethods()) { + @Override + protected boolean accept(JavaResourceMethod method) { + return methodIsElementFactoryMethod(method); + } + }; + } + + //For now we will just check that the method has an @XmlElementDecl annotation. + //In the future we could look for methods that are unannotated, but appear + //to be element factory methods : begin with create, return type is JAXB element, + //1 parameter, etc. + protected static boolean methodIsElementFactoryMethod(JavaResourceMethod method) { + return methodHasXmlElementDeclAnnotation(method); + } + + protected static boolean methodHasXmlElementDeclAnnotation(JavaResourceMethod method) { + return method.getAnnotation(XmlElementDeclAnnotation.ANNOTATION_NAME) != null; + } + + protected static boolean methodStartsWithCreate(JavaResourceMethod method) { + return method.getName().startsWith(ELEMENT_FACTORY_METHOD_CREATE_PREFIX); + } + + protected static boolean methodReturnTypeIsJAXBElement(JavaResourceMethod method) { + return method.returnTypeIsSubTypeOf(JAXB_ELEMENT_TYPE_NAME); + } + + protected static final String JAXB_ELEMENT_TYPE_NAME = "javax.xml.bind.JAXBElement"; //$NON-NLS-1$ + + /** + * element factory method container adapter + */ + protected class ElementFactoryMethodContainer + extends ContextCollectionContainer<JaxbElementFactoryMethod, JavaResourceMethod> + { + @Override + protected String getContextElementsPropertyName() { + return ELEMENT_FACTORY_METHODS_COLLECTION; + } + @Override + protected JaxbElementFactoryMethod buildContextElement(JavaResourceMethod resourceElement) { + return GenericJavaRegistry.this.buildElementFactoryMethod(resourceElement); + } + @Override + protected Iterable<JavaResourceMethod> getResourceElements() { + return GenericJavaRegistry.this.getResourceElementFactoryMethods(); + } + @Override + protected JavaResourceMethod getResourceElement(JaxbElementFactoryMethod contextElement) { + return contextElement.getResourceMethod(); + } + } + } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/NullXmlElementDeclAnnotation.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/NullXmlElementDeclAnnotation.java new file mode 100644 index 0000000000..7c6d6b144f --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/NullXmlElementDeclAnnotation.java @@ -0,0 +1,134 @@ +/******************************************************************************* + * 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.dom.CompilationUnit; +import org.eclipse.jpt.core.utility.TextRange; +import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceMethod; +import org.eclipse.jpt.jaxb.core.resource.java.XmlElementDeclAnnotation; + +/** + * javax.xml.bind.annotation.XmlElementDecl + */ +public final class NullXmlElementDeclAnnotation + extends NullAnnotation + implements XmlElementDeclAnnotation +{ + protected NullXmlElementDeclAnnotation(JavaResourceMethod parent) { + super(parent); + } + + public String getAnnotationName() { + return ANNOTATION_NAME; + } + + @Override + protected XmlElementDeclAnnotation addAnnotation() { + return (XmlElementDeclAnnotation) super.addAnnotation(); + } + + + // ********** XmlEnumAnnotation implementation ********** + + // ***** name + public String getName() { + return null; + } + + public void setName(String name) { + if (name != null) { + this.addAnnotation().setName(name); + } + } + + public TextRange getNameTextRange(CompilationUnit astRoot) { + return null; + } + + // ***** namespace + public String getNamespace() { + return null; + } + + public void setNamespace(String namespace) { + if (namespace != null) { + this.addAnnotation().setNamespace(namespace); + } + } + + public TextRange getNamespaceTextRange(CompilationUnit astRoot) { + return null; + } + + // ***** defaultValue + public String getDefaultValue() { + return null; + } + + public void setDefaultValue(String defaultValue) { + if (defaultValue != null) { + this.addAnnotation().setDefaultValue(defaultValue); + } + } + + public TextRange getDefaultValueTextRange(CompilationUnit astRoot) { + return null; + } + + // ***** scope + public String getScope() { + return null; + } + + public String getFullyQualifiedScopeClassName() { + return null; + } + + public void setScope(String scope) { + if (scope != null) { + this.addAnnotation().setScope(scope); + } + } + + public TextRange getScopeTextRange(CompilationUnit astRoot) { + return null; + } + + // ***** substitutionHeadName + public String getSubstitutionHeadName() { + return null; + } + + public void setSubstitutionHeadName(String substitutionHeadName) { + if (substitutionHeadName != null) { + this.addAnnotation().setSubstitutionHeadName(substitutionHeadName); + } + } + + public TextRange getSubstitutionHeadNameTextRange(CompilationUnit astRoot) { + return null; + } + + // ***** substitutionHeadNamespace + public String getSubstitutionHeadNamespace() { + return null; + } + + public void setSubstitutionHeadNamespace(String substitutionHeadNamespace) { + if (substitutionHeadNamespace != null) { + this.addAnnotation().setSubstitutionHeadNamespace(substitutionHeadNamespace); + } + } + + public TextRange getSubstitutionHeadNamespaceTextRange(CompilationUnit astRoot) { + return null; + } + +} |