Author: mriou
Date: Tue Aug 14 13:59:51 2007
New Revision: 565910
URL: http://svn.apache.org/viewvc?view=rev&rev=565910
Log:
Turned out that XSD resolution from a BPEL document wasn't implemented (nice
TODO). Fixes it and adds a test case.
Added:
ode/trunk/bpel-scripts/src/main/resources/2.0/good/xsd-import/helloworld-Server.bpel
ode/trunk/bpel-scripts/src/main/resources/2.0/good/xsd-import/helloworld-Server.wsdl
ode/trunk/bpel-scripts/src/main/resources/2.0/good/xsd-import/helloworld.wsdl
ode/trunk/bpel-scripts/src/main/resources/2.0/good/xsd-import/message.xsd
Modified:
ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/BpelCompiler.java
ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/WSDLRegistry.java
ode/trunk/bpel-compiler/src/test/java/org/apache/ode/bpel/compiler_2_0/GoodCompileTest.java
ode/trunk/utils/src/main/java/org/apache/ode/utils/xsd/XSUtils.java
Modified:
ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/BpelCompiler.java
URL:
http://svn.apache.org/viewvc/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/BpelCompiler.java?view=diff&rev=565910&r1=565909&r2=565910
==============================================================================
---
ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/BpelCompiler.java
(original)
+++
ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/BpelCompiler.java
Tue Aug 14 13:59:51 2007
@@ -84,11 +84,14 @@
import org.apache.ode.utils.GUID;
import org.apache.ode.utils.NSContext;
import org.apache.ode.utils.StreamUtils;
+import org.apache.ode.utils.xsd.XSUtils;
+import org.apache.ode.utils.xsd.XsdException;
import org.apache.ode.utils.fs.FileUtils;
import org.apache.ode.utils.msg.MessageBundle;
import org.apache.ode.utils.stl.CollectionsX;
import org.apache.ode.utils.stl.MemberOfFunction;
import org.apache.ode.utils.stl.UnaryFunction;
+import org.apache.xerces.xni.parser.XMLEntityResolver;
import org.w3c.dom.Node;
import javax.wsdl.Definition;
@@ -103,6 +106,7 @@
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
+import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
@@ -171,9 +175,7 @@
}
public void addWsdlImport(URI from, URI wsdlImport, SourceLocation sloc) {
-
Definition4BPEL def;
-
try {
WSDLReader r = _wsdlFactory.newWSDLReader();
WSDLLocatorImpl locator = new WSDLLocatorImpl(_resourceFinder,
from.resolve(wsdlImport));
@@ -195,7 +197,32 @@
}
public void addXsdImport(URI from, URI location, SourceLocation sloc) {
- // TODO: implement.
+ URI resFrom = from.resolve(location);
+ if (__log.isDebugEnabled())
+ __log.debug("Adding XSD import from " + resFrom + " location " +
location);
+ XMLEntityResolver resolver = new
WsdlFinderXMLEntityResolver(_resourceFinder,
+ location, new HashMap<URI,String>(), true);
+ try {
+ Map<URI, byte[]> schemas =
XSUtils.captureSchema(resFrom.toString(), resolver);
+ InputStream xsdStream = _resourceFinder.openResource(resFrom);
+ byte[] data;
+ try {
+ data = StreamUtils.read(xsdStream);
+ } finally {
+ xsdStream.close();
+ }
+ schemas.put(resFrom, data);
+ _wsdlRegistry.addSchemas(schemas);
+ } catch (XsdException e) {
+ CompilationException ce = new
CompilationException(__cmsgs.errInvalidImport(location.toString()));
+ recoveredFromError(sloc, ce);
+ } catch (MalformedURLException e) {
+ CompilationException ce = new
CompilationException(__cmsgs.errInvalidImport(location.toString()));
+ recoveredFromError(sloc, ce);
+ } catch (IOException e) {
+ CompilationException ce = new
CompilationException(__cmsgs.errInvalidImport(location.toString()));
+ recoveredFromError(sloc, ce);
+ }
}
public void setResourceFinder(ResourceFinder finder) {
Modified:
ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/WSDLRegistry.java
URL:
http://svn.apache.org/viewvc/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/WSDLRegistry.java?view=diff&rev=565910&r1=565909&r2=565910
==============================================================================
---
ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/WSDLRegistry.java
(original)
+++
ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/WSDLRegistry.java
Tue Aug 14 13:59:51 2007
@@ -171,7 +171,6 @@
throw ce;
_ctx.recoveredFromError(new SourceLocationImpl(defuri),
ce);
-
continue;
}
@@ -181,6 +180,10 @@
}
}
+ public void addSchemas(Map<URI, byte[]> capture) {
+ _schemas.putAll(capture);
+ }
+
@SuppressWarnings("unchecked")
private void captureSchemas(Definition def, ResourceFinder rf, URI defuri)
throws CompilationException {
assert def != null;
@@ -195,15 +198,12 @@
((List<ExtensibilityElement>)def.getTypes().getExtensibilityElements()).iterator();
iter.hasNext();) {
ExtensibilityElement ee = iter.next();
-
if (ee instanceof XMLSchemaType) {
String schema = ((XMLSchemaType)ee).getXMLSchema();
- Map<URI, byte[]> capture = null;
-
WsdlFinderXMLEntityResolver resolver = new
WsdlFinderXMLEntityResolver(rf, defuri, _internalSchemas, false);
try {
- capture = XSUtils.captureSchema(defuri, schema,
resolver);
+ Map<URI, byte[]> capture =
XSUtils.captureSchema(defuri, schema, resolver);
_schemas.putAll(capture);
try {
Modified:
ode/trunk/bpel-compiler/src/test/java/org/apache/ode/bpel/compiler_2_0/GoodCompileTest.java
URL:
http://svn.apache.org/viewvc/ode/trunk/bpel-compiler/src/test/java/org/apache/ode/bpel/compiler_2_0/GoodCompileTest.java?view=diff&rev=565910&r1=565909&r2=565910
==============================================================================
---
ode/trunk/bpel-compiler/src/test/java/org/apache/ode/bpel/compiler_2_0/GoodCompileTest.java
(original)
+++
ode/trunk/bpel-compiler/src/test/java/org/apache/ode/bpel/compiler_2_0/GoodCompileTest.java
Tue Aug 14 13:59:51 2007
@@ -74,6 +74,7 @@
suite.addTest(new
GoodCompileTCase("/2.0/good/xpath20-func/GetVariableData3-xp2.0.bpel"));
suite.addTest(new
GoodCompileTCase("/2.0/good/xpath20-func/GetVariableData4-xp2.0.bpel"));
suite.addTest(new
GoodCompileTCase("/2.0/good/xpath20-func/GetVariableProperty1-xp2.0.bpel"));
+ suite.addTest(new
GoodCompileTCase("/2.0/good/xsd-import/helloworld-Server.bpel"));
return suite;
}
Added:
ode/trunk/bpel-scripts/src/main/resources/2.0/good/xsd-import/helloworld-Server.bpel
URL:
http://svn.apache.org/viewvc/ode/trunk/bpel-scripts/src/main/resources/2.0/good/xsd-import/helloworld-Server.bpel?view=auto&rev=565910
==============================================================================
---
ode/trunk/bpel-scripts/src/main/resources/2.0/good/xsd-import/helloworld-Server.bpel
(added)
+++
ode/trunk/bpel-scripts/src/main/resources/2.0/good/xsd-import/helloworld-Server.bpel
Tue Aug 14 13:59:51 2007
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="utf-8"?>
+<bpel:process
xmlns:bpel="http://schemas.xmlsoap.org/ws/2004/03/business-process/"
xmlns:pnlk="http://schemas.xmlsoap.org/ws/2004/03/partner-link/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:Client="http://example.com/helloworld/Client"
xmlns:this="http://example.com/helloworld/Server"
xmlns:tns="http://www.example.org/message"
xmlns:diag="http://example.com/helloworld"
xmlns:bpmn="http://www.intalio.com/bpms"
queryLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xpath2.0"
expressionLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xpath2.0"
bpmn:label="Server" bpmn:id="_eAYxsEo7EdyemZotQ08t3A" name="Server"
targetNamespace="http://example.com/helloworld/Server">
+ <bpel:import namespace="http://example.com/helloworld"
location="helloworld.wsdl" importType="http://schemas.xmlsoap.org/wsdl/"/>
+ <bpel:import namespace="http://example.com/helloworld/Server"
location="helloworld-Server.wsdl"
importType="http://schemas.xmlsoap.org/wsdl/"/>
+ <bpel:import namespace="http://www.example.org/message"
location="message.xsd"
importType="http://www.w3.org/2001/XMLSchema"></bpel:import>
+ <bpel:partnerLinks>
+ <bpel:partnerLink name="serverAndClientPlkVar"
partnerLinkType="diag:ServerAndClient" myRole="Server_for_Client"/>
+ </bpel:partnerLinks>
+ <bpel:variables>
+ <bpel:variable name="thisReceiveRequestMsg"
messageType="this:receiveRequest"/>
+ <bpel:variable name="thisReceiveResponseMsg"
messageType="this:receiveResponse"/>
+ <bpel:variable name="Data" type="tns:Data"/>
+ </bpel:variables>
+ <bpel:sequence>
+ <bpel:receive partnerLink="serverAndClientPlkVar"
portType="this:ForClient" operation="receive" variable="thisReceiveRequestMsg"
createInstance="yes" bpmn:label="receive"
bpmn:id="_evn2QEo7EdyemZotQ08t3A"></bpel:receive>
+ <bpel:assign name="init-variables-Server">
+ <bpel:copy bpmn:label="$thisReceiveResponseMsg
out:_gfFowEo7EdyemZotQ08t3A">
+ <bpel:from>
+ <bpel:literal>
+<this:receiveResponse>
+</this:receiveResponse>
+ </bpel:literal>
+ </bpel:from>
+ <bpel:to>$thisReceiveResponseMsg.body</bpel:to>
+ </bpel:copy>
+ <bpel:copy bpmn:label="$Data">
+ <bpel:from>
+ <bpel:literal>
+ </bpel:literal>
+ </bpel:from>
+ <bpel:to>$Data</bpel:to>
+ </bpel:copy>
+ </bpel:assign>
+ <bpel:assign bpmn:label="invoke" bpmn:id="_FrsFcEpAEdySiIWBetfiFA">
+ <bpel:copy>
+ <bpel:from>"test"</bpel:from>
+ <bpel:to>$Data/tns:Name</bpel:to>
+ </bpel:copy>
+ <bpel:copy>
+ <bpel:from>"world"</bpel:from>
+ <bpel:to>$Data/tns:Age</bpel:to>
+ </bpel:copy>
+ </bpel:assign>
+ <bpel:assign bpmn:label="result" bpmn:id="_fz4IkEo7EdyemZotQ08t3A">
+ <bpel:copy>
+ <bpel:from>concat($Data/tns:Name, $Data/tns:Age)</bpel:from>
+ <bpel:to>$thisReceiveResponseMsg.body</bpel:to>
+ </bpel:copy>
+ </bpel:assign>
+ <bpel:reply partnerLink="serverAndClientPlkVar" portType="this:ForClient"
operation="receive" variable="thisReceiveResponseMsg" bpmn:label="result"
bpmn:id="_fz4IkEo7EdyemZotQ08t3A"></bpel:reply>
+ </bpel:sequence>
+</bpel:process>
\ No newline at end of file
Added:
ode/trunk/bpel-scripts/src/main/resources/2.0/good/xsd-import/helloworld-Server.wsdl
URL:
http://svn.apache.org/viewvc/ode/trunk/bpel-scripts/src/main/resources/2.0/good/xsd-import/helloworld-Server.wsdl?view=auto&rev=565910
==============================================================================
---
ode/trunk/bpel-scripts/src/main/resources/2.0/good/xsd-import/helloworld-Server.wsdl
(added)
+++
ode/trunk/bpel-scripts/src/main/resources/2.0/good/xsd-import/helloworld-Server.wsdl
Tue Aug 14 13:59:51 2007
@@ -0,0 +1,38 @@
+<?xml version='1.0' encoding='utf-8'?>
+<wsdl:definitions xmlns:tns="http://www.example.org/message"
xmlns:Client="http://example.com/helloworld/Client"
xmlns:diag="http://example.com/helloworld"
xmlns:bpel="http://schemas.xmlsoap.org/ws/2004/03/business-process/"
xmlns:pnlk="http://schemas.xmlsoap.org/ws/2004/03/partner-link/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:this="http://example.com/helloworld/Server"
targetNamespace="http://example.com/helloworld/Server">
+ <wsdl:types>
+ <xs:schema elementFormDefault="qualified"
targetNamespace="http://example.com/helloworld/Server">
+ <xs:element name="receiveRequest" type="xs:string"/>
+ <xs:element name="receiveResponse" type="xs:string"/>
+ </xs:schema>
+ </wsdl:types>
+ <wsdl:message name="receiveRequest">
+ <wsdl:part name="body" element="this:receiveRequest"/>
+ </wsdl:message>
+ <wsdl:message name="receiveResponse">
+ <wsdl:part name="body" element="this:receiveResponse"/>
+ </wsdl:message>
+ <wsdl:portType name="ForClient">
+ <wsdl:operation name="receive">
+ <wsdl:input message="this:receiveRequest" name="receive"/>
+ <wsdl:output message="this:receiveResponse"
name="receiveResponse"/>
+ </wsdl:operation>
+ </wsdl:portType>
+ <wsdl:binding name="CanonicBindingForClient" type="this:ForClient">
+ <soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"/>
+ <wsdl:operation name="receive">
+ <soap:operation style="document"
soapAction="http://example.com/helloworld/Server/ForClient/receive"/>
+ <wsdl:input>
+ <soap:body use="literal"/>
+ </wsdl:input>
+ <wsdl:output>
+ <soap:body use="literal"/>
+ </wsdl:output>
+ </wsdl:operation>
+ </wsdl:binding>
+ <wsdl:service name="CanonicServiceForClient">
+ <wsdl:port name="canonicPort" binding="this:CanonicBindingForClient">
+ <soap:address
location="http://localhost:8080/ode/processes/HelloWorld/helloworld/Server/Client"/>
+ </wsdl:port>
+ </wsdl:service>
+</wsdl:definitions>
\ No newline at end of file
Added:
ode/trunk/bpel-scripts/src/main/resources/2.0/good/xsd-import/helloworld.wsdl
URL:
http://svn.apache.org/viewvc/ode/trunk/bpel-scripts/src/main/resources/2.0/good/xsd-import/helloworld.wsdl?view=auto&rev=565910
==============================================================================
---
ode/trunk/bpel-scripts/src/main/resources/2.0/good/xsd-import/helloworld.wsdl
(added)
+++
ode/trunk/bpel-scripts/src/main/resources/2.0/good/xsd-import/helloworld.wsdl
Tue Aug 14 13:59:51 2007
@@ -0,0 +1,7 @@
+<?xml version='1.0' encoding='utf-8'?>
+<wsdl:definitions xmlns:tns="http://www.example.org/message"
xmlns:bpdm="http://www.intalio/designer/business-process-data-modeling"
xmlns:Client="http://example.com/helloworld/Client"
xmlns:diag="http://example.com/helloworld"
xmlns:bpel="http://schemas.xmlsoap.org/ws/2004/03/business-process/"
xmlns:pnlk="http://schemas.xmlsoap.org/ws/2004/03/partner-link/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:Server="http://example.com/helloworld/Server"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
targetNamespace="http://example.com/helloworld">
+ <wsdl:import namespace="http://example.com/helloworld/Server"
location="helloworld-Server.wsdl"/>
+ <pnlk:partnerLinkType name="ServerAndClient">
+ <pnlk:role name="Server_for_Client" portType="Server:ForClient"/>
+ </pnlk:partnerLinkType>
+</wsdl:definitions>
\ No newline at end of file
Added: ode/trunk/bpel-scripts/src/main/resources/2.0/good/xsd-import/message.xsd
URL:
http://svn.apache.org/viewvc/ode/trunk/bpel-scripts/src/main/resources/2.0/good/xsd-import/message.xsd?view=auto&rev=565910
==============================================================================
--- ode/trunk/bpel-scripts/src/main/resources/2.0/good/xsd-import/message.xsd
(added)
+++ ode/trunk/bpel-scripts/src/main/resources/2.0/good/xsd-import/message.xsd
Tue Aug 14 13:59:51 2007
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/message"
xmlns:tns="http://www.example.org/message" elementFormDefault="qualified">
+
+ <element name="start" type="string"></element>
+
+ <complexType name="Data">
+ <sequence>
+ <element name="Name" type="string"></element>
+ <element name="Age" type="string"></element>
+ </sequence>
+ </complexType>
+</schema>
\ No newline at end of file
Modified: ode/trunk/utils/src/main/java/org/apache/ode/utils/xsd/XSUtils.java
URL:
http://svn.apache.org/viewvc/ode/trunk/utils/src/main/java/org/apache/ode/utils/xsd/XSUtils.java?view=diff&rev=565910&r1=565909&r2=565910
==============================================================================
--- ode/trunk/utils/src/main/java/org/apache/ode/utils/xsd/XSUtils.java
(original)
+++ ode/trunk/utils/src/main/java/org/apache/ode/utils/xsd/XSUtils.java Tue Aug
14 13:59:51 2007
@@ -42,174 +42,174 @@
*/
public class XSUtils {
- private static final Log __log = LogFactory.getLog(XSUtils.class);
+ private static final Log __log = LogFactory.getLog(XSUtils.class);
- private static final XsdMessages __msgs =
MessageBundle.getMessages(XsdMessages.class);
+ private static final XsdMessages __msgs =
MessageBundle.getMessages(XsdMessages.class);
- /**
- * Recursively "capture" XSD documents starting at the given URI and
- * using an [EMAIL PROTECTED] XMLEntityResolver} to obtain document streams.
The
- * result is a mapping from the XSD URI to a byte array containing the
- * "captured" document stream.
- *
- * @param initialUri URI of the schema
- * @param resolver [EMAIL PROTECTED] XMLEntityResolver} used to obtain XSD
document streams
- *
- * @return mapping between schema URI and the "captured" schema text (in
byte form)
- */
- public static Map<URI, byte[]> captureSchema(String initialUri,
XMLEntityResolver resolver)
- throws XsdException {
- DOMInputImpl input = new DOMInputImpl();
- input.setSystemId(initialUri);
- return captureSchema(input, resolver);
- }
-
- /**
- * Capture the schemas supplied by the reader. <code>systemURI</code> is
- * required to resolve any relative uris encountered during the parse.
- *
- * @param systemURI Used to resolve relative uris.
- * @param schemaData the top level schema.
- * @param resolver entity resolver
- *
- * @return
- */
- public static Map<URI, byte[]> captureSchema(URI systemURI, String
schemaData,
- XMLEntityResolver resolver) throws XsdException {
-
- if (__log.isDebugEnabled())
- __log.debug("captureSchema(URI,Text,...): systemURI=" + systemURI);
-
- DOMInputImpl input = new DOMInputImpl();
- input.setSystemId(systemURI.toString());
- input.setStringData(schemaData);
-
- Map<URI, byte[]> ret = captureSchema(input, resolver);
- // Let's not forget the root schema.
- try {
- // TODO don't assume UTF-8 - but which encoding is required?
- // either we need another parameter or the entire idea of
- // passing in a String needs to be revised.
- ret.put(systemURI, schemaData.getBytes("UTF-8"));
- } catch (UnsupportedEncodingException uenc) {
- throw new RuntimeException(uenc);
- }
- return ret;
- }
+ /**
+ * Recursively "capture" XSD documents starting at the given URI and
+ * using an [EMAIL PROTECTED] XMLEntityResolver} to obtain document
streams. The
+ * result is a mapping from the XSD URI to a byte array containing the
+ * "captured" document stream.
+ *
+ * @param initialUri URI of the schema
+ * @param resolver [EMAIL PROTECTED] XMLEntityResolver} used to obtain XSD
document streams
+ *
+ * @return mapping between schema URI and the "captured" schema text (in
byte form)
+ */
+ public static Map<URI, byte[]> captureSchema(String initialUri,
XMLEntityResolver resolver)
+ throws XsdException {
+ DOMInputImpl input = new DOMInputImpl();
+ input.setSystemId(initialUri);
+ Map<URI, byte[]> ret = captureSchema(input, resolver);
- private static Map<URI, byte[]> captureSchema(LSInput input,
XMLEntityResolver resolver)
- throws XsdException {
-
- if (__log.isDebugEnabled())
- __log.debug("captureSchema(LSInput,...): input.systemId=" +
input.getSystemId());
-
- Map<URI, byte[]> captured = new HashMap<URI, byte[]>();
+ return ret;
+ }
- if (resolver == null) {
- resolver = new DefaultXMLEntityResolver();
+ /**
+ * Capture the schemas supplied by the reader. <code>systemURI</code> is
+ * required to resolve any relative uris encountered during the parse.
+ *
+ * @param systemURI Used to resolve relative uris.
+ * @param schemaData the top level schema.
+ * @param resolver entity resolver
+ *
+ * @return
+ */
+ public static Map<URI, byte[]> captureSchema(URI systemURI, String
schemaData,
+ XMLEntityResolver resolver)
throws XsdException {
+ if (__log.isDebugEnabled())
+ __log.debug("captureSchema(URI,Text,...): systemURI=" + systemURI);
+
+ DOMInputImpl input = new DOMInputImpl();
+ input.setSystemId(systemURI.toString());
+ input.setStringData(schemaData);
+
+ Map<URI, byte[]> ret = captureSchema(input, resolver);
+ // Let's not forget the root schema.
+ try {
+ // TODO don't assume UTF-8 - but which encoding is required?
+ // either we need another parameter or the entire idea of
+ // passing in a String needs to be revised.
+ ret.put(systemURI, schemaData.getBytes("UTF-8"));
+ } catch (UnsupportedEncodingException uenc) {
+ throw new RuntimeException(uenc);
+ }
+ return ret;
}
- CapturingXMLEntityResolver cr = new CapturingXMLEntityResolver(captured,
resolver);
+ private static Map<URI, byte[]> captureSchema(LSInput input,
XMLEntityResolver resolver)
+ throws XsdException {
+ if (__log.isDebugEnabled())
+ __log.debug("captureSchema(LSInput,...): input.systemId=" +
input.getSystemId());
- XMLSchemaLoader schemaLoader = new XMLSchemaLoader();
- schemaLoader.setEntityResolver(cr);
+ Map<URI, byte[]> captured = new HashMap<URI, byte[]>();
- LoggingXmlErrorHandler eh = new LoggingXmlErrorHandler(__log);
- schemaLoader.setErrorHandler(eh);
+ if (resolver == null) {
+ resolver = new DefaultXMLEntityResolver();
+ }
- XSModel model = schemaLoader.load(input);
-
- // The following mess is due to XMLSchemaLoaders funkyness in error
- // reporting: sometimes it throws an exception, sometime it returns
- // null, sometimes it just prints bs to the screen.
- if (model == null) {
- /*
- * Someone inside Xerces will have eaten this exception, for no good
- * reason.
- */
- List<XMLParseException> errors = eh.getErrors();
- if (errors.size() != 0) {
- __log.error("captureSchema: XMLParseException(s) in " + input);
-
- XsdException ex = null;
- for (XMLParseException xpe : errors) {
- ex = new XsdException(ex, xpe.getMessage(), xpe.getLineNumber(),
xpe.getColumnNumber(),
- xpe.getLiteralSystemId());
- }
- throw ex;
- }
-
- if (__log.isDebugEnabled())
- __log.debug("captureSchema: NULL model (unknown error) for " +
input.getSystemId());
- }
+ CapturingXMLEntityResolver cr = new
CapturingXMLEntityResolver(captured, resolver);
- return captured;
- }
+ XMLSchemaLoader schemaLoader = new XMLSchemaLoader();
+ schemaLoader.setEntityResolver(cr);
- /**
- * Implementation of [EMAIL PROTECTED] LoggingXmlErrorHandler} that outputs
messages to
- * a log.
- */
- static class LoggingXmlErrorHandler implements XMLErrorHandler {
+ LoggingXmlErrorHandler eh = new LoggingXmlErrorHandler(__log);
+ schemaLoader.setErrorHandler(eh);
- private Log _log;
+ XSModel model = schemaLoader.load(input);
+
+ // The following mess is due to XMLSchemaLoaders funkyness in error
+ // reporting: sometimes it throws an exception, sometime it returns
+ // null, sometimes it just prints bs to the screen.
+ if (model == null) {
+ /*
+ * Someone inside Xerces will have eaten this exception, for no good
+ * reason.
+ */
+ List<XMLParseException> errors = eh.getErrors();
+ if (errors.size() != 0) {
+ __log.error("captureSchema: XMLParseException(s) in " + input);
+
+ XsdException ex = null;
+ for (XMLParseException xpe : errors) {
+ ex = new XsdException(ex, xpe.getMessage(),
xpe.getLineNumber(), xpe.getColumnNumber(),
+ xpe.getLiteralSystemId());
+ }
+ throw ex;
+ }
- private ArrayList<XMLParseException> _errors = new
ArrayList<XMLParseException>();
+ if (__log.isDebugEnabled())
+ __log.debug("captureSchema: NULL model (unknown error) for " +
input.getSystemId());
+ }
- /**
- * Create a new instance that will output to the specified [EMAIL
PROTECTED] Log}
- * instance.
- * @param log the target log, which much be non-<code>null</code>
- */
- public LoggingXmlErrorHandler(Log log) {
- assert log != null;
- _log = log;
+ return captured;
}
- public List<XMLParseException> getErrors() {
- return _errors;
- }
-
/**
- * @see XMLErrorHandler#warning(java.lang.String, java.lang.String,
org.apache.xerces.xni.parser.XMLParseException)
+ * Implementation of [EMAIL PROTECTED] LoggingXmlErrorHandler} that
outputs messages to
+ * a log.
*/
- public void warning(String domain, String key, XMLParseException ex)
throws XNIException {
- if (_log.isDebugEnabled())
- _log.debug("XSDErrorHandler.warning: domain=" + domain + ", key=" +
key,ex);
-
- if (ex != null) {
- _errors.add(ex);
- throw ex;
- }
- }
+ static class LoggingXmlErrorHandler implements XMLErrorHandler {
- /**
- * @see
org.apache.xerces.xni.parser.XMLErrorHandler#error(java.lang.String,
java.lang.String, org.apache.xerces.xni.parser.XMLParseException)
- */
- public void error(String domain, String key, XMLParseException ex) throws
XNIException {
- if (_log.isDebugEnabled())
- _log.debug("XSDErrorHandler.error: domain=" + domain + ", key=" +
key,ex);
-
- if (ex != null) {
- _errors.add(ex);
- throw ex;
- }
+ private Log _log;
- // Should not reach here, but just in case...
- throw new XNIException("Unknown XSD error state; domain=" + domain + ",
key=" +key);
- }
+ private ArrayList<XMLParseException> _errors = new
ArrayList<XMLParseException>();
+
+ /**
+ * Create a new instance that will output to the specified [EMAIL
PROTECTED] Log}
+ * instance.
+ * @param log the target log, which much be non-<code>null</code>
+ */
+ public LoggingXmlErrorHandler(Log log) {
+ assert log != null;
+ _log = log;
+ }
+
+ public List<XMLParseException> getErrors() {
+ return _errors;
+ }
+
+ /**
+ * @see XMLErrorHandler#warning(java.lang.String, java.lang.String,
org.apache.xerces.xni.parser.XMLParseException)
+ */
+ public void warning(String domain, String key, XMLParseException ex)
throws XNIException {
+ if (_log.isDebugEnabled())
+ _log.debug("XSDErrorHandler.warning: domain=" + domain + ",
key=" + key,ex);
+
+ if (ex != null) {
+ _errors.add(ex);
+ throw ex;
+ }
+ }
+
+ /**
+ * @see
org.apache.xerces.xni.parser.XMLErrorHandler#error(java.lang.String,
java.lang.String, org.apache.xerces.xni.parser.XMLParseException)
+ */
+ public void error(String domain, String key, XMLParseException ex)
throws XNIException {
+ if (_log.isDebugEnabled())
+ _log.debug("XSDErrorHandler.error: domain=" + domain + ",
key=" + key,ex);
+
+ if (ex != null) {
+ _errors.add(ex);
+ throw ex;
+ }
+
+ // Should not reach here, but just in case...
+ throw new XNIException("Unknown XSD error state; domain=" + domain
+ ", key=" +key);
+ }
- public void fatalError(String domain, String key, XMLParseException ex)
throws XNIException {
- if (_log.isDebugEnabled())
- _log.debug("XSDErrorHandler.fatal: domain=" + domain + ", key=" +
key,ex);
-
- if (ex != null) {
- _errors.add(ex);
- throw ex;
- }
-
- // Should not reach here, but just in case...
- throw new XNIException("Unknown XSD error state; domain=" + domain + ",
key=" +key);
- }
- }
+ public void fatalError(String domain, String key, XMLParseException
ex) throws XNIException {
+ if (_log.isDebugEnabled())
+ _log.debug("XSDErrorHandler.fatal: domain=" + domain + ",
key=" + key,ex);
+
+ if (ex != null) {
+ _errors.add(ex);
+ throw ex;
+ }
+
+ // Should not reach here, but just in case...
+ throw new XNIException("Unknown XSD error state; domain=" + domain
+ ", key=" +key);
+ }
+ }
}