From e82439c36427b234ed6b0bc86a4751531c910c7c Mon Sep 17 00:00:00 2001 From: Dmitry Katsubo Date: Wed, 6 Jun 2018 10:53:44 +0200 Subject: [PATCH] Fixed JavaDocs so that they are compatible with Java8. Added samples for JAXB issues. Minor improvements. --- README.md | 16 +++--- playground/JAXB-1108/pom.xml | 34 ++++++++++++ playground/JAXB-1108/runme.bat | 2 + playground/JAXB-1108/xsd/test.xsd | 32 ++++++++++++ playground/JAXB-element/pom.xml | 34 ++++++++++++ playground/JAXB-element/xsd/test.xsd | 29 +++++++++++ pom.xml | 2 +- samples/jaxb2-maven-plugin/pom.xml | 15 +++--- .../episode_default.xjb} | 6 +-- .../budgetary/commitment/ObjectFactory.java | 6 ++- samples/maven-jaxb2-plugin-basics/pom.xml | 5 +- samples/maven-jaxb2-plugin/pom.xml | 3 +- .../src/main/java/generated/Order.java | 24 ++++----- samples/pom.xml | 8 +-- .../sun/tools/xjc/addon/xew/Candidate.java | 5 +- .../sun/tools/xjc/addon/xew/CommonUtils.java | 11 ++-- .../xjc/addon/xew/ScopedElementInfo.java | 14 ++--- .../addon/xew/XmlElementWrapperPlugin.java | 52 +++++++++++-------- .../addon/xew/config/GlobalConfiguration.java | 4 +- 19 files changed, 219 insertions(+), 83 deletions(-) create mode 100644 playground/JAXB-1108/pom.xml create mode 100644 playground/JAXB-1108/runme.bat create mode 100644 playground/JAXB-1108/xsd/test.xsd create mode 100644 playground/JAXB-element/pom.xml create mode 100644 playground/JAXB-element/xsd/test.xsd rename samples/jaxb2-maven-plugin/src/test/java/META-INF/{sun-jaxb.episode => JAXB/episode_default.xjb} (92%) diff --git a/README.md b/README.md index f1430c8..b6f4659 100644 --- a/README.md +++ b/README.md @@ -547,7 +547,9 @@ If you provide the code in any way (patch, pull request, post, comment, …) you ### Bug reports -This very open source project is maintained and improved during my free time. That is why I have no ability to test the functionality will all different combinations of Java, JAXB, JAXB plugins and Maven plugins. I leave this to community. Also newly created bug report should mention Java version and have a simple project attached (or one can clone the repository and alter one of the [`samples`](samples/)) that demonstrates the problem. +This very open source project is maintained and improved during my free time. That is why I have no ability to test the functionality will all different combinations of Java, JAXB, JAXB plugins and Maven plugins. I leave this to community. Hence please in newly created bug report: +- mention Java version +- attach a simple project (or one can clone the repository and alter one of the [`samples`](samples/)) that demonstrates the problem #### Code style @@ -642,12 +644,12 @@ The plugin flow consists of the following parts: There are many pitfalls in JAXB Code Model API which are forcing the developer to use dirty tricks (like accessing private fields) in order to implement the manipulation of code model. Among others: -* [JAXB-784](http://java.net/jira/browse/JAXB-784) is about NPE in `JAnnotationUse#getAnnotationMembers()` method. -* [JAXB-884](https://java.net/jira/browse/JAXB-884) is about ClassCastException in `JAnnotationArrayMember#annotations()` method. -* [JAXB-878](https://java.net/jira/browse/JAXB-878) and [JAXB-879](https://java.net/jira/browse/JAXB-879) describe the lack of public getters for class fields. -* [JAXB-957](https://java.net/jira/browse/JAXB-957) mentions what need to be added to make it possible for the inner class to be moved to another class or package. -* [JAXB-883](http://java.net/jira/browse/JAXB-883) does not allow to learn if "simpleMode" setting is enabled, which in its turn controls plural form for collection property names. There are however some more difficulties to overcome. -* [JAXB-1107](https://java.net/jira/browse/JAXB-1107) – marshalling of text nodes for mixed-mode contents +* [JAXB-784](https://github.com/javaee/jaxb-v2/issues/784) is about NPE in `JAnnotationUse#getAnnotationMembers()` method. +* [JAXB-884](https://github.com/javaee/jaxb-v2/issues/884) is about ClassCastException in `JAnnotationArrayMember#annotations()` method. +* [JAXB-878](https://github.com/javaee/jaxb-v2/issues/878) and [JAXB-879](https://github.com/javaee/jaxb-v2/issues/879) describe the lack of public getters for class fields. +* [JAXB-957](https://github.com/javaee/jaxb-v2/issues/957) mentions what need to be added to make it possible for the inner class to be moved to another class or package. +* [JAXB-883](https://github.com/javaee/jaxb-v2/issues/883) does not allow to learn if "simpleMode" setting is enabled, which in its turn controls plural form for collection property names. There are however some more difficulties to overcome. +* [JAXB-1107](https://github.com/javaee/jaxb-v2/issues/1107) – marshalling of text nodes for mixed-mode contents ## Authors diff --git a/playground/JAXB-1108/pom.xml b/playground/JAXB-1108/pom.xml new file mode 100644 index 0000000..a0fadeb --- /dev/null +++ b/playground/JAXB-1108/pom.xml @@ -0,0 +1,34 @@ + + + + 4.0.0 + + com.github.jaxb-xew-plugin.sample + jaxb-1108 + 1.0-SNAPSHOT + jar + + + + + org.jvnet.jaxb2.maven2 + maven-jaxb2-plugin + 0.13.1 + + + generate-sources + + generate + + + true + xsd + false + true + + + + + + + diff --git a/playground/JAXB-1108/runme.bat b/playground/JAXB-1108/runme.bat new file mode 100644 index 0000000..7c15c11 --- /dev/null +++ b/playground/JAXB-1108/runme.bat @@ -0,0 +1,2 @@ +mvn -X clean install +rem D:\jaxb-ri\bin\xjc.bat -extension xsd\test.xsd diff --git a/playground/JAXB-1108/xsd/test.xsd b/playground/JAXB-1108/xsd/test.xsd new file mode 100644 index 0000000..4c94031 --- /dev/null +++ b/playground/JAXB-1108/xsd/test.xsd @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/playground/JAXB-element/pom.xml b/playground/JAXB-element/pom.xml new file mode 100644 index 0000000..5b8f42f --- /dev/null +++ b/playground/JAXB-element/pom.xml @@ -0,0 +1,34 @@ + + + + 4.0.0 + + com.github.jaxb-xew-plugin.sample + jaxb-element + 1.0-SNAPSHOT + jar + + + + + org.jvnet.jaxb2.maven2 + maven-jaxb2-plugin + 0.13.1 + + + generate-sources + + generate + + + true + xsd + false + true + + + + + + + diff --git a/playground/JAXB-element/xsd/test.xsd b/playground/JAXB-element/xsd/test.xsd new file mode 100644 index 0000000..54ea0a3 --- /dev/null +++ b/playground/JAXB-element/xsd/test.xsd @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pom.xml b/pom.xml index 14aa77c..00afc5f 100644 --- a/pom.xml +++ b/pom.xml @@ -196,7 +196,7 @@ org.jvnet.jaxb2_commons jaxb2-basics-tools - 0.6.5 + 0.12.0 diff --git a/samples/jaxb2-maven-plugin/pom.xml b/samples/jaxb2-maven-plugin/pom.xml index 865f2f0..aac29c0 100644 --- a/samples/jaxb2-maven-plugin/pom.xml +++ b/samples/jaxb2-maven-plugin/pom.xml @@ -21,7 +21,7 @@ org.codehaus.mojo jaxb2-maven-plugin - 2.3 + 2.4 generate-sources @@ -31,20 +31,17 @@ ${project.build.testSourceDirectory} - xsd/BudgetaryCommitment.xsd - xsd/ContractorReference.xsd - xsd/different-namespaces.xsd - xsd/different-namespaces-entries.xsd + xsd - - + \.xml - - false + + true true true diff --git a/samples/jaxb2-maven-plugin/src/test/java/META-INF/sun-jaxb.episode b/samples/jaxb2-maven-plugin/src/test/java/META-INF/JAXB/episode_default.xjb similarity index 92% rename from samples/jaxb2-maven-plugin/src/test/java/META-INF/sun-jaxb.episode rename to samples/jaxb2-maven-plugin/src/test/java/META-INF/JAXB/episode_default.xjb index 202c14a..f388431 100644 --- a/samples/jaxb2-maven-plugin/src/test/java/META-INF/sun-jaxb.episode +++ b/samples/jaxb2-maven-plugin/src/test/java/META-INF/JAXB/episode_default.xjb @@ -2,10 +2,10 @@ diff --git a/samples/jaxb2-maven-plugin/src/test/java/budgetary/commitment/ObjectFactory.java b/samples/jaxb2-maven-plugin/src/test/java/budgetary/commitment/ObjectFactory.java index 3efe228..e3e3fa0 100644 --- a/samples/jaxb2-maven-plugin/src/test/java/budgetary/commitment/ObjectFactory.java +++ b/samples/jaxb2-maven-plugin/src/test/java/budgetary/commitment/ObjectFactory.java @@ -43,8 +43,12 @@ public BudgetaryCommitmentType createBudgetaryCommitmentType() { } /** - * Create an instance of {@link JAXBElement }{@code <}{@link BudgetaryCommitmentType }{@code >}} + * Create an instance of {@link JAXBElement }{@code <}{@link BudgetaryCommitmentType }{@code >} * + * @param value + * Java instance representing xml element's value. + * @return + * the new instance of {@link JAXBElement }{@code <}{@link BudgetaryCommitmentType }{@code >} */ @XmlElementDecl(namespace = "budgetary/commitment", name = "BudgetaryCommitment") public JAXBElement createBudgetaryCommitment(BudgetaryCommitmentType value) { diff --git a/samples/maven-jaxb2-plugin-basics/pom.xml b/samples/maven-jaxb2-plugin-basics/pom.xml index 80b958b..7606c29 100644 --- a/samples/maven-jaxb2-plugin-basics/pom.xml +++ b/samples/maven-jaxb2-plugin-basics/pom.xml @@ -19,8 +19,6 @@ xsd xsd - - 0.11.1 @@ -28,8 +26,7 @@ org.jvnet.jaxb2.maven2 maven-jaxb2-plugin - - 0.13.1 + ${maven-jaxb2-plugin.version} generate diff --git a/samples/maven-jaxb2-plugin/pom.xml b/samples/maven-jaxb2-plugin/pom.xml index de7cd61..9c449ba 100644 --- a/samples/maven-jaxb2-plugin/pom.xml +++ b/samples/maven-jaxb2-plugin/pom.xml @@ -21,8 +21,7 @@ org.jvnet.jaxb2.maven2 maven-jaxb2-plugin - - 0.13.1 + ${maven-jaxb2-plugin.version} generate-sources diff --git a/samples/maven-jaxb2-plugin/src/main/java/generated/Order.java b/samples/maven-jaxb2-plugin/src/main/java/generated/Order.java index ea79890..4eb4924 100644 --- a/samples/maven-jaxb2-plugin/src/main/java/generated/Order.java +++ b/samples/maven-jaxb2-plugin/src/main/java/generated/Order.java @@ -9,10 +9,10 @@ import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; -import org.jvnet.jaxb2_commons.lang.Equals; -import org.jvnet.jaxb2_commons.lang.EqualsStrategy; -import org.jvnet.jaxb2_commons.lang.HashCode; -import org.jvnet.jaxb2_commons.lang.HashCodeStrategy; +import org.jvnet.jaxb2_commons.lang.Equals2; +import org.jvnet.jaxb2_commons.lang.EqualsStrategy2; +import org.jvnet.jaxb2_commons.lang.HashCode2; +import org.jvnet.jaxb2_commons.lang.HashCodeStrategy2; import org.jvnet.jaxb2_commons.lang.JAXBEqualsStrategy; import org.jvnet.jaxb2_commons.lang.JAXBHashCodeStrategy; import org.jvnet.jaxb2_commons.locator.ObjectLocator; @@ -43,7 +43,7 @@ "items" }) @XmlRootElement(name = "order") -public class Order implements Equals, HashCode +public class Order implements Equals2, HashCode2 { @XmlElementWrapper(required = true) @@ -61,8 +61,8 @@ public void setItems(List items) { this.items = items; } - public boolean equals(ObjectLocator thisLocator, ObjectLocator thatLocator, Object object, EqualsStrategy strategy) { - if (!(object instanceof Order)) { + public boolean equals(ObjectLocator thisLocator, ObjectLocator thatLocator, Object object, EqualsStrategy2 strategy) { + if ((object == null)||(this.getClass()!= object.getClass())) { return false; } if (this == object) { @@ -74,7 +74,7 @@ public boolean equals(ObjectLocator thisLocator, ObjectLocator thatLocator, Obje lhsItems = ((this.items!= null)?this.getItems():null); List rhsItems; rhsItems = ((that.items!= null)?that.getItems():null); - if (!strategy.equals(LocatorUtils.property(thisLocator, "items", lhsItems), LocatorUtils.property(thatLocator, "items", rhsItems), lhsItems, rhsItems)) { + if (!strategy.equals(LocatorUtils.property(thisLocator, "items", lhsItems), LocatorUtils.property(thatLocator, "items", rhsItems), lhsItems, rhsItems, (this.items!= null), (that.items!= null))) { return false; } } @@ -82,22 +82,22 @@ public boolean equals(ObjectLocator thisLocator, ObjectLocator thatLocator, Obje } public boolean equals(Object object) { - final EqualsStrategy strategy = JAXBEqualsStrategy.INSTANCE; + final EqualsStrategy2 strategy = JAXBEqualsStrategy.INSTANCE2; return equals(null, null, object, strategy); } - public int hashCode(ObjectLocator locator, HashCodeStrategy strategy) { + public int hashCode(ObjectLocator locator, HashCodeStrategy2 strategy) { int currentHashCode = 1; { List theItems; theItems = ((this.items!= null)?this.getItems():null); - currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "items", theItems), currentHashCode, theItems); + currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "items", theItems), currentHashCode, theItems, (this.items!= null)); } return currentHashCode; } public int hashCode() { - final HashCodeStrategy strategy = JAXBHashCodeStrategy.INSTANCE; + final HashCodeStrategy2 strategy = JAXBHashCodeStrategy.INSTANCE2; return this.hashCode(null, strategy); } diff --git a/samples/pom.xml b/samples/pom.xml index 5adad93..7eed1f2 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -9,8 +9,8 @@ pom - 1.9 - - 0.9.1 + 0.12.0 + + 0.14.0 diff --git a/src/main/java/com/sun/tools/xjc/addon/xew/Candidate.java b/src/main/java/com/sun/tools/xjc/addon/xew/Candidate.java index 9fe5e2b..3ba8264 100644 --- a/src/main/java/com/sun/tools/xjc/addon/xew/Candidate.java +++ b/src/main/java/com/sun/tools/xjc/addon/xew/Candidate.java @@ -11,7 +11,6 @@ import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; -import java.util.List; import java.util.Map; import com.sun.codemodel.JAnnotationUse; @@ -162,8 +161,8 @@ public String getFieldTargetNamespace() { } /** - * The only parametrisation class of the field (collection type). In case of basic parametrisation like {@link List - * } this property is {@code null}. + * The only parametrisation class of the field (collection type). In case of basic parametrisation like + * {@code List} this property is {@code null}. */ public JDefinedClass getFieldParametrisationClass() { return fieldParametrisationClass; diff --git a/src/main/java/com/sun/tools/xjc/addon/xew/CommonUtils.java b/src/main/java/com/sun/tools/xjc/addon/xew/CommonUtils.java index a6a22ed..560a22c 100644 --- a/src/main/java/com/sun/tools/xjc/addon/xew/CommonUtils.java +++ b/src/main/java/com/sun/tools/xjc/addon/xew/CommonUtils.java @@ -11,7 +11,6 @@ import com.sun.codemodel.JAnnotationUse; import com.sun.codemodel.JAnnotationValue; import com.sun.codemodel.JClass; -import com.sun.codemodel.JCodeModel; import com.sun.codemodel.JDefinedClass; import com.sun.codemodel.JExpr; import com.sun.codemodel.JExpression; @@ -34,8 +33,8 @@ public final class CommonUtils { /** - * Returns {@code true} if given class is hidden, that is not generated & saved by XJC. These are for example - * instances of {@link JCodeModel.JReferencedClass} (JVM-wide classes) or instances of {@link JDefinedClass} with + * Returns {@code true} if given class is hidden, that is not generated and saved by XJC. These are for example + * instances of {@code JCodeModel.JReferencedClass} (JVM-wide classes) or instances of {@link JDefinedClass} with * hidden flag (customized super-class or super-interface). */ public static boolean isHiddenClass(JClass clazz) { @@ -130,7 +129,7 @@ public static void removeAnnotation(JVar field, JAnnotationUse annotation) { /** * Check that given field property has name customization ({@code }). * - * @see com.sun.xml.bind.api.impl.NameUtil + * @see com.sun.xml.bind.api.impl.NameUtil * @see com.sun.codemodel.JJavaName * @see com.sun.tools.xjc.reader.xmlschema.bindinfo.BIProperty#getCustomization(XSComponent) */ @@ -175,7 +174,7 @@ public static final String generableToString(JGenerable generable) { /** * Set the {@code newValue} to private field {@code fieldName} of given object {@code obj}. * - * @throws NoSuchFieldException + * @throws IllegalArgumentException * if given field was not found */ public static void setPrivateField(Object obj, String fieldName, Object newValue) { @@ -205,7 +204,7 @@ public static T getPrivateField(Object obj, String fieldName) { /** * Perform the copying of all fields from {@code src} to {@code dest}. The code was copied from - * {@link org.springframework.util.ReflectionUtils#shallowCopyFieldState(Object, Object)}. + * {@code org.springframework.util.ReflectionUtils#shallowCopyFieldState(Object, Object)}. */ public static void copyFields(final S src, D dest) throws IllegalArgumentException { Class targetClass = src.getClass(); diff --git a/src/main/java/com/sun/tools/xjc/addon/xew/ScopedElementInfo.java b/src/main/java/com/sun/tools/xjc/addon/xew/ScopedElementInfo.java index 70df870..ead0ce9 100644 --- a/src/main/java/com/sun/tools/xjc/addon/xew/ScopedElementInfo.java +++ b/src/main/java/com/sun/tools/xjc/addon/xew/ScopedElementInfo.java @@ -14,13 +14,13 @@ * *
  * @XmlElementDecl(namespace = "http://foo.bar/extra", name = "age")
- * public JAXBElement createAge(String value) {
- *     return new JAXBElement(new QName("http://foo.bar/extra", "age"), String.class, null, value);
+ * public JAXBElement<String> createAge(String value) {
+ *     return new JAXBElement<String>(new QName("http://foo.bar/extra", "age"), String.class, null, value);
  * }
  * 
  * @XmlElementDecl(namespace = "http://foo.bar/scope", name = "age", scope = Container.class)
- * public JAXBElement createReturnAge(String value) {
- *     return new JAXBElement(new QName("http://foo.bar/scope", "age"), String.class, Container.class, value);
+ * public JAXBElement<String> createReturnAge(String value) {
+ *     return new JAXBElement<String>(new QName("http://foo.bar/scope", "age"), String.class, Container.class, value);
  * }
  * 
*/ @@ -29,17 +29,17 @@ public final class ScopedElementInfo { /** * Element name ("post-office"). */ - public JExpression name; + public final JExpression name; /** * Element namespace ("http://foo.bar"). */ - public JExpression namespace; + public final JExpression namespace; /** * Element type ({@link String}). */ - public JType type; + public final JType type; public ScopedElementInfo(JExpression name, JExpression namespace, JType type) { this.name = name; diff --git a/src/main/java/com/sun/tools/xjc/addon/xew/XmlElementWrapperPlugin.java b/src/main/java/com/sun/tools/xjc/addon/xew/XmlElementWrapperPlugin.java index 0db127c..e7088a6 100644 --- a/src/main/java/com/sun/tools/xjc/addon/xew/XmlElementWrapperPlugin.java +++ b/src/main/java/com/sun/tools/xjc/addon/xew/XmlElementWrapperPlugin.java @@ -107,23 +107,23 @@ */ public class XmlElementWrapperPlugin extends AbstractConfigurablePlugin { - private JClass xmlElementDeclModelClass; - - static final String FACTORY_CLASS_NAME = "ObjectFactory"; + static final String FACTORY_CLASS_NAME = "ObjectFactory"; @Override protected void runInternal(Outline outline) throws ClassNotFoundException, IOException { - JCodeModel codeModel = outline.getCodeModel(); - JClass xmlElementWrapperModelClass = codeModel.ref(XmlElementWrapper.class); - JClass xmlElementModelClass = codeModel.ref(XmlElement.class); - JClass xmlAnyElementModelClass = codeModel.ref(XmlAnyElement.class); - JClass xmlMixedModelClass = codeModel.ref(XmlMixed.class); - JClass xmlElementRefModelClass = codeModel.ref(XmlElementRef.class); - JClass xmlElementRefsModelClass = codeModel.ref(XmlElementRefs.class); - JClass xmlElementsModelClass = codeModel.ref(XmlElements.class); - JClass xmlJavaTypeAdapterModelClass = codeModel.ref(XmlJavaTypeAdapter.class); - JClass xmlTypeModelClass = codeModel.ref(XmlType.class); - xmlElementDeclModelClass = codeModel.ref(XmlElementDecl.class); + final JCodeModel codeModel = outline.getCodeModel(); + final JClass xmlElementWrapperModelClass = codeModel.ref(XmlElementWrapper.class); + final JClass xmlElementModelClass = codeModel.ref(XmlElement.class); + final JClass xmlAnyElementModelClass = codeModel.ref(XmlAnyElement.class); + final JClass xmlMixedModelClass = codeModel.ref(XmlMixed.class); + final JClass xmlElementRefModelClass = codeModel.ref(XmlElementRef.class); + final JClass xmlElementRefsModelClass = codeModel.ref(XmlElementRefs.class); + final JClass xmlElementsModelClass = codeModel.ref(XmlElements.class); + final JClass xmlJavaTypeAdapterModelClass = codeModel.ref(XmlJavaTypeAdapter.class); + final JClass xmlTypeModelClass = codeModel.ref(XmlType.class); + final JClass xmlElementDeclModelClass = codeModel.ref(XmlElementDecl.class); + final JClass jaxbElementModelClass = codeModel.ref(JAXBElement.class); + final JClass qNameModelClass = codeModel.ref(QName.class); Ring.begin(); Ring.add(outline.getModel()); @@ -152,7 +152,8 @@ protected void runInternal(Outline outline) throws ClassNotFoundException, IOExc // Write information on candidate classes to summary file. writeSummary("Candidates:"); - for (Iterator iter = findCandidateClasses(outline).iterator(); iter.hasNext();) { + for (Iterator iter = findCandidateClasses(outline, xmlElementDeclModelClass).iterator(); iter + .hasNext();) { Candidate candidate = iter.next(); if (globalConfiguration.isClassIncluded(candidate.getClassName())) { @@ -504,7 +505,8 @@ else if (candidateFieldPropertyInfo instanceof CReferencePropertyInfo) { // Adapt factory class: for (JDefinedClass objectFactoryClass : candidate.getObjectFactoryClasses()) { modificationCount += createScopedFactoryMethods(codeModel, objectFactoryClass, - candidate.getScopedElementInfos().values(), targetClass); + candidate.getScopedElementInfos().values(), targetClass, xmlElementDeclModelClass, + jaxbElementModelClass, qNameModelClass); } candidate.addObjectFactoryForClass(targetClass); @@ -571,11 +573,16 @@ private boolean moveInnerClassToParent(Outline outline, Candidate candidate) { * * @param targetClass * the class that is applied the transformation of properties + * @param jaxbElementModelClass + * TODO + * @param qNameModelClass + * TODO * @return number of created methods * @see com.sun.tools.xjc.generator.bean.ObjectFactoryGenerator */ private int createScopedFactoryMethods(JCodeModel codeModel, JDefinedClass factoryClass, - Collection scopedElementInfos, JDefinedClass targetClass) { + Collection scopedElementInfos, JDefinedClass targetClass, + JClass xmlElementDeclModelClass, JClass jaxbElementModelClass, JClass qNameModelClass) { int createdMethods = 0; NEXT: for (ScopedElementInfo info : scopedElementInfos) { @@ -617,17 +624,16 @@ && generableToString(info.name).equals(generableToString(name))) { methodName.insert(0, "create").append(NameConverter.standard.toPropertyName(generableToString(info.name))); - JClass wrapperType = codeModel.ref(JAXBElement.class).narrow(info.type); + JClass jaxbElementType = jaxbElementModelClass.narrow(info.type); - JMethod method = factoryClass.method(JMod.PUBLIC, wrapperType, methodName.toString()); + JMethod method = factoryClass.method(JMod.PUBLIC, jaxbElementType, methodName.toString()); method.annotate(xmlElementDeclModelClass).param("namespace", info.namespace).param("name", info.name) .param("scope", targetClass); - // FIXME: Make a try to load constants and (a) rename it appropriately (b) use it? - JInvocation qname = JExpr._new(codeModel.ref(QName.class)).arg(info.namespace).arg(info.name); + JInvocation qname = JExpr._new(qNameModelClass).arg(info.namespace).arg(info.name); - method.body()._return(JExpr._new(wrapperType).arg(qname).arg(info.type.boxify().dotclass()) + method.body()._return(JExpr._new(jaxbElementType).arg(qname).arg(info.type.boxify().dotclass()) .arg(targetClass.dotclass()).arg(method.param(info.type, "value"))); createdMethods++; @@ -641,7 +647,7 @@ && generableToString(info.name).equals(generableToString(name))) { * * @return a map className -> Candidate */ - private Collection findCandidateClasses(Outline outline) { + private Collection findCandidateClasses(Outline outline, JClass xmlElementDeclModelClass) { Map interfaceImplementations = new HashMap(); // Visit all classes to create a map "interfaceName -> ClassOutline". diff --git a/src/main/java/com/sun/tools/xjc/addon/xew/config/GlobalConfiguration.java b/src/main/java/com/sun/tools/xjc/addon/xew/config/GlobalConfiguration.java index 81d7b52..b2c6b1c 100644 --- a/src/main/java/com/sun/tools/xjc/addon/xew/config/GlobalConfiguration.java +++ b/src/main/java/com/sun/tools/xjc/addon/xew/config/GlobalConfiguration.java @@ -22,9 +22,9 @@ public class GlobalConfiguration extends CommonConfiguration { private List controlList = new ArrayList(); private static class ControlEntry { - Pattern pattern; + final Pattern pattern; - ControlMode controlMode; + final ControlMode controlMode; ControlEntry(Pattern pattern, ControlMode controlMode) { this.pattern = pattern;