cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r826002 - in /cxf/branches/2.2.x-fixes: ./ common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java distribution/src/main/release/samples/wsdl_first_dynamic_client/pom.xml
Date Fri, 16 Oct 2009 17:01:30 GMT
Author: dkulp
Date: Fri Oct 16 17:01:30 2009
New Revision: 826002

URL: http://svn.apache.org/viewvc?rev=826002&view=rev
Log:
Merged revisions 826001 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r826001 | dkulp | 2009-10-16 12:55:13 -0400 (Fri, 16 Oct 2009) | 3 lines
  
  [CXF-2339] Add jaxb-xjc to deps for dynamic_client pom.
  Update JAXBUtils to hunt for the tools.jar to create the SchemaCompiler
  things to help in the case where xjc isn't found
........

Modified:
    cxf/branches/2.2.x-fixes/   (props changed)
    cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java
    cxf/branches/2.2.x-fixes/distribution/src/main/release/samples/wsdl_first_dynamic_client/pom.xml

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java?rev=826002&r1=826001&r2=826002&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java
(original)
+++ cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java
Fri Oct 16 17:01:30 2009
@@ -31,6 +31,8 @@
 import java.lang.reflect.Type;
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLClassLoader;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -106,6 +108,7 @@
     private static final Map<String, String> BUILTIN_DATATYPES_MAP;
     private static final Map<String, Class<?>> HOLDER_TYPES_MAP;
     private static final Logger LOG = LogUtils.getL7dLogger(JAXBUtils.class, "CommonUtilityMessages");
+    private static ClassLoader jaxbXjcLoader;
 
     static {
         BUILTIN_DATATYPES_MAP = new HashMap<String, String>();        
@@ -501,6 +504,35 @@
         return cls;
     }
 
+    private static synchronized ClassLoader getXJCClassLoader() {
+        if (jaxbXjcLoader == null) {
+            try {
+                Class.forName("com.sun.tools.internal.xjc.api.XJC");
+                jaxbXjcLoader = ClassLoader.getSystemClassLoader();
+            } catch (Exception t2) {
+                //couldn't find either, probably cause tools.jar isn't on 
+                //the classpath.   Let's see if we can find the tools jar
+                String s = System.getProperty("java.home");
+                if (!StringUtils.isEmpty(s)) {
+                    File home = new File(s);
+                    File jar = new File(home, "lib/tools.jar");
+                    if (!jar.exists()) {
+                        jar = new File(home, "../lib/tools.jar");
+                    }
+                    if (jar.exists()) {
+                        try {
+                            jaxbXjcLoader = new URLClassLoader(new URL[] {jar.toURI().toURL()});
+                            Class.forName("com.sun.tools.internal.xjc.api.XJC", false, jaxbXjcLoader);
+                        } catch (Exception e) {
+                            jaxbXjcLoader = null;
+                        }
+                    }
+                }
+            } 
+        }
+        return jaxbXjcLoader;
+    }
+    
     public static JAXBContext createRIContext(Class<?> clss[], String defaultNS) throws
JAXBException {
         try {
             Class<?> cls;
@@ -512,7 +544,7 @@
                 }
             } catch (ClassNotFoundException e) {
                 // TODO Auto-generated catch block
-                cls = Class.forName("com.sun.xml.internal.bind.v2.ContextFactory");
+                cls = Class.forName("com.sun.xml.internal.bind.v2.ContextFactory", true,
getXJCClassLoader());
                 if (defaultNS != null) {
                     map.put("com.sun.xml.internal.bind.defaultNamespaceRemap", defaultNS);
                 }
@@ -557,10 +589,10 @@
                 cls = Class.forName("com.sun.xml.bind.api.JAXBRIContext");
             } catch (ClassNotFoundException e) {
                 // TODO Auto-generated catch block
-                cls = Class.forName("com.sun.xml.internal.bind.api.JAXBRIContext");
+                cls = Class.forName("com.sun.xml.internal.bind.api.JAXBRIContext", true,
getXJCClassLoader());
                 pkg = "com.sun.xml.internal.bind.";
             }
-            Class<?> refClass = Class.forName(pkg + "api.TypeReference");
+            Class<?> refClass = Class.forName(pkg + "api.TypeReference", true, getXJCClassLoader());
             Object ref = refClass.getConstructor(QName.class, 
                                                  Type.class, 
                                                  anns.getClass()).newInstance(qname, refcls,
anns);
@@ -613,8 +645,7 @@
                 cls = Class.forName("com.sun.tools.xjc.api.XJC");
                 sc = cls.getMethod("createSchemaCompiler").invoke(null);
             } catch (Throwable e) {
-                // TODO Auto-generated catch block
-                cls = Class.forName("com.sun.tools.internal.xjc.api.XJC");
+                cls = Class.forName("com.sun.tools.internal.xjc.api.XJC", true, getXJCClassLoader());
                 sc = cls.getMethod("createSchemaCompiler").invoke(null);
             }
             
@@ -632,7 +663,8 @@
                 cls = Class.forName("com.sun.codemodel.writer.FileCodeWriter");
             } catch (ClassNotFoundException e) {
                 // TODO Auto-generated catch block
-                cls = Class.forName("com.sun.codemodel.internal.writer.FileCodeWriter");
+                cls = Class.forName("com.sun.codemodel.internal.writer.FileCodeWriter",
+                                    true, getXJCClassLoader());
             }
             return cls.getConstructor(File.class).newInstance(f);
         } catch (Exception ex) {
@@ -976,7 +1008,21 @@
         cw.visitEnd();
 
         byte bts[] = cw.toByteArray();
+        
+        
+        Class<?> cls;
+        try {
+            cls = Class.forName("com.sun.xml.bind.api.JAXBRIContext");
+        } catch (ClassNotFoundException e) {
+            // TODO Auto-generated catch block
+            try {
+                cls = Class.forName("com.sun.xml.internal.bind.api.JAXBRIContext", true,
getXJCClassLoader());
+            } catch (ClassNotFoundException e1) {
+                cls = JAXBUtils.class;
+            }
+        }
+        
         return helper.loadClass(className,
-                                JAXBUtils.class, bts);
+                                cls, bts);
     }
 }

Modified: cxf/branches/2.2.x-fixes/distribution/src/main/release/samples/wsdl_first_dynamic_client/pom.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/distribution/src/main/release/samples/wsdl_first_dynamic_client/pom.xml?rev=826002&r1=826001&r2=826002&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/distribution/src/main/release/samples/wsdl_first_dynamic_client/pom.xml
(original)
+++ cxf/branches/2.2.x-fixes/distribution/src/main/release/samples/wsdl_first_dynamic_client/pom.xml
Fri Oct 16 17:01:30 2009
@@ -168,5 +168,10 @@
             <artifactId>cxf-rt-transports-http-jetty</artifactId>
             <version>${cxf.version}</version>
         </dependency>
+        <dependency>
+            <groupId>com.sun.xml.bind</groupId>
+            <artifactId>jaxb-xjc</artifactId>
+            <version>2.1.12</version>
+        </dependency>
     </dependencies>
 </project>



Mime
View raw message