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 2012/10/23 21:50:51 UTC

svn commit: r1401419 - /cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java

Author: dkulp
Date: Tue Oct 23 19:50:50 2012
New Revision: 1401419

URL: http://svn.apache.org/viewvc?rev=1401419&view=rev
Log:
[CXF-4564] Try to work around a bug in JAXB 2.2 that causes problems if the initial source location is a jar: URL but imports/includes are then absolute URL's.  Not a complete workaround, but at least helps SOME cases.

Modified:
    cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java

Modified: cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java?rev=1401419&r1=1401418&r2=1401419&view=diff
==============================================================================
--- cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java (original)
+++ cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java Tue Oct 23 19:50:50 2012
@@ -65,6 +65,7 @@ import org.xml.sax.Attributes;
 import org.xml.sax.InputSource;
 import org.xml.sax.Locator;
 import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
 import org.xml.sax.helpers.XMLFilterImpl;
 
 import com.sun.codemodel.ClassType;
@@ -79,6 +80,7 @@ import com.sun.tools.xjc.Driver;
 import com.sun.tools.xjc.ErrorReceiver;
 import com.sun.tools.xjc.Options;
 import com.sun.tools.xjc.Plugin;
+import com.sun.tools.xjc.XJCListener;
 import com.sun.tools.xjc.api.Mapping;
 import com.sun.tools.xjc.api.Property;
 import com.sun.tools.xjc.api.S2JJAXBModel;
@@ -125,8 +127,46 @@ import org.apache.ws.commons.schema.XmlS
 import org.apache.ws.commons.schema.XmlSchemaSerializer.XmlSchemaSerializerException;
 
 public class JAXBDataBinding implements DataBindingProfile {
+    static final String XJCVERSION;
+    static {
+        
+        VersionDetectListener listener = new VersionDetectListener();
+        try {
+            Driver.run(new String[] {"-version"}, listener);
+        } catch (BadCommandLineException e) {
+            //
+        }
+        XJCVERSION = listener.getVersion();
+    }
+    
+    static final class VersionDetectListener extends XJCListener {
+        private String s = "2.1";
+        VersionDetectListener() {
+        }
+        public String getVersion() {
+            return s;
+        }
+        public void error(SAXParseException exception) {
+        }
+
+        public void fatalError(SAXParseException exception) {
+        }
 
+        public void warning(SAXParseException exception) {
+        }
 
+        public void info(SAXParseException exception) {
+        }
+
+        public void message(String msg) {
+            if (msg.contains(" ")) {
+                msg = msg.substring(msg.indexOf(' ')).trim();
+            }
+            if (!StringUtils.isEmpty(msg)) {
+                s = msg;
+            }
+        }
+    }
     public class LocationFilterReader extends StreamReaderDelegate {
         boolean isImport;
         boolean isInclude;
@@ -198,6 +238,11 @@ public class JAXBDataBinding implements 
         }
 
         private String mapSchemaLocation(String target) {
+            //See http://java.net/jira/browse/JAXB-925
+            if (this.getLocation().getSystemId().startsWith("jar:") 
+                && XJCVERSION.startsWith("2.2")) {
+                return target;
+            }
             return JAXBDataBinding.mapSchemaLocation(target, this.getLocation().getSystemId(), catalog);
         }
 
@@ -459,6 +504,11 @@ public class JAXBDataBinding implements 
                     || "include".equals(localName))) {
                 String s = atts.getValue("schemaLocation");
                 if (!StringUtils.isEmpty(s)) {
+                    //See http://java.net/jira/browse/JAXB-925
+                    if (locator.getSystemId().startsWith("jar:") 
+                        && XJCVERSION.startsWith("2.2")) {
+                        return s;
+                    }
                     s = JAXBDataBinding.mapSchemaLocation(s, locator.getSystemId(), catalog);
                 }
                 return s;