Author: dkulp
Date: Thu Jun 5 10:45:54 2008
New Revision: 663674
URL: http://svn.apache.org/viewvc?rev=663674&view=rev
Log:
Merged revisions 663658 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r663658 | dkulp | 2008-06-05 12:58:15 -0400 (Thu, 05 Jun 2008) | 3 lines
Start of XMLBeans tooling
More validation fixes
........
Modified:
cxf/branches/2.0.x-fixes/ (props changed)
cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java
Propchange: cxf/branches/2.0.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified:
cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java?rev=663674&r1=663673&r2=663674&view=diff
==============================================================================
---
cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java
(original)
+++
cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java
Thu Jun 5 10:45:54 2008
@@ -19,10 +19,13 @@
package org.apache.cxf.wsdl;
+import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import java.util.LinkedHashMap;
import java.util.List;
@@ -56,7 +59,6 @@
import org.w3c.dom.ls.LSResourceResolver;
import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
import org.apache.cxf.Bus;
import org.apache.cxf.common.i18n.Message;
@@ -96,14 +98,14 @@
* the code in here.
*/
private static final class SchemaLSResourceResolver implements
LSResourceResolver {
- private final ServiceInfo si;
+ private final Map<String, DOMSource> schemas;
private final ExtendedURIResolver resolver = new ExtendedURIResolver();
- private SchemaLSResourceResolver(ServiceInfo serviceInfo) {
- this.si = serviceInfo;
+
+ private SchemaLSResourceResolver(Map<String, DOMSource> schemas) {
+ this.schemas = schemas;
}
- private Reader getSchemaAsStream(Element schemaElement) {
- DOMSource source = new DOMSource(schemaElement);
+ private Reader getSchemaAsStream(DOMSource source) {
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
try {
@@ -116,35 +118,37 @@
public LSInput resolveResource(String type, String namespaceURI,
String publicId,
String systemId, String baseURI) {
- for (SchemaInfo schemaInfo : si.getSchemas()) {
- XmlSchema sch = schemaInfo.getSchema();
- if (namespaceURI.equals(sch.getTargetNamespace())) {
+
+ String newId = systemId;
+ if (baseURI != null) {
+ try {
+ URI uri = new URI(baseURI);
+ uri = uri.resolve(systemId);
+ newId = uri.toString();
+ } catch (URISyntaxException e) {
+ //ignore
+ }
+ }
+ if (schemas.containsKey(newId + ":" + namespaceURI)) {
+ DOMSource ds = schemas.remove(newId + ":" + namespaceURI);
+ LSInputImpl impl = new LSInputImpl();
+ impl.setSystemId(newId);
+ impl.setBaseURI(newId);
+ impl.setCharacterStream(getSchemaAsStream(ds));
+ return impl;
+ }
+
+ for (Map.Entry<String, DOMSource> ent : schemas.entrySet()) {
+ if (ent.getKey().endsWith(namespaceURI)) {
+ schemas.remove(ent.getKey());
LSInputImpl impl = new LSInputImpl();
- Element schemaAsDom = schemaInfo.getElement();
- if (schemaAsDom != null) {
-
impl.setCharacterStream(getSchemaAsStream(schemaAsDom));
- return impl;
- }
- // otherwise, go ahead and assume it's out there somewhere.
- // this needs catalog support, does it not?
- 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();
- }
- impl.setByteStream(ins);
+ impl.setSystemId(newId);
+ impl.setBaseURI(newId);
+ impl.setCharacterStream(getSchemaAsStream(ent.getValue()));
return impl;
}
}
+
//REVIST - we need to get catalogs in here somehow :-(
if (systemId == null) {
systemId = publicId;
@@ -533,7 +537,7 @@
Schema schema = serviceInfo.getProperty(Schema.class.getName(),
Schema.class);
if (schema == null) {
SchemaFactory factory =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
- Map<String, Source> schemaSourcesMap = new LinkedHashMap<String,
Source>();
+ Map<String, DOMSource> schemaSourcesMap = new
LinkedHashMap<String, DOMSource>();
for (SchemaInfo si : serviceInfo.getSchemas()) {
Element el = si.getElement();
String baseURI = el.getBaseURI();
@@ -544,36 +548,43 @@
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)
+ try {
+ 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();
+ }
+ Document doc = XMLUtils.parse(ins);
+ try {
+ ins.close();
+ } catch (IOException ex) {
+ //ignore
+ }
+
+ DOMSource ss = new DOMSource(doc, sch.getSourceURI());
+ schemaSourcesMap.put(sch.getSourceURI() + ":"
+ + sch.getTargetNamespace(), ss);
}
-
- 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));
+ factory.setResourceResolver(new
SchemaLSResourceResolver(schemaSourcesMap));
schema = factory.newSchema(schemaSourcesMap.values()
.toArray(new
Source[schemaSourcesMap.size()]));
- } catch (SAXException ex) {
+ } catch (Exception ex) {
// Something not right with the schema from the wsdl.
LOG.log(Level.WARNING, "SAXException for newSchema() on ", ex);
for (SchemaInfo schemaInfo : serviceInfo.getSchemas()) {