You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2009/10/16 19:10:46 UTC
svn commit: r826008 - in /cxf/branches/2.1.x-fixes: ./
common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java
distribution/src/main/release/samples/wsdl_first_dynamic_client/pom.xml
Author: dkulp
Date: Fri Oct 16 17:10:46 2009
New Revision: 826008
URL: http://svn.apache.org/viewvc?rev=826008&view=rev
Log:
Merged revisions 826002 via svnmerge from
https://svn.apache.org/repos/asf/cxf/branches/2.2.x-fixes
................
r826002 | dkulp | 2009-10-16 13:01:30 -0400 (Fri, 16 Oct 2009) | 11 lines
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.1.x-fixes/ (props changed)
cxf/branches/2.1.x-fixes/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java
cxf/branches/2.1.x-fixes/distribution/src/main/release/samples/wsdl_first_dynamic_client/pom.xml
Propchange: cxf/branches/2.1.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: cxf/branches/2.1.x-fixes/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java?rev=826008&r1=826007&r2=826008&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java (original)
+++ cxf/branches/2.1.x-fixes/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java Fri Oct 16 17:10:46 2009
@@ -29,7 +29,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.Iterator;
@@ -99,6 +100,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>();
@@ -494,6 +496,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;
@@ -505,7 +536,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);
}
@@ -550,10 +581,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);
@@ -606,8 +637,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);
}
@@ -624,7 +654,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) {
@@ -826,7 +857,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.1.x-fixes/distribution/src/main/release/samples/wsdl_first_dynamic_client/pom.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/distribution/src/main/release/samples/wsdl_first_dynamic_client/pom.xml?rev=826008&r1=826007&r2=826008&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/distribution/src/main/release/samples/wsdl_first_dynamic_client/pom.xml (original)
+++ cxf/branches/2.1.x-fixes/distribution/src/main/release/samples/wsdl_first_dynamic_client/pom.xml Fri Oct 16 17:10:46 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>