cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r761727 - in /cxf/trunk: common/common/src/main/java/org/apache/cxf/common/ common/common/src/main/java/org/apache/cxf/staxutils/ tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/
Date Fri, 03 Apr 2009 16:48:13 GMT
Author: dkulp
Date: Fri Apr  3 16:48:12 2009
New Revision: 761727

URL: http://svn.apache.org/viewvc?rev=761727&view=rev
Log:
Strip the schemaLocation from imports for the "file" based things as well.  Make sure the
line numbers are actually propogated up.

Modified:
    cxf/trunk/common/common/src/main/java/org/apache/cxf/common/WSDLConstants.java
    cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
    cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBBindErrorListener.java
    cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java

Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/common/WSDLConstants.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/WSDLConstants.java?rev=761727&r1=761726&r2=761727&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/common/WSDLConstants.java (original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/common/WSDLConstants.java Fri Apr
 3 16:48:12 2009
@@ -35,6 +35,8 @@
     public static final String NS_SCHEMA_XSD = "http://www.w3.org/2001/XMLSchema";
 
     public static final QName QNAME_SCHEMA = new QName(NS_SCHEMA_XSD, "schema");
+    public static final QName QNAME_SCHEMA_IMPORT = new QName(NS_SCHEMA_XSD, "import");
+    public static final QName QNAME_SCHEMA_INCLUDE = new QName(NS_SCHEMA_XSD, "include");
 
     // XML Schema instance
     public static final String NP_SCHEMA_XSI = "xsi";

Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java?rev=761727&r1=761726&r2=761727&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java (original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java Fri Apr
 3 16:48:12 2009
@@ -853,6 +853,13 @@
             throw new RuntimeException("Couldn't parse stream.", e);
         }
     }
+    public static XMLStreamReader createXMLStreamReader(String systemId, InputStream in)
{
+        try {
+            return getXMLInputFactory().createXMLStreamReader(systemId, in);
+        } catch (XMLStreamException e) {
+            throw new RuntimeException("Couldn't parse stream.", e);
+        }
+    }
     
     public static XMLStreamReader createXMLStreamReader(Element el) {
         return new W3CDOMStreamReader(el);

Modified: cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBBindErrorListener.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBBindErrorListener.java?rev=761727&r1=761726&r2=761727&view=diff
==============================================================================
--- cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBBindErrorListener.java
(original)
+++ cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBBindErrorListener.java
Fri Apr  3 16:48:12 2009
@@ -31,6 +31,13 @@
     }
 
     public void error(org.xml.sax.SAXParseException exception) {
+        if (exception.getLineNumber() > 0) {
+            throw new ToolException(prefix + exception.getLocalizedMessage() 
+                                    + " at line " + exception.getLineNumber()
+                                    + " column " + exception.getColumnNumber()
+                                    + " of schema " + exception.getSystemId(), exception);
+           
+        }
         throw new ToolException(prefix + exception.getLocalizedMessage(), exception);
 
     }

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=761727&r1=761726&r2=761727&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
Fri Apr  3 16:48:12 2009
@@ -18,10 +18,12 @@
  */
 package org.apache.cxf.tools.wsdlto.databinding.jaxb;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.Writer;
 import java.lang.reflect.Field;
+import java.net.URI;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -36,6 +38,9 @@
 
 import javax.xml.XMLConstants;
 import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.util.StreamReaderDelegate;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.validation.SchemaFactory;
 
@@ -65,6 +70,7 @@
 import com.sun.tools.xjc.api.TypeAndAnnotation;
 import com.sun.tools.xjc.api.XJC;
 
+import org.apache.cxf.common.WSDLConstants;
 import org.apache.cxf.common.i18n.Message;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.StringUtils;
@@ -74,6 +80,7 @@
 import org.apache.cxf.helpers.FileUtils;
 import org.apache.cxf.service.model.SchemaInfo;
 import org.apache.cxf.service.model.ServiceInfo;
+import org.apache.cxf.staxutils.StaxUtils;
 import org.apache.cxf.tools.common.ToolConstants;
 import org.apache.cxf.tools.common.ToolContext;
 import org.apache.cxf.tools.common.ToolException;
@@ -88,6 +95,102 @@
 import org.apache.ws.commons.schema.XmlSchemaSerializer.XmlSchemaSerializerException;
 
 public class JAXBDataBinding implements DataBindingProfile {
+
+
+    public class LocationFilterReader extends StreamReaderDelegate implements XMLStreamReader
{
+        boolean isImport;
+        int locIdx;
+        LocationFilterReader(XMLStreamReader read) {
+            super(read);
+        }
+        public int next() throws XMLStreamException {
+            int i = super.next();
+            if (i == XMLStreamReader.START_ELEMENT) {
+                isImport = super.getName().equals(WSDLConstants.QNAME_SCHEMA_IMPORT);
+                if (isImport) {
+                    findLocation();
+                }
+            } else {
+                isImport = false;
+                locIdx = -1;
+            }
+            return i;
+        }
+
+        public int nextTag() throws XMLStreamException {
+            int i = super.nextTag();
+            if (i == XMLStreamReader.START_ELEMENT) {
+                isImport = super.getName().equals(WSDLConstants.QNAME_SCHEMA_IMPORT);
+                if (isImport) {
+                    findLocation();
+                }
+            } else {
+                isImport = false;
+                locIdx = -1;
+            }
+            return i;
+        }
+        private void findLocation() {
+            locIdx = -1;
+            for (int x = super.getAttributeCount(); x > 0; --x) {
+                String nm = super.getAttributeLocalName(x - 1);
+                if ("schemaLocation".equals(nm)) {
+                    locIdx = x - 1;
+                }
+            }
+        }
+        public String getAttributeValue(String namespaceURI, String localName) {
+            return super.getAttributeValue(namespaceURI, localName);
+        }
+    
+        public int getAttributeCount() {
+            int i = super.getAttributeCount();
+            if (locIdx != -1) {
+                --i;
+            }
+            return i;
+        }
+        private int mapIdx(int index) {
+            if (locIdx != -1
+                && index >= locIdx) {
+                ++index;
+            }
+            return index;
+        }
+    
+        public QName getAttributeName(int index) {
+            return super.getAttributeName(mapIdx(index));
+        }
+    
+        public String getAttributePrefix(int index) {
+            return super.getAttributePrefix(mapIdx(index));
+        }
+    
+        public String getAttributeNamespace(int index) {
+            return super.getAttributeNamespace(mapIdx(index));
+        }
+    
+        public String getAttributeLocalName(int index) {
+            return super.getAttributeLocalName(mapIdx(index));
+        }
+    
+        public String getAttributeType(int index) {
+            return super.getAttributeType(mapIdx(index));
+        }
+    
+        public String getAttributeValue(int index) {
+            return super.getAttributeValue(mapIdx(index));
+        }
+    
+        public boolean isAttributeSpecified(int index) {
+            return super.isAttributeSpecified(mapIdx(index));
+        }
+
+        
+
+    }
+
+
     private static final Logger LOG = LogUtils.getL7dLogger(JAXBDataBinding.class);
     
     private static final Set<String> DEFAULT_TYPE_MAP = new HashSet<String>();
@@ -147,7 +250,7 @@
         
         Options opts = null;
         opts = getOptions(schemaCompiler);
-        //schemaCompiler.setEntityResolver(entityResolver)
+        
         List<String> args = new ArrayList<String>();
         
         if (context.get(ToolConstants.CFG_NO_ADDRESS_BINDING) == null) {
@@ -256,8 +359,29 @@
                     continue;
                 }
                 ids.add(key);
+            }
+        }
                 
-                Element ele = sci.getElement();
+        for (XmlSchema schema : schemaCollection.getXmlSchemas()) {
+            if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(schema.getTargetNamespace())) {
+                continue;
+            }
+            String key = schema.getSourceURI();
+            if (ids.contains(key)) {
+                continue;
+            }
+            
+            if (!key.startsWith("file:")) {
+                XmlSchemaSerializer xser = new XmlSchemaSerializer();
+                xser.setExtReg(schemaCollection.getExtReg());
+                Document[] docs;
+                try {
+                    docs = xser.serializeSchema(schema, false);
+                } catch (XmlSchemaSerializerException e) {
+                    throw new RuntimeException(e);
+                }
+                Element ele = docs[0].getDocumentElement();
+    
                 ele = removeImportElement(ele);
                 if (context.get(ToolConstants.CFG_VALIDATE_WSDL) != null) {
                     validateSchema(ele);
@@ -278,23 +402,30 @@
             if (ids.contains(key)) {
                 continue;
             }
-            
             if (key.startsWith("file:")) {
-                InputSource is = new InputSource(key);
-                //key = key.replaceFirst("#types[0-9]+$", "");
-                opts.addGrammar(is);
-                schemaCompiler.parseSchema(is);
-            } else {
-                XmlSchemaSerializer xser = new XmlSchemaSerializer();
-                xser.setExtReg(schemaCollection.getExtReg());
-                Document[] docs;
                 try {
-                    docs = xser.serializeSchema(schema, false);
-                } catch (XmlSchemaSerializerException e) {
-                    throw new RuntimeException(e);
+                    FileInputStream fin = new FileInputStream(new File(new URI(key)));
+                    XMLStreamReader reader = StaxUtils.createXMLStreamReader(key, fin);
+                    reader = new LocationFilterReader(reader);
+                    InputSource is = new InputSource(key);
+                    opts.addGrammar(is);
+                    schemaCompiler.parseSchema(key, reader);
+                } catch (RuntimeException ex) {
+                    throw ex;
+                } catch (Exception ex) {
+                    throw new RuntimeException(ex);
                 }
-                Element ele = docs[0].getDocumentElement();
-    
+            }
+        }
+        ids.clear();
+        for (ServiceInfo si : serviceList) {
+            for (SchemaInfo sci : si.getSchemas()) {
+                String key = sci.getSystemId();
+                if (ids.contains(key)) {
+                    continue;
+                }
+                ids.add(key);
+                Element ele = sci.getElement();
                 ele = removeImportElement(ele);
                 if (context.get(ToolConstants.CFG_VALIDATE_WSDL) != null) {
                     validateSchema(ele);
@@ -307,6 +438,7 @@
                 schemaCompiler.parseSchema(key, ele);
             }
         }
+
     }
     private String getPluginUsageString(Options opts) {
         StringBuffer buf = new StringBuffer();



Mime
View raw message