cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r1243102 - in /cxf/trunk: api/pom.xml api/src/main/java/org/apache/cxf/common/classloader/JAXBClassLoaderUtils.java rt/core/pom.xml rt/databinding/jaxb/pom.xml rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextInitializer.java
Date Sat, 11 Feb 2012 17:08:52 GMT
Author: cschneider
Date: Sat Feb 11 17:08:52 2012
New Revision: 1243102

URL: http://svn.apache.org/viewvc?rev=1243102&view=rev
Log:
CXF-4101 Minimize use of dynamic imports move special jaxb classloading to api

Added:
    cxf/trunk/api/src/main/java/org/apache/cxf/common/classloader/JAXBClassLoaderUtils.java
Modified:
    cxf/trunk/api/pom.xml
    cxf/trunk/rt/core/pom.xml
    cxf/trunk/rt/databinding/jaxb/pom.xml
    cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextInitializer.java

Modified: cxf/trunk/api/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/api/pom.xml?rev=1243102&r1=1243101&r2=1243102&view=diff
==============================================================================
--- cxf/trunk/api/pom.xml (original)
+++ cxf/trunk/api/pom.xml Sat Feb 11 17:08:52 2012
@@ -45,18 +45,14 @@
             javax.annotation;version="${cxf.osgi.javax.annotation.version}",
             javax.xml.bind*;version="${cxf.osgi.javax.bind.version}",
             javax.xml.stream*;version="${cxf.osgi.javax.stream.version}",
+            com.sun.xml.bind.api;resolution:=optional,
+            com.sun.xml.bind.api.impl;resolution:=optional,
+            com.sun.xml.internal.bind.api;resolution:=optional,
+            com.sun.xml.internal.bind.api.impl;resolution:=optional,
         </cxf.osgi.import>
         <cxf.osgi.dynamic.import>
-            com.sun.xml.bind.api,
-            com.sun.xml.bind.api.*,
-            com.sun.xml.internal.bind.api,
-            com.sun.xml.internal.bind.api.*,
-            com.ctc.wstx.*,
-            org.apache.commons.logging.*,
-            org.slf4j.*,
-            org.slf4j.impl.*,
+            org.apache.cxf.bus
         </cxf.osgi.dynamic.import>
-        <cxf.osgi.dynamic.import>org.apache.cxf.bus</cxf.osgi.dynamic.import>
     </properties>
 
     <dependencies>

Added: cxf/trunk/api/src/main/java/org/apache/cxf/common/classloader/JAXBClassLoaderUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/common/classloader/JAXBClassLoaderUtils.java?rev=1243102&view=auto
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/common/classloader/JAXBClassLoaderUtils.java
(added)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/common/classloader/JAXBClassLoaderUtils.java
Sat Feb 11 17:08:52 2012
@@ -0,0 +1,63 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.common.classloader;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.xml.namespace.QName;
+
+public final class JAXBClassLoaderUtils {
+
+    private JAXBClassLoaderUtils() {
+    }
+    
+    /**
+     * 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
+     */
+    public static Object createTypeReference(QName n, Class<?> cls) {
+        Class<?> refClass = null;
+        try {
+            refClass = ClassLoaderUtils.loadClass("com.sun.xml.bind.api.TypeReference", 
+                                                  JAXBClassLoaderUtils.class);
+        } catch (Throwable ex) {
+            try {
+                refClass = ClassLoaderUtils.loadClass("com.sun.xml.internal.bind.api.TypeReference",
+                                                      JAXBClassLoaderUtils.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;
+    }
+}

Modified: cxf/trunk/rt/core/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/pom.xml?rev=1243102&r1=1243101&r2=1243102&view=diff
==============================================================================
--- cxf/trunk/rt/core/pom.xml (original)
+++ cxf/trunk/rt/core/pom.xml Sat Feb 11 17:08:52 2012
@@ -45,9 +45,11 @@
             javax.xml.stream*;version="${cxf.osgi.javax.stream.version}"
         </cxf.osgi.import>
         <cxf.osgi.export>
-            '=META-INF.cxf',
-            org.apache.cxf.*;-split-package:=first,
+            META-INF.cxf, *
         </cxf.osgi.export>
+        <cxf.osgi.dynamic.import>
+            com.ctc.wstx.*
+        </cxf.osgi.dynamic.import>
     </properties>
 
     <dependencies>

Modified: cxf/trunk/rt/databinding/jaxb/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/pom.xml?rev=1243102&r1=1243101&r2=1243102&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/pom.xml (original)
+++ cxf/trunk/rt/databinding/jaxb/pom.xml Sat Feb 11 17:08:52 2012
@@ -37,12 +37,6 @@
             javax.xml.stream*;version="${cxf.osgi.javax.stream.version}",
             org.objectweb.asm*;resolution:=optional;version="${cxf.osgi.asm.version}",
         </cxf.osgi.import>
-        <cxf.osgi.dynamic.import>
-            com.sun.xml.bind.api,
-            com.sun.xml.bind.api.*,
-            com.sun.xml.internal.bind.api,
-            com.sun.xml.internal.bind.api.*,
-        </cxf.osgi.dynamic.import>
     </properties>
     <build>
         <plugins>

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=1243102&r1=1243101&r2=1243102&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
Sat Feb 11 17:08:52 2012
@@ -41,9 +41,8 @@ import javax.xml.bind.annotation.XmlTran
 import javax.xml.bind.annotation.XmlType;
 import javax.xml.bind.annotation.adapters.XmlAdapter;
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
-import javax.xml.namespace.QName;
 
-import org.apache.cxf.common.classloader.ClassLoaderUtils;
+import org.apache.cxf.common.classloader.JAXBClassLoaderUtils;
 import org.apache.cxf.common.jaxb.JAXBUtils;
 import org.apache.cxf.common.util.ReflectionUtil;
 import org.apache.cxf.common.util.StringUtils;
@@ -164,35 +163,15 @@ class JAXBContextInitializer extends Ser
                 && clazz.getAnnotation(XmlRootElement.class) == null
                 && clazz.getAnnotation(XmlType.class) != null
                 && StringUtils.isEmpty(clazz.getAnnotation(XmlType.class).name()))
{
-                createTypeReference(part.getName(), clazz);
+                Object ref = JAXBClassLoaderUtils.createTypeReference(part.getName(), clazz);
+                if (ref != null) {
+                    typeReferences.add(ref);
+                }
             }
             
             addClass(clazz);
         }
     }
-    
-    private void createTypeReference(QName n, Class<?> cls) {
-        Class<?> refClass = null;
-        try {
-            refClass = ClassLoaderUtils.loadClass("com.sun.xml.bind.api.TypeReference", this.getClass());
-        } catch (Throwable ex) {
-            try {
-                refClass = ClassLoaderUtils.loadClass("com.sun.xml.internal.bind.api.TypeReference",
-                                                      this.getClass());
-            } catch (Throwable ex2) {
-                //ignore
-            }
-        }
-        if (refClass != null) {
-            try {
-                Object o =  refClass.getConstructor(QName.class, Type.class, new Annotation[0].getClass())
-                    .newInstance(n, cls, new Annotation[0]);
-                typeReferences.add(o);
-            } catch (Throwable e) {
-                //ignore
-            }
-        }
-    }
 
     private void checkForAdapter(Class<?> clazz, Annotation[] anns) {
         if (anns != null) {



Mime
View raw message