cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r661821 - /cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java
Date Fri, 30 May 2008 19:10:31 GMT
Author: dkulp
Date: Fri May 30 12:10:31 2008
New Revision: 661821

URL: http://svn.apache.org/viewvc?rev=661821&view=rev
Log:
Collect all the schemas in the schemaCollection upfront to create the schema for validation.

Modified:
    cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java?rev=661821&r1=661820&r2=661821&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java Fri May 30
12:10:31 2008
@@ -24,7 +24,7 @@
 import java.io.StringReader;
 import java.io.StringWriter;
 import java.net.URL;
-import java.util.ArrayList;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.logging.Level;
@@ -569,20 +569,46 @@
         Schema schema = serviceInfo.getProperty(Schema.class.getName(), Schema.class);
         if (schema == null) {
             SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
-            List<Source> schemaSources = new ArrayList<Source>();
-            for (SchemaInfo schemaInfo : serviceInfo.getSchemas()) {
-                Source source = new DOMSource(schemaInfo.getElement());
-                String baseURI = schemaInfo.getElement().getBaseURI();
-                if (baseURI != null) {
-                    source.setSystemId(baseURI);
-                } else {
-                    source.setSystemId(schemaInfo.getSystemId());
+            Map<String, Source> schemaSourcesMap = new LinkedHashMap<String, Source>();
+            for (SchemaInfo si : serviceInfo.getSchemas()) {
+                Element el = si.getElement();
+                String baseURI = el.getBaseURI();
+                if (baseURI == null) {
+                    baseURI = si.getSystemId();
                 }
-                schemaSources.add(source);
+                DOMSource ds = new DOMSource(el, baseURI);                
+                schemaSourcesMap.put(si.getSystemId() + ":" + si.getNamespaceURI(), ds);
             }
+
+            for (XmlSchema sch : serviceInfo.getXmlSchemaCollection().getXmlSchemas()) {
+                if (sch.getSourceURI() != null
+                    && !schemaSourcesMap.containsKey(sch.getSourceURI() + ":" 
+                                                     + sch.getTargetNamespace())) { 
+                    
+                    InputStream ins = null;
+                    try {
+                        URL url = new URL(sch.getSourceURI());
+                        ins = url.openStream();
+                    } catch (Exception e) {
+                        //ignore, we'll just use what we have.  (though
+                        //bugs in XmlSchema could make this less useful)
+                    }
+                    
+                    if (ins == null) {
+                        LoadingByteArrayOutputStream out = new LoadingByteArrayOutputStream();
+                        sch.write(out);
+                        ins = out.createInputStream();
+                    }
+                    StreamSource ss = new StreamSource(ins, sch.getSourceURI());
+                    schemaSourcesMap.put(sch.getSourceURI() + ":" 
+                                         + sch.getTargetNamespace(), ss);
+                }
+            } 
+
             try {
                 factory.setResourceResolver(new SchemaLSResourceResolver(serviceInfo));
-                schema = factory.newSchema(schemaSources.toArray(new Source[schemaSources.size()]));
+                schema = factory.newSchema(schemaSourcesMap.values()
+                                           .toArray(new Source[schemaSourcesMap.size()]));
             } catch (SAXException ex) {
                 // Something not right with the schema from the wsdl.
                 LOG.log(Level.WARNING, "SAXException for newSchema() on ", ex);



Mime
View raw message