aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Vojtek2014-07-25 10:14:40 (EDT)
committerTomas Kraus2014-07-25 10:27:55 (EDT)
commit8608692e382430fbd152566cc03748aa6b23ae81 (patch)
treeea7d4c3a3e4bdd1edbd0abfc04b3afc389c0400f
parentcc1dc4a30a14639fa1956d7ca129e4a168fb4f69 (diff)
downloadeclipselink.runtime-8608692e382430fbd152566cc03748aa6b23ae81.zip
eclipselink.runtime-8608692e382430fbd152566cc03748aa6b23ae81.tar.gz
eclipselink.runtime-8608692e382430fbd152566cc03748aa6b23ae81.tar.bz2
Bug# 440360 - Fix for broken JPARS tests.
Commit a10e30f broke JPARS tests. The problem is related to finding a proper generic class for XmlAdapter. Introduced GenericsClassHelper which resolves correct bound type and value type of generic XmlAdapter class. Signed-off-by: Martin Vojtek <martin.vojtek@oracle.com>
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/xmladapter/XmlAdapterTestSuite.java36
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/xmladapter/enumeration/AdapterEnumMoreGenericTestCases.java49
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/xmladapter/enumeration/GenericSuitsAdapterWithT.java38
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/xmladapter/enumeration/MoreGenericCardSuit.java17
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/xmladapter/enumeration/MoreGenericEnumRoot.java64
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/xmladapter/enumeration/MoreGenericSuitsAdapter.java17
-rw-r--r--moxy/org.eclipse.persistence.moxy.dynamicxjc/src/org/eclipse/persistence/jaxb/javamodel/xjc/XJCJavaClassImpl.java37
-rw-r--r--moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/internal/jaxb/GenericsClassHelper.java308
-rw-r--r--moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/internal/jaxb/XMLJavaTypeConverter.java144
-rw-r--r--moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/compiler/Property.java108
-rw-r--r--moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/javamodel/JavaClass.java19
-rw-r--r--moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/javamodel/JavaClassInstanceOf.java21
-rw-r--r--moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/javamodel/oxm/OXMJAXBElementImpl.java47
-rw-r--r--moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/javamodel/oxm/OXMJavaClassImpl.java47
-rw-r--r--moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/javamodel/oxm/OXMObjectFactoryImpl.java48
-rw-r--r--moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/javamodel/reflection/JavaClassImpl.java124
16 files changed, 812 insertions, 312 deletions
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/xmladapter/XmlAdapterTestSuite.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/xmladapter/XmlAdapterTestSuite.java
index 319e234..0217db9 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/xmladapter/XmlAdapterTestSuite.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/xmladapter/XmlAdapterTestSuite.java
@@ -1,8 +1,8 @@
-/*******************************************************************************
- * Copyright (c) 1998, 2012 Oracle and/or its affiliates. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
- * which accompanies this distribution.
+/*******************************************************************************
+ * Copyright (c) 1998, 2014 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
@@ -32,12 +32,13 @@ import org.eclipse.persistence.testing.jaxb.xmladapter.direct.XmlAdapterDirectEx
import org.eclipse.persistence.testing.jaxb.xmladapter.direct.XmlAdapterDirectNullTestCases;
import org.eclipse.persistence.testing.jaxb.xmladapter.direct.XmlAdapterDirectTestCases;
import org.eclipse.persistence.testing.jaxb.xmladapter.direct.XmlAdapterSchemaTypeTestCases;
-import org.eclipse.persistence.testing.jaxb.xmladapter.direct.objectlist.ObjectListTestCases;
-import org.eclipse.persistence.testing.jaxb.xmladapter.elementref.XmlAdapterElementRefListTestCases;
-import org.eclipse.persistence.testing.jaxb.xmladapter.elementref.XmlAdapterElementRefTestCases;
-import org.eclipse.persistence.testing.jaxb.xmladapter.enumeration.AdapterEnumTestCases;
-import org.eclipse.persistence.testing.jaxb.xmladapter.generics.AdapterWithGenericsTestCases;
-import org.eclipse.persistence.testing.jaxb.xmladapter.hexbinary.XmlAdapterHexBinaryTestCases;
+import org.eclipse.persistence.testing.jaxb.xmladapter.direct.objectlist.ObjectListTestCases;
+import org.eclipse.persistence.testing.jaxb.xmladapter.elementref.XmlAdapterElementRefListTestCases;
+import org.eclipse.persistence.testing.jaxb.xmladapter.elementref.XmlAdapterElementRefTestCases;
+import org.eclipse.persistence.testing.jaxb.xmladapter.enumeration.AdapterEnumMoreGenericTestCases;
+import org.eclipse.persistence.testing.jaxb.xmladapter.enumeration.AdapterEnumTestCases;
+import org.eclipse.persistence.testing.jaxb.xmladapter.generics.AdapterWithGenericsTestCases;
+import org.eclipse.persistence.testing.jaxb.xmladapter.hexbinary.XmlAdapterHexBinaryTestCases;
import org.eclipse.persistence.testing.jaxb.xmladapter.inheritance.AdapterWithInheritanceTestCases;
import org.eclipse.persistence.testing.jaxb.xmladapter.inheritance.generics.GenericAdapterTestCases;
import org.eclipse.persistence.testing.jaxb.xmladapter.list.XmlAdapterListMultipleBarTestCases;
@@ -84,12 +85,13 @@ public class XmlAdapterTestSuite extends TestCase {
suite.addTestSuite(CollapsedStringListTestCases.class);
suite.addTestSuite(CollapsedStringTestCases.class);
suite.addTestSuite(NormalizedStringListTestCases.class);
- suite.addTestSuite(NormalizedStringTestCases.class);
- suite.addTestSuite(AdapterWithInheritanceTestCases.class);
- suite.addTestSuite(AdapterEnumTestCases.class);
- suite.addTestSuite(GenericAdapterTestCases.class);
- suite.addTestSuite(NoArgCtorAdapterTestCases.class);
- suite.addTestSuite(XmlAdapterSchemaTypeTestCases.class);
+ suite.addTestSuite(NormalizedStringTestCases.class);
+ suite.addTestSuite(AdapterWithInheritanceTestCases.class);
+ suite.addTestSuite(AdapterEnumTestCases.class);
+ suite.addTestSuite(AdapterEnumMoreGenericTestCases.class);
+ suite.addTestSuite(GenericAdapterTestCases.class);
+ suite.addTestSuite(NoArgCtorAdapterTestCases.class);
+ suite.addTestSuite(XmlAdapterSchemaTypeTestCases.class);
return suite;
}
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/xmladapter/enumeration/AdapterEnumMoreGenericTestCases.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/xmladapter/enumeration/AdapterEnumMoreGenericTestCases.java
new file mode 100644
index 0000000..d2f61f2
--- /dev/null
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/xmladapter/enumeration/AdapterEnumMoreGenericTestCases.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ ******************************************************************************/
+package org.eclipse.persistence.testing.jaxb.xmladapter.enumeration;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import org.eclipse.persistence.testing.jaxb.JAXBWithJSONTestCases;
+
+/**
+ * This test represents scenario when more complicated generic XmlAdapter is used.
+ * <p>
+ * Example: GenericSuitsAdapterWithT&lt;T extends Enum> extends XmlAdapter&lt;String, T>
+ * </p>
+ */
+public class AdapterEnumMoreGenericTestCases extends JAXBWithJSONTestCases{
+ private final static String XML_RESOURCE = "org/eclipse/persistence/testing/jaxb/xmladapter/enum.xml";
+ private final static String JSON_RESOURCE = "org/eclipse/persistence/testing/jaxb/xmladapter/enum.json";
+
+ public AdapterEnumMoreGenericTestCases(String name) throws Exception {
+ super(name);
+ setControlDocument(XML_RESOURCE);
+ setControlJSON(JSON_RESOURCE);
+ Class[] classes = {MoreGenericEnumRoot.class};
+ setClasses(classes);
+ }
+
+ protected Object getControlObject() {
+ MoreGenericEnumRoot emp = new MoreGenericEnumRoot();
+ emp.multi = new ArrayList<Byte>();
+ emp.multi.add((byte)1);
+ emp.multi.add((byte)3);
+ emp.multi.add((byte)1);
+
+ emp.single = (byte)2;
+
+ emp.cardSuit = MoreGenericCardSuit.DIAMOND;
+ emp.cardSuits = Arrays.asList(MoreGenericCardSuit.CLUB, MoreGenericCardSuit.HEART, MoreGenericCardSuit.SPADE);
+ return emp;
+ }
+}
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/xmladapter/enumeration/GenericSuitsAdapterWithT.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/xmladapter/enumeration/GenericSuitsAdapterWithT.java
new file mode 100644
index 0000000..ed06dbe
--- /dev/null
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/xmladapter/enumeration/GenericSuitsAdapterWithT.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ ******************************************************************************/
+package org.eclipse.persistence.testing.jaxb.xmladapter.enumeration;
+
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+
+import org.eclipse.persistence.internal.jaxb.GenericsClassHelper;
+
+/**
+ * <p>
+ * The correct values of BoundType and ValueType of Generic XmlAdapter are resolved by GenericsClassHelper.
+ *
+ * <p>
+ * ReflectionHelper does not help when you define XmlAdapter as XmlAdapter&lt;Object, Object> or XmlAdapter&lt;Object, T>
+ *
+ * @see GenericsClassHelper
+ *
+ */
+public abstract class GenericSuitsAdapterWithT<T extends Enum> extends XmlAdapter<String, T> {
+ @Override
+ public T unmarshal(String v) throws Exception {
+ return convert(v);
+ }
+
+ public abstract T convert(String value);
+
+ @Override
+ public String marshal(T v) throws Exception {
+ return v.name();
+ }
+}
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/xmladapter/enumeration/MoreGenericCardSuit.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/xmladapter/enumeration/MoreGenericCardSuit.java
new file mode 100644
index 0000000..ee6e9f7
--- /dev/null
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/xmladapter/enumeration/MoreGenericCardSuit.java
@@ -0,0 +1,17 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ ******************************************************************************/
+package org.eclipse.persistence.testing.jaxb.xmladapter.enumeration;
+
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+
+@XmlJavaTypeAdapter(value = MoreGenericSuitsAdapter.class)
+public enum MoreGenericCardSuit {
+ CLUB, DIAMOND, HEART, SPADE
+}
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/xmladapter/enumeration/MoreGenericEnumRoot.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/xmladapter/enumeration/MoreGenericEnumRoot.java
new file mode 100644
index 0000000..ed1e719
--- /dev/null
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/xmladapter/enumeration/MoreGenericEnumRoot.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ ******************************************************************************/
+package org.eclipse.persistence.testing.jaxb.xmladapter.enumeration;
+
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+
+@XmlRootElement(name="root")
+public class MoreGenericEnumRoot {
+
+ @XmlJavaTypeAdapter(ByteToExampleEnumAdapter.class)
+ public Byte single;
+
+ @XmlJavaTypeAdapter(ByteToExampleEnumAdapter.class)
+ public List<Byte> multi;
+
+ public MoreGenericCardSuit cardSuit;
+
+ public List<MoreGenericCardSuit> cardSuits;
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ MoreGenericEnumRoot enumRoot = (MoreGenericEnumRoot) o;
+
+ if (cardSuit != enumRoot.cardSuit) return false;
+ if (cardSuits != null ? !cardSuits.equals(enumRoot.cardSuits) : enumRoot.cardSuits != null) return false;
+ if (multi != null ? !multi.equals(enumRoot.multi) : enumRoot.multi != null) return false;
+ if (single != null ? !single.equals(enumRoot.single) : enumRoot.single != null) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = single != null ? single.hashCode() : 0;
+ result = 31 * result + (multi != null ? multi.hashCode() : 0);
+ result = 31 * result + (cardSuit != null ? cardSuit.hashCode() : 0);
+ result = 31 * result + (cardSuits != null ? cardSuits.hashCode() : 0);
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return "EnumRoot{" +
+ "single=" + single +
+ ", multi=" + multi +
+ ", cardSuit=" + cardSuit +
+ ", cardSuits=" + cardSuits +
+ '}';
+ }
+}
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/xmladapter/enumeration/MoreGenericSuitsAdapter.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/xmladapter/enumeration/MoreGenericSuitsAdapter.java
new file mode 100644
index 0000000..f9ad67c
--- /dev/null
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/xmladapter/enumeration/MoreGenericSuitsAdapter.java
@@ -0,0 +1,17 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ ******************************************************************************/
+package org.eclipse.persistence.testing.jaxb.xmladapter.enumeration;
+
+public class MoreGenericSuitsAdapter extends GenericSuitsAdapter<MoreGenericCardSuit> {
+ @Override
+ public MoreGenericCardSuit convert(String value) {
+ return MoreGenericCardSuit.valueOf(value);
+ }
+}
diff --git a/moxy/org.eclipse.persistence.moxy.dynamicxjc/src/org/eclipse/persistence/jaxb/javamodel/xjc/XJCJavaClassImpl.java b/moxy/org.eclipse.persistence.moxy.dynamicxjc/src/org/eclipse/persistence/jaxb/javamodel/xjc/XJCJavaClassImpl.java
index a3b792c..7692c2e 100644
--- a/moxy/org.eclipse.persistence.moxy.dynamicxjc/src/org/eclipse/persistence/jaxb/javamodel/xjc/XJCJavaClassImpl.java
+++ b/moxy/org.eclipse.persistence.moxy.dynamicxjc/src/org/eclipse/persistence/jaxb/javamodel/xjc/XJCJavaClassImpl.java
@@ -23,19 +23,13 @@ import java.util.Map;
import org.eclipse.persistence.dynamic.DynamicClassLoader;
import org.eclipse.persistence.exceptions.JAXBException;
-import org.eclipse.persistence.internal.helper.ClassConstants;
-import org.eclipse.persistence.internal.helper.ConversionManager;
-import org.eclipse.persistence.internal.security.PrivilegedAccessHelper;
-import org.eclipse.persistence.jaxb.javamodel.JavaAnnotation;
-import org.eclipse.persistence.jaxb.javamodel.JavaClass;
-import org.eclipse.persistence.jaxb.javamodel.JavaConstructor;
-import org.eclipse.persistence.jaxb.javamodel.JavaField;
-import org.eclipse.persistence.jaxb.javamodel.JavaMethod;
-import org.eclipse.persistence.jaxb.javamodel.JavaModel;
-import org.eclipse.persistence.jaxb.javamodel.JavaPackage;
-
-import com.sun.codemodel.ClassType;
-import com.sun.codemodel.JAnnotationUse;
+import org.eclipse.persistence.internal.helper.ClassConstants;
+import org.eclipse.persistence.internal.helper.ConversionManager;
+import org.eclipse.persistence.internal.security.PrivilegedAccessHelper;
+import org.eclipse.persistence.jaxb.javamodel.*;
+
+import com.sun.codemodel.ClassType;
+import com.sun.codemodel.JAnnotationUse;
import com.sun.codemodel.JClass;
import com.sun.codemodel.JCodeModel;
import com.sun.codemodel.JDefinedClass;
@@ -701,12 +695,17 @@ public class XJCJavaClassImpl implements JavaClass {
* Not supported.
*/
public boolean isSynthetic() {
- throw new UnsupportedOperationException("isSynthetic");
- }
-
- /**
- * If this <code>JavaClass</code> is annotated with an <code>Annotation</code> matching <code>aClass</code>,
- * return its <code>JavaAnnotation</code> representation.
+ throw new UnsupportedOperationException("isSynthetic");
+ }
+
+ @Override
+ public JavaClassInstanceOf instanceOf() {
+ return JavaClassInstanceOf.XJC_JAVA_CLASS_IMPL;
+ }
+
+ /**
+ * If this <code>JavaClass</code> is annotated with an <code>Annotation</code> matching <code>aClass</code>,
+ * return its <code>JavaAnnotation</code> representation.
*
* @param aClass a <code>JavaClass</code> representing the <code>Annotation</code> to look for.
*
diff --git a/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/internal/jaxb/GenericsClassHelper.java b/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/internal/jaxb/GenericsClassHelper.java
new file mode 100644
index 0000000..e30cc15
--- /dev/null
+++ b/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/internal/jaxb/GenericsClassHelper.java
@@ -0,0 +1,308 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ ******************************************************************************/
+package org.eclipse.persistence.internal.jaxb;
+
+import java.lang.reflect.Array;
+import java.lang.reflect.GenericArrayType;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.lang.reflect.TypeVariable;
+import java.util.HashMap;
+import java.util.Map;
+
+
+/**
+ * Utility class for Generic class hierarchy.
+ *
+ */
+public class GenericsClassHelper {
+
+ /**
+ * A tuple consisting of a concrete class, declaring class that declares a
+ * generic interface type.
+ */
+ private static class DeclaringClassInterfacePair {
+ public final Class concreteClass;
+
+ public final Class declaringClass;
+
+ public final Type genericInterface;
+
+ private DeclaringClassInterfacePair(Class concreteClass, Class declaringClass, Type genericInteface) {
+ this.concreteClass = concreteClass;
+ this.declaringClass = declaringClass;
+ this.genericInterface = genericInteface;
+ }
+ }
+
+ /**
+ * Get the parameterized type arguments for a declaring class that
+ * declares a generic class or interface type.
+ *
+ * @param concrete the concrete class than directly or indirectly
+ * implements or extends an interface class.
+ * @param classOrIface the interface or class.
+ * @return the parameterized type arguments, or null if the generic
+ * interface type is not a parameterized type.
+ */
+ public static Type[] getParameterizedTypeArguments(Class concrete, Class classOrIface) {
+ DeclaringClassInterfacePair declaringClassInterfacePair = getClass(concrete, classOrIface);
+ if (null != declaringClassInterfacePair) {
+ return getParameterizedTypeArguments(declaringClassInterfacePair);
+ }
+ return null;
+ }
+
+ /**
+ * Get the parameterized type arguments for a declaring class that
+ * declares a generic interface type.
+ *
+ * @param p the declaring class
+ * @return the parameterized type arguments, or null if the generic
+ * interface type is not a parameterized type.
+ */
+ private static Type[] getParameterizedTypeArguments(DeclaringClassInterfacePair p) {
+ if (p.genericInterface instanceof ParameterizedType) {
+ ParameterizedType pt = (ParameterizedType) p.genericInterface;
+ Type[] as = pt.getActualTypeArguments();
+ Type[] ras = new Type[as.length];
+
+ for (int i = 0; i < as.length; i++) {
+ Type a = as[i];
+ if (a instanceof Class) {
+ ras[i] = a;
+ } else if (a instanceof ParameterizedType) {
+ pt = (ParameterizedType) a;
+ ras[i] = a;
+ } else if (a instanceof TypeVariable) {
+ ClassTypePair ctp = resolveTypeVariable(p.concreteClass, p.declaringClass, (TypeVariable) a);
+ if (null != ctp) {
+ ras[i] = ctp.t;
+ }
+ }
+ }
+ return ras;
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Find the declaring class that implements or extends an interface or class.
+ *
+ * @param concrete the concrete class than directly or indirectly
+ * implements or extends an interface class.
+ * @param classOrIface the interface or class.
+ * @return the tuple of the declaring class and the generic interface or class
+ * type.
+ */
+ private static DeclaringClassInterfacePair getClass(Class concrete, Class classOrIface) {
+ return getClass(concrete, classOrIface, concrete);
+ }
+
+ private static DeclaringClassInterfacePair getClass(Class concrete, Class classOrIface, Class c) {
+ Type[] gis = null;
+
+ if (null != c.getGenericSuperclass()) {
+ gis = new Type[] {c.getGenericSuperclass()};
+ }
+
+ if (null == gis) {
+ gis = c.getGenericInterfaces();
+ }
+
+ DeclaringClassInterfacePair p = getType(concrete, classOrIface, c, gis);
+ if (p != null)
+ return p;
+
+ c = c.getSuperclass();
+ if (c == null || c == Object.class)
+ return null;
+
+ return getClass(concrete, classOrIface, c);
+ }
+
+ private static DeclaringClassInterfacePair getType(Class concrete, Class classOrIface, Class c, Type[] ts) {
+ for (Type t : ts) {
+ DeclaringClassInterfacePair p = getType(concrete, classOrIface, c, t);
+ if (p != null)
+ return p;
+ }
+ return null;
+ }
+
+ private static DeclaringClassInterfacePair getType(Class concrete, Class classOrIface, Class c, Type t) {
+ if (t instanceof Class) {
+ if (t == classOrIface) {
+ return new DeclaringClassInterfacePair(concrete, c, t);
+ } else {
+ return getClass(concrete, classOrIface, (Class) t);
+ }
+ } else if (t instanceof ParameterizedType) {
+ ParameterizedType pt = (ParameterizedType) t;
+ if (pt.getRawType() == classOrIface) {
+ return new DeclaringClassInterfacePair(concrete, c, t);
+ } else {
+ return getClass(concrete, classOrIface, (Class) pt.getRawType());
+ }
+ }
+ return null;
+ }
+
+ /**
+ * A tuple consisting of a class and type of the class.
+ */
+ private static class ClassTypePair {
+
+ /**
+ * The type of the class.
+ */
+ public final Type t;
+
+ public ClassTypePair(Class c) {
+ this(c, c);
+ }
+
+ public ClassTypePair(Class c, Type t) {
+ this.t = t;
+ }
+ }
+
+ /**
+ * Given a type variable resolve the Java class of that variable.
+ *
+ * @param c the concrete class from which all type variables are resolved
+ * @param dc the declaring class where the type variable was defined
+ * @param tv the type variable
+ * @return the resolved Java class and type, otherwise null if the type variable
+ * could not be resolved
+ */
+ private static ClassTypePair resolveTypeVariable(Class c, Class dc, TypeVariable tv) {
+ return resolveTypeVariable(c, dc, tv, new HashMap<TypeVariable, Type>());
+ }
+
+ private static ClassTypePair resolveTypeVariable(Class c, Class dc, TypeVariable tv,
+ Map<TypeVariable, Type> map) {
+ Type[] gis = c.getGenericInterfaces();
+ for (Type gi : gis) {
+ if (gi instanceof ParameterizedType) {
+ // process pt of interface
+ ParameterizedType pt = (ParameterizedType) gi;
+ ClassTypePair ctp = resolveTypeVariable(pt, (Class) pt.getRawType(), dc, tv, map);
+ if (ctp != null)
+ return ctp;
+ }
+ }
+
+ Type gsc = c.getGenericSuperclass();
+ if (gsc instanceof ParameterizedType) {
+ // process pt of class
+ ParameterizedType pt = (ParameterizedType) gsc;
+ return resolveTypeVariable(pt, c.getSuperclass(), dc, tv, map);
+ } else if (gsc instanceof Class) {
+ return resolveTypeVariable(c.getSuperclass(), dc, tv, map);
+ }
+ return null;
+ }
+
+ private static ClassTypePair resolveTypeVariable(ParameterizedType pt, Class c, Class dc, TypeVariable tv,
+ Map<TypeVariable, Type> map) {
+ Type[] typeArguments = pt.getActualTypeArguments();
+
+ TypeVariable[] typeParameters = c.getTypeParameters();
+
+ Map<TypeVariable, Type> submap = new HashMap<TypeVariable, Type>();
+ for (int i = 0; i < typeArguments.length; i++) {
+ // Substitute a type variable with the Java class
+ if (typeArguments[i] instanceof TypeVariable) {
+ Type t = map.get(typeArguments[i]);
+ submap.put(typeParameters[i], t);
+ } else {
+ submap.put(typeParameters[i], typeArguments[i]);
+ }
+ }
+
+ if (c == dc) {
+ Type t = submap.get(tv);
+ if (t instanceof Class) {
+ return new ClassTypePair((Class) t);
+ } else if (t instanceof GenericArrayType) {
+ t = ((GenericArrayType) t).getGenericComponentType();
+ if (t instanceof Class) {
+ c = (Class) t;
+ try {
+ return new ClassTypePair(getArrayClass(c));
+ } catch (Exception e) {
+ }
+ return null;
+ } else if (t instanceof ParameterizedType) {
+ Type rt = ((ParameterizedType) t).getRawType();
+ if (rt instanceof Class) {
+ c = (Class) rt;
+ } else {
+ return null;
+ }
+ try {
+ return new ClassTypePair(getArrayClass(c), t);
+ } catch (Exception e) {
+ return null;
+ }
+ } else {
+ return null;
+ }
+ } else if (t instanceof ParameterizedType) {
+ pt = (ParameterizedType) t;
+ if (pt.getRawType() instanceof Class) {
+ return new ClassTypePair((Class) pt.getRawType(), pt);
+ } else
+ return null;
+ } else {
+ return null;
+ }
+ } else {
+ return resolveTypeVariable(c, dc, tv, submap);
+ }
+ }
+
+ protected static Class getClassOfType(Type type) {
+ if (type instanceof Class) {
+ return (Class) type;
+ } else if (type instanceof GenericArrayType) {
+ GenericArrayType arrayType = (GenericArrayType) type;
+ Type t = arrayType.getGenericComponentType();
+ if (t instanceof Class) {
+ return getArrayClass((Class) t);
+ }
+ } else if (type instanceof ParameterizedType) {
+ ParameterizedType subType = (ParameterizedType) type;
+ Type t = subType.getRawType();
+ if (t instanceof Class) {
+ return (Class) t;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Get Array class of component class.
+ *
+ * @param c the component class of the array
+ * @return the array class.
+ */
+ private static Class getArrayClass(Class c) {
+ try {
+ Object o = Array.newInstance(c, 0);
+ return o.getClass();
+ } catch (Exception e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+
+}
diff --git a/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/internal/jaxb/XMLJavaTypeConverter.java b/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/internal/jaxb/XMLJavaTypeConverter.java
index 2ed9063..c65020b 100644
--- a/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/internal/jaxb/XMLJavaTypeConverter.java
+++ b/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/internal/jaxb/XMLJavaTypeConverter.java
@@ -9,44 +9,41 @@
*
* Contributors:
* Oracle - initial API and implementation from Oracle TopLink
- ******************************************************************************/
-package org.eclipse.persistence.internal.jaxb;
-
-import java.security.AccessController;
-import java.security.PrivilegedActionException;
-import java.util.HashMap;
-
-import org.eclipse.persistence.core.mappings.converters.CoreConverter;
-import org.eclipse.persistence.exceptions.ConversionException;
-import org.eclipse.persistence.exceptions.JAXBException;
-import org.eclipse.persistence.internal.oxm.XMLConversionManager;
-import org.eclipse.persistence.internal.oxm.XMLBinaryDataHelper;
-import org.eclipse.persistence.internal.oxm.mappings.BinaryDataMapping;
-import org.eclipse.persistence.internal.security.PrivilegedAccessHelper;
-import org.eclipse.persistence.internal.security.PrivilegedClassForName;
-import org.eclipse.persistence.internal.security.PrivilegedGetConstructorFor;
-import org.eclipse.persistence.internal.security.PrivilegedGetDeclaredMethods;
-import org.eclipse.persistence.internal.security.PrivilegedGetMethods;
-import org.eclipse.persistence.internal.security.PrivilegedNewInstanceFromClass;
-import org.eclipse.persistence.internal.sessions.AbstractSession;
-import org.eclipse.persistence.mappings.DatabaseMapping;
-import org.eclipse.persistence.mappings.converters.ObjectTypeConverter;
-import org.eclipse.persistence.oxm.XMLMarshaller;
-import org.eclipse.persistence.oxm.XMLUnmarshaller;
-import org.eclipse.persistence.jaxb.JAXBMarshaller;
-import org.eclipse.persistence.jaxb.JAXBUnmarshaller;
-import org.eclipse.persistence.sessions.Session;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import javax.xml.bind.annotation.adapters.XmlAdapter;
-import javax.xml.namespace.QName;
-
-/**
- * Converter that wraps an XmlAdapter.
- *
+ ******************************************************************************/
+package org.eclipse.persistence.internal.jaxb;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Type;
+import java.security.AccessController;
+import java.util.HashMap;
+
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+import javax.xml.namespace.QName;
+
+import org.eclipse.persistence.core.mappings.converters.CoreConverter;
+import org.eclipse.persistence.exceptions.ConversionException;
+import org.eclipse.persistence.exceptions.JAXBException;
+import org.eclipse.persistence.internal.oxm.XMLBinaryDataHelper;
+import org.eclipse.persistence.internal.oxm.XMLConversionManager;
+import org.eclipse.persistence.internal.oxm.mappings.BinaryDataMapping;
+import org.eclipse.persistence.internal.security.PrivilegedAccessHelper;
+import org.eclipse.persistence.internal.security.PrivilegedClassForName;
+import org.eclipse.persistence.internal.security.PrivilegedGetConstructorFor;
+import org.eclipse.persistence.internal.security.PrivilegedNewInstanceFromClass;
+import org.eclipse.persistence.internal.sessions.AbstractSession;
+import org.eclipse.persistence.jaxb.JAXBMarshaller;
+import org.eclipse.persistence.jaxb.JAXBUnmarshaller;
+import org.eclipse.persistence.mappings.DatabaseMapping;
+import org.eclipse.persistence.mappings.converters.ObjectTypeConverter;
+import org.eclipse.persistence.oxm.XMLMarshaller;
+import org.eclipse.persistence.oxm.XMLUnmarshaller;
+import org.eclipse.persistence.sessions.Session;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+/**
+ * Converter that wraps an XmlAdapter.
+ *
* @see javax.xml.bind.annotation.adapters.XmlAdapter
*/
public class XMLJavaTypeConverter extends org.eclipse.persistence.oxm.mappings.converters.XMLConverterAdapter {
@@ -252,38 +249,14 @@ public class XMLJavaTypeConverter extends org.eclipse.persistence.oxm.mappings.c
// validate adapter class extends javax.xml.bind.annotation.adapters.XmlAdapter
if (!XmlAdapter.class.isAssignableFrom(xmlAdapterClass)) {
- throw JAXBException.invalidAdapterClass(getXmlAdapterClassName());
- }
-
- this.mapping = mapping;
- Method[] methods; // becaus adapter could be not direct child of XmlAdapter -> we need all methods
- if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
- try {
- methods = AccessController.doPrivileged(new PrivilegedGetMethods(xmlAdapterClass));
- } catch (PrivilegedActionException ex) {
- throw JAXBException.adapterClassMethodsCouldNotBeAccessed(getXmlAdapterClassName(), ex);
- }
- } else {
- methods = PrivilegedAccessHelper.getMethods(xmlAdapterClass);
- }
- // look for marshal method
- Class[] parameterTypes;
- for (Method method : methods) {
- if (!method.isBridge()
- && method.getName().equals("marshal") // looking for marshal method
- && (parameterTypes = PrivilegedAccessHelper.getMethodParameterTypes(method)).length == 1) { // should contain 1 parameter
-
- Class methodReturnType = PrivilegedAccessHelper.getMethodReturnType(method);
- if (!methodReturnType.isInterface())
- valueType = methodReturnType;
- boundType = parameterTypes[0];
- break;
- }
- }
-
- try {
- try {
- if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
+ throw JAXBException.invalidAdapterClass(getXmlAdapterClassName());
+ }
+
+ setBoundTypeAndValueTypeInCaseOfGenericXmlAdapter();
+
+ try {
+ try {
+ if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
xmlAdapter = (XmlAdapter) AccessController.doPrivileged(new PrivilegedNewInstanceFromClass(getXmlAdapterClass()));
} else {
xmlAdapter = (XmlAdapter) PrivilegedAccessHelper.newInstanceFromClass(getXmlAdapterClass());
@@ -305,12 +278,31 @@ public class XMLJavaTypeConverter extends org.eclipse.persistence.oxm.mappings.c
((ObjectTypeConverter)nestedConverter).convertClassNamesToClasses(loader);
}
nestedConverter.initialize(mapping, session);
- }
- }
-
- /**
- * Satisfy the interface.
- */
+ }
+ }
+
+ private void setBoundTypeAndValueTypeInCaseOfGenericXmlAdapter() {
+ Type[] parameterizedTypeArguments = GenericsClassHelper.getParameterizedTypeArguments(xmlAdapterClass, XmlAdapter.class);
+
+ if (null != parameterizedTypeArguments) {
+ Class valueTypeClass = GenericsClassHelper.getClassOfType(parameterizedTypeArguments[0]);
+ if (null != valueTypeClass) {
+ valueType = valueTypeClass;
+ }
+ if (valueType.isInterface()) {
+ valueType = Object.class; // during unmarshalling we'll need to instantiate this, so -> no interfaces
+ }
+
+ Class boundTypeClass = GenericsClassHelper.getClassOfType(parameterizedTypeArguments[1]);
+ if (null != boundTypeClass) {
+ boundType = boundTypeClass;
+ }
+ }
+ }
+
+ /**
+ * Satisfy the interface.
+ */
public boolean isMutable() {
return false;
}
diff --git a/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/compiler/Property.java b/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/compiler/Property.java
index 9afa0f9..b7a2879 100644
--- a/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/compiler/Property.java
+++ b/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/compiler/Property.java
@@ -21,23 +21,21 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
+import java.util.List;
+import java.util.Map;
+
import javax.xml.bind.annotation.adapters.XmlAdapter;
import javax.xml.namespace.QName;
import org.eclipse.persistence.jaxb.compiler.facets.Facet;
-import org.eclipse.persistence.jaxb.javamodel.reflection.JavaClassImpl;
-import org.eclipse.persistence.internal.oxm.mappings.Field;
+import org.eclipse.persistence.internal.jaxb.GenericsClassHelper;
import org.eclipse.persistence.internal.oxm.XPathFragment;
-import org.eclipse.persistence.jaxb.javamodel.Helper;
-import org.eclipse.persistence.jaxb.javamodel.JavaClass;
-import org.eclipse.persistence.jaxb.javamodel.JavaHasAnnotations;
-import org.eclipse.persistence.jaxb.javamodel.JavaMethod;
-import org.eclipse.persistence.jaxb.xmlmodel.XmlAbstractNullPolicy;
-import org.eclipse.persistence.jaxb.xmlmodel.XmlElementRef;
-import org.eclipse.persistence.jaxb.xmlmodel.XmlElementWrapper;
+import org.eclipse.persistence.internal.oxm.mappings.Field;
+import org.eclipse.persistence.jaxb.javamodel.*;
+import org.eclipse.persistence.jaxb.javamodel.reflection.JavaClassImpl;
+import org.eclipse.persistence.jaxb.xmlmodel.XmlAbstractNullPolicy;
+import org.eclipse.persistence.jaxb.xmlmodel.XmlElementRef;
+import org.eclipse.persistence.jaxb.xmlmodel.XmlElementWrapper;
import org.eclipse.persistence.jaxb.xmlmodel.XmlElements;
import org.eclipse.persistence.jaxb.xmlmodel.XmlJavaTypeAdapter;
import org.eclipse.persistence.jaxb.xmlmodel.XmlJoinNodes;
@@ -73,9 +71,9 @@ public class Property implements Cloneable {
private String mimeType;
private JavaClass type;
private JavaHasAnnotations element;
- private JavaClass genericType;
- private boolean isAttribute = false;
- private boolean isAnyAttribute = false;
+ private JavaClass genericType;
+ private boolean isAttribute = false;
+ private boolean isAnyAttribute = false;
private boolean isAnyElement = false;
private Helper helper;
private Map<Object, Object> userProperties;
@@ -84,9 +82,9 @@ public class Property implements Cloneable {
//Original get and set methods for this property
//Used to keep track of overrides
private String originalGetMethodName;
- private String originalSetMethodName;
-
- private String getMethodName;
+ private String originalSetMethodName;
+
+ private String getMethodName;
private String setMethodName;
private boolean isRequired = false;
private boolean isNillable = false;
@@ -118,18 +116,18 @@ public class Property implements Cloneable {
private boolean isInverseReference;
private boolean isWriteableInverseReference;
- // XmlAnyElement specific attributes
- private boolean lax;
- private String domHandlerClassName;
+ // XmlAnyElement specific attributes
+ private boolean lax;
+ private String domHandlerClassName;
private String variableAttributeName;
private String variableClassName;
private boolean variableNodeAttribute;
// XmlMap specific attributes
private JavaClass keyType;
- private JavaClass valueType;
- public static final String DEFAULT_KEY_NAME = "key";
- public static final String DEFAULT_VALUE_NAME = "value";
+ private JavaClass valueType;
+ public static final String DEFAULT_KEY_NAME = "key";
+ public static final String DEFAULT_VALUE_NAME = "value";
private boolean isMap = false;
private String xmlPath;
@@ -149,9 +147,9 @@ public class Property implements Cloneable {
private boolean isSuperClassProperty;
private boolean isTransientType;
- private static final String MARSHAL_METHOD_NAME = "marshal";
-
- private static JavaClass XML_ADAPTER_CLASS;
+ private static final String MARSHAL_METHOD_NAME = "marshal";
+
+ private static JavaClass XML_ADAPTER_CLASS;
private static JavaClass OBJECT_CLASS;
private boolean isTyped;
@@ -163,9 +161,9 @@ public class Property implements Cloneable {
public Property() {}
public Property(Helper helper) {
- this.helper = helper;
-
- // let's init static fields
+ this.helper = helper;
+
+ // let's init static fields
if (XML_ADAPTER_CLASS == null)
XML_ADAPTER_CLASS = helper.getJavaClass(XmlAdapter.class);
if (OBJECT_CLASS == null)
@@ -181,28 +179,26 @@ public class Property implements Cloneable {
* original type will be set as required based on the XmlAdapter's
* marshal method return type and input parameters.
*
- * @param adapterCls
- */
- public void setAdapterClass(JavaClass adapterCls) {
- // Looking for XmlAdapter inheritance
- JavaClass xmlAdapterChild = adapterCls;
- while (xmlAdapterChild.getSuperclass() != null && !XML_ADAPTER_CLASS.getQualifiedName().equals(xmlAdapterChild.getSuperclass().getQualifiedName())) {
- xmlAdapterChild = xmlAdapterChild.getSuperclass();
- }
- Type xmlAdapterType = xmlAdapterChild.getGenericSuperclass();
- if (xmlAdapterType != null) { // generic XmlAdapter found
- ParameterizedType parameterizedSuperClass = (ParameterizedType) xmlAdapterType;
- Type[] typeArguments = parameterizedSuperClass.getActualTypeArguments();
- if (typeArguments[0] == typeArguments[1]) // adapter doesn't change the type -> no need to continue
- return;
- JavaClass valueTypeClass = getJavaClassFromType(typeArguments[0]);
- if (valueTypeClass.isInterface())
- valueTypeClass = OBJECT_CLASS; // during unmarshalling we'll need to instantiate this, so -> no interfaces
- setTypeFromAdapterClass(valueTypeClass, getJavaClassFromType(typeArguments[1]));
- return;
- }
-
- // If no generic superclass was found, use the old method of looking at
+ * @param adapterCls
+ */
+ public void setAdapterClass(JavaClass adapterCls) {
+
+ if (adapterCls.instanceOf() == JavaClassInstanceOf.JAVA_CLASS_IMPL) {
+ Type[] parameterizedTypeArguments = GenericsClassHelper.getParameterizedTypeArguments(((JavaClassImpl)adapterCls).getJavaClass(), XmlAdapter.class);
+ if (null != parameterizedTypeArguments && null != parameterizedTypeArguments[0]) {
+ JavaClass valueTypeClass = getJavaClassFromType(parameterizedTypeArguments[0]);
+ JavaClass boundType = getJavaClassFromType(parameterizedTypeArguments[1]);
+
+ if (valueTypeClass.isInterface()) {
+ valueTypeClass = OBJECT_CLASS; // during unmarshalling we'll need to instantiate this, so -> no interfaces
+ }
+
+ setTypeFromAdapterClass(valueTypeClass, boundType);
+ return;
+ }
+ }
+
+ // If no generic superclass was found, use the old method of looking at
// marshal method return type. This mechanism is used for Dynamic JAXB.
ArrayList<JavaMethod> marshalMethods = new ArrayList<JavaMethod>();
@@ -1487,9 +1483,9 @@ public class Property implements Cloneable {
public boolean isTyped() {
return isTyped;
- }
-
- public void setTyped(boolean isTyped) {
+ }
+
+ public void setTyped(boolean isTyped) {
this.isTyped = isTyped;
}
@@ -1524,4 +1520,4 @@ public class Property implements Cloneable {
public boolean isNotNullAnnotated() {
return notNullAnnotated;
}
-} \ No newline at end of file
+}
diff --git a/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/javamodel/JavaClass.java b/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/javamodel/JavaClass.java
index 6233978..a4362a1 100644
--- a/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/javamodel/JavaClass.java
+++ b/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/javamodel/JavaClass.java
@@ -1,8 +1,8 @@
-/*******************************************************************************
- * Copyright (c) 1998, 2013 Oracle and/or its affiliates. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
- * which accompanies this distribution.
+/*******************************************************************************
+ * Copyright (c) 1998, 2014 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
@@ -63,7 +63,8 @@ public interface JavaClass extends JavaHasAnnotations {
public boolean isPrimitive();
public boolean isPrivate();
public boolean isProtected();
- public boolean isPublic();
- public boolean isStatic();
- public boolean isSynthetic();
-}
+ public boolean isPublic();
+ public boolean isStatic();
+ public boolean isSynthetic();
+ public JavaClassInstanceOf instanceOf();
+}
diff --git a/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/javamodel/JavaClassInstanceOf.java b/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/javamodel/JavaClassInstanceOf.java
new file mode 100644
index 0000000..87ffc15
--- /dev/null
+++ b/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/javamodel/JavaClassInstanceOf.java
@@ -0,0 +1,21 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ ******************************************************************************/
+package org.eclipse.persistence.jaxb.javamodel;
+
+/**
+ * INTERNAL:
+ * <p><b>Purpose:</b>To provide faster alternative to instanceof.
+ *
+ * @author Martin Vojtek (martin.vojtek@oracle.com)
+ */
+public enum JavaClassInstanceOf {
+ JAVA_CLASS_IMPL, OXM_JAVA_CLASS_IMPL, OXM_JAXB_ELEMENT_IMPL, OXM_OBJECT_FACTORY_IMPL, XJC_JAVA_CLASS_IMPL
+}
diff --git a/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/javamodel/oxm/OXMJAXBElementImpl.java b/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/javamodel/oxm/OXMJAXBElementImpl.java
index b134ac8..b27c811 100644
--- a/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/javamodel/oxm/OXMJAXBElementImpl.java
+++ b/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/javamodel/oxm/OXMJAXBElementImpl.java
@@ -1,8 +1,8 @@
-/*******************************************************************************
- * Copyright (c) 2011, 2013 Oracle and/or its affiliates. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
- * which accompanies this distribution.
+/*******************************************************************************
+ * Copyright (c) 2011, 2014 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
@@ -13,19 +13,13 @@
package org.eclipse.persistence.jaxb.javamodel.oxm;
import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.Collection;
-
-import org.eclipse.persistence.jaxb.javamodel.JavaAnnotation;
-import org.eclipse.persistence.jaxb.javamodel.JavaClass;
-import org.eclipse.persistence.jaxb.javamodel.JavaConstructor;
-import org.eclipse.persistence.jaxb.javamodel.JavaField;
-import org.eclipse.persistence.jaxb.javamodel.JavaMethod;
-import org.eclipse.persistence.jaxb.javamodel.JavaModel;
-import org.eclipse.persistence.jaxb.javamodel.JavaPackage;
-
-/**
- * INTERNAL:
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.eclipse.persistence.jaxb.javamodel.*;
+
+/**
+ * INTERNAL:
* <p>
* <b>Purpose:</b> Specialized <code>JavaClass</code> used to represent a
* <code>JAXBElement</code>. Used when bootstrapping a <code>DynamicJAXBContext</code>
@@ -202,12 +196,17 @@ public class OXMJAXBElementImpl implements JavaClass {
}
public boolean isSynthetic() {
- return false;
- }
-
- public JavaAnnotation getAnnotation(JavaClass arg0) {
- return null;
- }
+ return false;
+ }
+
+ @Override
+ public JavaClassInstanceOf instanceOf() {
+ return JavaClassInstanceOf.OXM_JAXB_ELEMENT_IMPL;
+ }
+
+ public JavaAnnotation getAnnotation(JavaClass arg0) {
+ return null;
+ }
public Collection<JavaAnnotation> getAnnotations() {
return null;
diff --git a/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/javamodel/oxm/OXMJavaClassImpl.java b/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/javamodel/oxm/OXMJavaClassImpl.java
index 4ea3862..0714cd5 100644
--- a/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/javamodel/oxm/OXMJavaClassImpl.java
+++ b/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/javamodel/oxm/OXMJavaClassImpl.java
@@ -1,8 +1,8 @@
-/*******************************************************************************
- * Copyright (c) 2011, 2013 Oracle and/or its affiliates. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
- * which accompanies this distribution.
+/*******************************************************************************
+ * Copyright (c) 2011, 2014 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
@@ -22,19 +22,13 @@ import java.util.Iterator;
import java.util.List;
import javax.xml.bind.JAXBElement;
-
-import org.eclipse.persistence.internal.security.PrivilegedAccessHelper;
-import org.eclipse.persistence.jaxb.compiler.XMLProcessor;
-import org.eclipse.persistence.jaxb.javamodel.JavaAnnotation;
-import org.eclipse.persistence.jaxb.javamodel.JavaClass;
-import org.eclipse.persistence.jaxb.javamodel.JavaConstructor;
-import org.eclipse.persistence.jaxb.javamodel.JavaField;
-import org.eclipse.persistence.jaxb.javamodel.JavaMethod;
-import org.eclipse.persistence.jaxb.javamodel.JavaModel;
-import org.eclipse.persistence.jaxb.javamodel.JavaPackage;
-import org.eclipse.persistence.jaxb.xmlmodel.JavaAttribute;
-import org.eclipse.persistence.jaxb.xmlmodel.JavaType;
-import org.eclipse.persistence.jaxb.xmlmodel.JavaType.JavaAttributes;
+
+import org.eclipse.persistence.internal.security.PrivilegedAccessHelper;
+import org.eclipse.persistence.jaxb.compiler.XMLProcessor;
+import org.eclipse.persistence.jaxb.javamodel.*;
+import org.eclipse.persistence.jaxb.xmlmodel.JavaAttribute;
+import org.eclipse.persistence.jaxb.xmlmodel.JavaType;
+import org.eclipse.persistence.jaxb.xmlmodel.JavaType.JavaAttributes;
import org.eclipse.persistence.jaxb.xmlmodel.XmlAnyAttribute;
import org.eclipse.persistence.jaxb.xmlmodel.XmlAnyElement;
import org.eclipse.persistence.jaxb.xmlmodel.XmlAttribute;
@@ -603,12 +597,17 @@ public class OXMJavaClassImpl implements JavaClass {
* Not supported.
*/
public boolean isSynthetic() {
- throw new UnsupportedOperationException("isSynthetic");
- }
-
- /**
- * If this <code>JavaClass</code> is annotated with an <code>Annotation</code> matching <code>aClass</code>,
- * return its <code>JavaAnnotation</code> representation.
+ throw new UnsupportedOperationException("isSynthetic");
+ }
+
+ @Override
+ public JavaClassInstanceOf instanceOf() {
+ return JavaClassInstanceOf.OXM_JAVA_CLASS_IMPL;
+ }
+
+ /**
+ * If this <code>JavaClass</code> is annotated with an <code>Annotation</code> matching <code>aClass</code>,
+ * return its <code>JavaAnnotation</code> representation.
*
* @param aClass a <code>JavaClass</code> representing the <code>Annotation</code> to look for.
*
diff --git a/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/javamodel/oxm/OXMObjectFactoryImpl.java b/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/javamodel/oxm/OXMObjectFactoryImpl.java
index 765e56e..4c0d533 100644
--- a/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/javamodel/oxm/OXMObjectFactoryImpl.java
+++ b/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/javamodel/oxm/OXMObjectFactoryImpl.java
@@ -1,8 +1,8 @@
-/*******************************************************************************
- * Copyright (c) 2011, 2013 Oracle and/or its affiliates. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
- * which accompanies this distribution.
+/*******************************************************************************
+ * Copyright (c) 2011, 2014 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
@@ -18,20 +18,13 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.persistence.internal.oxm.XMLConversionManager;
-import org.eclipse.persistence.jaxb.javamodel.AnnotationProxy;
-import org.eclipse.persistence.jaxb.javamodel.JavaAnnotation;
-import org.eclipse.persistence.jaxb.javamodel.JavaClass;
-import org.eclipse.persistence.jaxb.javamodel.JavaConstructor;
-import org.eclipse.persistence.jaxb.javamodel.JavaField;
-import org.eclipse.persistence.jaxb.javamodel.JavaMethod;
-import org.eclipse.persistence.jaxb.javamodel.JavaModel;
-import org.eclipse.persistence.jaxb.javamodel.JavaPackage;
-import org.eclipse.persistence.jaxb.javamodel.reflection.JavaAnnotationImpl;
-import org.eclipse.persistence.jaxb.xmlmodel.XmlRegistry;
-import org.eclipse.persistence.jaxb.xmlmodel.XmlRegistry.XmlElementDecl;
+import java.util.List;
+
+import org.eclipse.persistence.internal.oxm.XMLConversionManager;
+import org.eclipse.persistence.jaxb.javamodel.*;
+import org.eclipse.persistence.jaxb.javamodel.reflection.JavaAnnotationImpl;
+import org.eclipse.persistence.jaxb.xmlmodel.XmlRegistry;
+import org.eclipse.persistence.jaxb.xmlmodel.XmlRegistry.XmlElementDecl;
/**
* INTERNAL:
@@ -242,12 +235,17 @@ public class OXMObjectFactoryImpl implements JavaClass {
}
public boolean isSynthetic() {
- return false;
- }
-
- public JavaAnnotation getAnnotation(JavaClass arg0) {
- return null;
- }
+ return false;
+ }
+
+ @Override
+ public JavaClassInstanceOf instanceOf() {
+ return JavaClassInstanceOf.OXM_OBJECT_FACTORY_IMPL;
+ }
+
+ public JavaAnnotation getAnnotation(JavaClass arg0) {
+ return null;
+ }
public Collection<JavaAnnotation> getAnnotations() {
return null;
diff --git a/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/javamodel/reflection/JavaClassImpl.java b/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/javamodel/reflection/JavaClassImpl.java
index 453a331..c7df4ec 100644
--- a/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/javamodel/reflection/JavaClassImpl.java
+++ b/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/javamodel/reflection/JavaClassImpl.java
@@ -1,8 +1,8 @@
-/*******************************************************************************
- * Copyright (c) 1998, 2013 Oracle and/or its affiliates. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
- * which accompanies this distribution.
+/*******************************************************************************
+ * Copyright (c) 1998, 2014 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
@@ -11,26 +11,21 @@
* Oracle - initial API and implementation from Oracle TopLink
******************************************************************************/
package org.eclipse.persistence.jaxb.javamodel.reflection;
-
-import org.eclipse.persistence.exceptions.JAXBException;
-import org.eclipse.persistence.internal.security.PrivilegedAccessHelper;
-import org.eclipse.persistence.jaxb.javamodel.JavaAnnotation;
-import org.eclipse.persistence.jaxb.javamodel.JavaClass;
-import org.eclipse.persistence.jaxb.javamodel.JavaConstructor;
-import org.eclipse.persistence.jaxb.javamodel.JavaField;
-import org.eclipse.persistence.jaxb.javamodel.JavaMethod;
-import org.eclipse.persistence.jaxb.javamodel.JavaPackage;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.AnnotatedElement;
+
+import org.eclipse.persistence.exceptions.JAXBException;
+import org.eclipse.persistence.internal.security.PrivilegedAccessHelper;
+import org.eclipse.persistence.jaxb.javamodel.*;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.lang.reflect.TypeVariable;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.lang.reflect.TypeVariable;
import java.lang.reflect.WildcardType;
import java.util.ArrayList;
import java.util.Collection;
@@ -38,9 +33,9 @@ import java.util.List;
/**
* INTERNAL:
- * <p><b>Purpose:</b>A wrapper class for a JDK Class. This implementation
- * of the EclipseLink JAXB 2.X Java model simply makes reflective calls on the
- * underlying JDK object.
+ * <p><b>Purpose:</b>A wrapper class for a JDK Class. This implementation
+ * of the EclipseLink JAXB 2.X Java model simply makes reflective calls on the
+ * underlying JDK object.
*
* <p><b>Responsibilities:</b>
* <ul>
@@ -74,9 +69,9 @@ public class JavaClassImpl implements JavaClass {
this.javaModelImpl = javaModelImpl;
isMetadataComplete = false;
}
-
- public void setJavaModelImpl(JavaModelImpl javaModel) {
- this.javaModelImpl = javaModel;
+
+ public void setJavaModelImpl(JavaModelImpl javaModel) {
+ this.javaModelImpl = javaModel;
}
public Collection getActualTypeArguments() {
ArrayList<JavaClass> argCollection = new ArrayList<JavaClass>();
@@ -85,9 +80,9 @@ public class JavaClassImpl implements JavaClass {
for (Type type : params) {
if (type instanceof ParameterizedType) {
ParameterizedType pt = (ParameterizedType) type;
- argCollection.add(new JavaClassImpl(pt, (Class) pt.getRawType(), javaModelImpl));
- } else if(type instanceof WildcardType){
- Type[] upperTypes = ((WildcardType)type).getUpperBounds();
+ argCollection.add(new JavaClassImpl(pt, (Class) pt.getRawType(), javaModelImpl));
+ } else if(type instanceof WildcardType){
+ Type[] upperTypes = ((WildcardType)type).getUpperBounds();
if(upperTypes.length >0){
Type upperType = upperTypes[0];
if(upperType instanceof Class){
@@ -126,9 +121,9 @@ public class JavaClassImpl implements JavaClass {
if (arg0 != null && (!isMetadataComplete || arg0.getQualifiedName().equals(XML_REGISTRY_CLASS_NAME))) {
Class annotationClass = ((JavaClassImpl) arg0).getJavaClass();
if (javaModelImpl.getAnnotationHelper().isAnnotationPresent(getAnnotatedElement(), annotationClass)) {
- return new JavaAnnotationImpl(this.javaModelImpl.getAnnotationHelper().getAnnotation(getAnnotatedElement(), annotationClass));
- }
- }
+ return new JavaAnnotationImpl(this.javaModelImpl.getAnnotationHelper().getAnnotation(getAnnotatedElement(), annotationClass));
+ }
+ }
return null;
}
@@ -137,9 +132,9 @@ public class JavaClassImpl implements JavaClass {
if (!isMetadataComplete) {
Annotation[] annotations = javaModelImpl.getAnnotationHelper().getAnnotations(getAnnotatedElement());
for (Annotation annotation : annotations) {
- annotationCollection.add(new JavaAnnotationImpl(annotation));
- }
- }
+ annotationCollection.add(new JavaAnnotationImpl(annotation));
+ }
+ }
return annotationCollection;
}
@@ -148,15 +143,15 @@ public class JavaClassImpl implements JavaClass {
Class[] classes = jClass.getDeclaredClasses();
for (Class javaClass : classes) {
classCollection.add(javaModelImpl.getClass(javaClass));
- }
- return classCollection;
- }
+ }
+ return classCollection;
+ }
public JavaField getDeclaredField(String arg0) {
try {
- return getJavaField(jClass.getDeclaredField(arg0));
- } catch (NoSuchFieldException nsfe) {
- return null;
+ return getJavaField(jClass.getDeclaredField(arg0));
+ } catch (NoSuchFieldException nsfe) {
+ return null;
}
}
@@ -165,9 +160,9 @@ public class JavaClassImpl implements JavaClass {
Field[] fields = PrivilegedAccessHelper.getDeclaredFields(jClass);
for (Field field : fields) {
- field.setAccessible(true);
- fieldCollection.add(getJavaField(field));
- }
+ field.setAccessible(true);
+ fieldCollection.add(getJavaField(field));
+ }
return fieldCollection;
}
@@ -455,9 +450,9 @@ public class JavaClassImpl implements JavaClass {
return false;
}
if(!(arg0.getClass() == this.getClass())) {
- return false;
- }
- if(arg0.getName().equals("java.lang.Object")) {
+ return false;
+ }
+ if(arg0.getName().equals("java.lang.Object")) {
return false;
}
JavaClassImpl jClass = (JavaClassImpl)arg0;
@@ -465,9 +460,9 @@ public class JavaClassImpl implements JavaClass {
}
public boolean isEnum() {
- return jClass.isEnum();
- }
-
+ return jClass.isEnum();
+ }
+
public boolean isInterface() {
return jClass.isInterface();
}
@@ -509,12 +504,17 @@ public class JavaClassImpl implements JavaClass {
}
public boolean isSynthetic() {
- return jClass.isSynthetic();
- }
-
- public JavaClass getComponentType() {
- if(!isArray()) {
- return null;
+ return jClass.isSynthetic();
+ }
+
+ @Override
+ public JavaClassInstanceOf instanceOf() {
+ return JavaClassInstanceOf.JAVA_CLASS_IMPL;
+ }
+
+ public JavaClass getComponentType() {
+ if(!isArray()) {
+ return null;
}
return javaModelImpl.getClass(this.jClass.getComponentType());
}
@@ -547,9 +547,9 @@ public class JavaClassImpl implements JavaClass {
if (annotation.annotationType().equals(annotationClass)) {
return new JavaAnnotationImpl(annotation);
}
- }
- }
- return null;
+ }
+ }
+ return null;
}
public Collection getDeclaredAnnotations() {
@@ -557,9 +557,9 @@ public class JavaClassImpl implements JavaClass {
if (!isMetadataComplete) {
Annotation[] annotations = javaModelImpl.getAnnotationHelper().getDeclaredAnnotations(getAnnotatedElement());
for (Annotation annotation : annotations) {
- annotationCollection.add(new JavaAnnotationImpl(annotation));
- }
- }
+ annotationCollection.add(new JavaAnnotationImpl(annotation));
+ }
+ }
return annotationCollection;
}