cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1502369 - in /cxf/trunk: api/src/main/java/org/apache/cxf/common/classloader/JAXBClassLoaderUtils.java rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextInitializer.java
Date Thu, 11 Jul 2013 21:21:25 GMT
Author: dkulp
Date: Thu Jul 11 21:21:25 2013
New Revision: 1502369

URL: http://svn.apache.org/r1502369
Log:
Move some code to a private method in the only place it's called

Removed:
    cxf/trunk/api/src/main/java/org/apache/cxf/common/classloader/JAXBClassLoaderUtils.java
Modified:
    cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextInitializer.java

Modified: cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextInitializer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextInitializer.java?rev=1502369&r1=1502368&r2=1502369&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextInitializer.java
(original)
+++ cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextInitializer.java
Thu Jul 11 21:21:25 2013
@@ -41,8 +41,9 @@ import javax.xml.bind.annotation.XmlTran
 import javax.xml.bind.annotation.XmlType;
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters;
+import javax.xml.namespace.QName;
 
-import org.apache.cxf.common.classloader.JAXBClassLoaderUtils;
+import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.jaxb.JAXBUtils;
 import org.apache.cxf.common.util.ReflectionUtil;
 import org.apache.cxf.common.util.StringUtils;
@@ -164,7 +165,7 @@ class JAXBContextInitializer extends Ser
                 && clazz.getAnnotation(XmlRootElement.class) == null
                 && clazz.getAnnotation(XmlType.class) != null
                 && StringUtils.isEmpty(clazz.getAnnotation(XmlType.class).name()))
{
-                Object ref = JAXBClassLoaderUtils.createTypeReference(part.getName(), clazz);
+                Object ref = createTypeReference(part.getName(), clazz);
                 if (ref != null) {
                     typeReferences.add(ref);
                 }
@@ -446,4 +447,38 @@ class JAXBContextInitializer extends Ser
         }
         return false;
     }
+    
+    /**
+     * The TypeReference class is a sun specific class that is found in two different
+     * locations depending on environment. In IBM JDK the class is not available at all.
+     * So we have to load it at runtime.
+     * 
+     * @param n
+     * @param cls
+     * @return initiated TypeReference
+     */
+    private static Object createTypeReference(QName n, Class<?> cls) {
+        Class<?> refClass = null;
+        try {
+            refClass = ClassLoaderUtils.loadClass("com.sun.xml.bind.api.TypeReference", 
+                                                  JAXBContextInitializer.class);
+        } catch (Throwable ex) {
+            try {
+                refClass = ClassLoaderUtils.loadClass("com.sun.xml.internal.bind.api.TypeReference",
+                                                      JAXBContextInitializer.class);
+            } catch (Throwable ex2) {
+                //ignore
+            }
+        }
+        if (refClass != null) {
+            try {
+                return refClass.getConstructor(QName.class, Type.class, new Annotation[0].getClass())
+                    .newInstance(n, cls, new Annotation[0]);
+            } catch (Throwable e) {
+                //ignore
+            }
+        }
+        return null;
+    }
+    
 }
\ No newline at end of file



Mime
View raw message