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 2010/01/05 03:19:51 UTC

svn commit: r895861 - in /cxf/branches/2.2.x-fixes: ./ common/common/src/main/java/org/apache/cxf/staxutils/ tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/ tools/wsdlto/frontend/jaxws/src/main/java/org/apache/...

Author: dkulp
Date: Tue Jan  5 02:19:41 2010
New Revision: 895861

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

........
  r895810 | dkulp | 2010-01-04 17:39:28 -0500 (Mon, 04 Jan 2010) | 4 lines
  
  [CXF-2135, CXF-2600] Add autoNameResolution suggestion to appropriate
  JAXB error message.   If jaxb binding file doesn't have a schemaLocation
  element, attempt to find schemas that would match it and create a
  schemaLocation attribute for it.
........

Modified:
    cxf/branches/2.2.x-fixes/   (props changed)
    cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
    cxf/branches/2.2.x-fixes/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBBindErrorListener.java
    cxf/branches/2.2.x-fixes/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java
    cxf/branches/2.2.x-fixes/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/customization/CustomizationParser.java
    cxf/branches/2.2.x-fixes/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenBugTest.java

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/staxutils/StaxUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java?rev=895861&r1=895860&r2=895861&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java (original)
+++ cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java Tue Jan  5 02:19:41 2010
@@ -24,6 +24,7 @@
 import java.io.Reader;
 import java.io.StringWriter;
 import java.io.Writer;
+import java.net.URL;
 import java.util.Iterator;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.LinkedBlockingQueue;
@@ -991,6 +992,15 @@
             StreamSource ss = new StreamSource(src.getCharacterStream(), sysId);
             ss.setPublicId(pubId);
             return createXMLStreamReader(ss);
+        } else {
+            try {
+                URL url = new URL(sysId);
+                StreamSource ss = new StreamSource(url.openStream(), sysId);
+                ss.setPublicId(pubId);
+                return createXMLStreamReader(ss);
+            } catch (Exception ex) {
+                //ignore - not a valid URL
+            }
         }
         throw new IllegalArgumentException("InputSource must have a ByteStream or CharacterStream");
     }

Modified: cxf/branches/2.2.x-fixes/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBBindErrorListener.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBBindErrorListener.java?rev=895861&r1=895860&r2=895861&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBBindErrorListener.java (original)
+++ cxf/branches/2.2.x-fixes/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBBindErrorListener.java Tue Jan  5 02:19:41 2010
@@ -38,7 +38,7 @@
                                     + " of schema " + exception.getSystemId(), exception);
            
         }
-        throw new ToolException(prefix + exception.getLocalizedMessage(), exception);
+        throw new ToolException(prefix + mapMessage(exception.getLocalizedMessage()), exception);
 
     }
 
@@ -60,4 +60,16 @@
                                + " in schema " + exception.getSystemId());
         }
     }
+    
+    private String mapMessage(String msg) {
+        //this is kind of a hack to map the JAXB error message into
+        //something more appropriate for CXF.  If JAXB changes their
+        //error messages, this will break
+        if (msg.contains("Use a class customization to resolve")
+            && msg.contains("with the same name")) {
+            int idx = msg.lastIndexOf("class customization") + 19;
+            msg = msg.substring(0, idx) + " or the -autoNameResolution option" + msg.substring(idx);
+        }
+        return msg;
+    }
 }

Modified: cxf/branches/2.2.x-fixes/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java?rev=895861&r1=895860&r2=895861&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java (original)
+++ cxf/branches/2.2.x-fixes/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java Tue Jan  5 02:19:41 2010
@@ -19,6 +19,7 @@
 package org.apache.cxf.tools.wsdlto.databinding.jaxb;
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.Writer;
@@ -43,6 +44,9 @@
 import javax.xml.stream.util.StreamReaderDelegate;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.validation.SchemaFactory;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpression;
 
 
 import org.w3c.dom.Attr;
@@ -51,6 +55,7 @@
 import org.w3c.dom.Element;
 import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
 
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
@@ -81,15 +86,19 @@
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.helpers.FileUtils;
+import org.apache.cxf.helpers.XMLUtils;
+import org.apache.cxf.helpers.XPathUtils;
 import org.apache.cxf.service.model.SchemaInfo;
 import org.apache.cxf.service.model.ServiceInfo;
 import org.apache.cxf.staxutils.StaxUtils;
+import org.apache.cxf.staxutils.W3CNamespaceContext;
 import org.apache.cxf.tools.common.ToolConstants;
 import org.apache.cxf.tools.common.ToolContext;
 import org.apache.cxf.tools.common.ToolException;
 import org.apache.cxf.tools.common.model.DefaultValueWriter;
 import org.apache.cxf.tools.util.ClassCollector;
 import org.apache.cxf.tools.util.JAXBUtils;
+import org.apache.cxf.tools.util.URIParserUtil;
 import org.apache.cxf.tools.wsdlto.core.DataBindingProfile;
 import org.apache.cxf.tools.wsdlto.core.DefaultValueProvider;
 import org.apache.cxf.tools.wsdlto.core.RandomValueProvider;
@@ -331,9 +340,7 @@
         }
         
         addSchemas(opts, schemaCompiler, schemas);
-        for (InputSource binding : jaxbBindings) {
-            opts.addBindFile(binding);
-        }
+        addBindingFiles(opts, jaxbBindings, schemas);
 
                        
         for (String ns : context.getNamespacePackageMap().keySet()) {
@@ -372,7 +379,66 @@
         }
         initialized = true;
     }
-
+    private void addBindingFiles(Options opts, List<InputSource> jaxbBindings, SchemaCollection schemas) {
+        for (InputSource binding : jaxbBindings) {
+            XMLStreamReader r = StaxUtils.createXMLStreamReader(binding);
+            try {
+                StaxUtils.toNextTag(r);
+                String s = r.getAttributeValue(null, "schemaLocation");
+                if (StringUtils.isEmpty(s)) {
+                    Document d = StaxUtils.read(r);
+                    XPath p = XPathUtils.getFactory().newXPath();
+                    p.setNamespaceContext(new W3CNamespaceContext(d.getDocumentElement()));
+                    XPathExpression xpe = p.compile(d.getDocumentElement().getAttribute("node"));
+                    for (XmlSchema schema : schemas.getXmlSchemas()) {
+                        if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(schema.getTargetNamespace())) {
+                            continue;
+                        }
+                        Object src = getSchemaNode(schema, schemas);
+                        NodeList nodes = (NodeList)xpe.evaluate(src, XPathConstants.NODESET);
+                        if (nodes.getLength() > 0) {
+                            String key = schema.getSourceURI();
+                            binding = convertToTmpInputSource(d.getDocumentElement(), key);
+                            opts.addBindFile(binding);
+                            binding = null;
+                        }
+                    }
+                } 
+            } catch (Exception ex) {
+                //ignore, just pass to jaxb
+            } finally {
+                try {
+                    r.close();
+                } catch (Exception ex) {
+                    //ignore
+                }
+            }
+            if (binding != null) {
+                opts.addBindFile(binding);
+            }
+        }
+    }
+    private Object getSchemaNode(XmlSchema schema, SchemaCollection schemaCollection) {
+        XmlSchemaSerializer xser = new XmlSchemaSerializer();
+        xser.setExtReg(schemaCollection.getExtReg());
+        Document[] docs;
+        try {
+            docs = xser.serializeSchema(schema, false);
+        } catch (XmlSchemaSerializerException e) {
+            throw new RuntimeException(e);
+        }
+        return docs[0].getDocumentElement();
+    }
+    private InputSource convertToTmpInputSource(Element ele, String schemaLoc) throws Exception {
+        InputSource result = null;
+        ele.setAttribute("schemaLocation", schemaLoc);
+        File tmpFile = FileUtils.createTempFile("jaxbbinding", ".xml");
+        XMLUtils.writeTo(ele, new FileOutputStream(tmpFile));
+        result = new InputSource(URIParserUtil.getAbsoluteURI(tmpFile.getAbsolutePath()));
+        tmpFile.deleteOnExit();
+        return result;
+    }
+    
     @SuppressWarnings("unchecked")
     private void addSchemas(Options opts, 
                             SchemaCompiler schemaCompiler,

Modified: cxf/branches/2.2.x-fixes/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/customization/CustomizationParser.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/customization/CustomizationParser.java?rev=895861&r1=895860&r2=895861&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/customization/CustomizationParser.java (original)
+++ cxf/branches/2.2.x-fixes/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/customization/CustomizationParser.java Tue Jan  5 02:19:41 2010
@@ -379,9 +379,6 @@
             }
 
         }
-
-        
-        
         Element element = DOMUtils.getFirstElement(bindings);
         while (element != null) {
             if (element.getNamespaceURI().equals(ToolConstants.JAXWS_BINDINGS.getNamespaceURI())) {
@@ -389,9 +386,6 @@
             }
             element = DOMUtils.getNextElement(element);
         }
-        
-        
-
         Node cloneNode = ProcessorUtil.cloneNode(node.getOwnerDocument(), bindings, true);
         Node firstChild = DOMUtils.getChild(node, "jaxws:bindings");
         if (firstChild == null && cloneNode.getNodeName().indexOf("bindings") == -1) {

Modified: cxf/branches/2.2.x-fixes/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenBugTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenBugTest.java?rev=895861&r1=895860&r2=895861&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenBugTest.java (original)
+++ cxf/branches/2.2.x-fixes/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenBugTest.java Tue Jan  5 02:19:41 2010
@@ -828,7 +828,6 @@
     }
     
     // See CXF-2135
-    @org.junit.Ignore
     @Test
     public void testReuseJaxbBindingFile1() throws Exception {
         env.put(ToolConstants.CFG_WSDLURL,