Author: jkaputin
Date: Tue Sep 27 04:37:42 2005
New Revision: 291912
URL: http://svn.apache.org/viewcvs?rev=291912&view=rev
Log:
Temporarily change schema parsing to use Xerces XML
Schema API impl, pending enhancements to ws-commons
XmlSchema (i.e. to achieve Woden M1 end-Sept).
Also, tidied up error handling so non-WSDL system errors
are now thrown as WSDLExceptions and WSDL-related errors
are reported by the ErrorReporter.
Modified:
incubator/woden/java/src/org/apache/woden/internal/DOMWSDLReader.java
incubator/woden/java/src/org/apache/woden/internal/ErrorReporter.java
incubator/woden/java/src/org/apache/woden/internal/Messages.properties
Modified: incubator/woden/java/src/org/apache/woden/internal/DOMWSDLReader.java
URL:
http://svn.apache.org/viewcvs/incubator/woden/java/src/org/apache/woden/internal/DOMWSDLReader.java?rev=291912&r1=291911&r2=291912&view=diff
==============================================================================
--- incubator/woden/java/src/org/apache/woden/internal/DOMWSDLReader.java
(original)
+++ incubator/woden/java/src/org/apache/woden/internal/DOMWSDLReader.java Tue
Sep 27 04:37:42 2005
@@ -5,6 +5,7 @@
import java.io.IOException;
import java.io.InputStream;
+import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
@@ -23,6 +24,7 @@
import org.apache.woden.schema.Schema;
import org.apache.woden.schema.SchemaImport;
import org.apache.woden.wsdl20.xml.*;
+import org.apache.ws.commons.schema.*;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -32,7 +34,16 @@
//JK temporary imports (pending TODOs)
-import org.apache.axis.xsd.xml.schema.*; //TODO test ws-commons XmlSchema
+
+//imports required temporarily while using Xerces XMLSchema APi
+import com.ibm.wsdl.util.xml.DOM2Writer;
+import org.apache.xerces.dom3.bootstrap.DOMImplementationRegistry;
+import org.apache.xerces.xs.*;
+import org.w3c.dom.ls.DOMImplementationLS;
+import org.w3c.dom.ls.LSInput;
+
+
+
import temp.WSDLException;
/**
@@ -54,32 +65,36 @@
* WSDL XML description.
* @return the description.
*/
- public DescriptionElement readWSDL(String wsdlURI) throws Exception {
+ public DescriptionElement readWSDL(String wsdlURI) throws WSDLException {
try {
- URL url = StringUtils.getURL(null, wsdlURI);
+ System.out.println("readWSDL at " + wsdlURI);
- InputStream inputStream = StringUtils.getContentAsInputStream(url);
- InputSource inputSource = new InputSource(inputStream);
- inputSource.setSystemId(url.toString());
- Document doc = getDocument(inputSource, url.toString());
+ //TODO add WSDL locator for resolving URIs
- inputStream.close();
+ URL url = StringUtils.getURL(null, wsdlURI);
+ String wsdlURL = url.toString();
+ Document doc = getDocument(new InputSource(wsdlURL), wsdlURL);
+
Element docEl = doc.getDocumentElement();
- DescriptionElement desc = parseDescription(url.toString(), docEl,
null);
+ DescriptionElement desc = parseDescription(wsdlURL, docEl, null);
return desc;
- } catch (Exception e) {
- // TODO decide how to handle exceptions. Here,
MalformedURLException
- // and IOException
- // TODO: Comment LM: Although we need to decide how to
deal with exceptions
- // all exceptions need to be handled by a replacable
reporter. Comment JK:
- // Just WSDL parsing errors handled by reporter...other errors
handled as
- // exceptions (i.e. wrapped as WSDLExceptions).
+ //We can't continue from any caught exceptions, so just wrap them as
+ //a WSDLException and re-throw.
+
+ } catch (MalformedURLException e) {
- //e.printStackTrace();
- throw e;
+ String msg = getErrorReporter().getFormattedMessage(
+ "WSDL013", new Object[] {null, wsdlURI});
+ throw new WSDLException(WSDLException.PARSER_ERROR, msg, e);
+
+ } catch (IOException e) {
+
+ String msg = getErrorReporter().getFormattedMessage(
+ "WSDL014", new Object[] {wsdlURI});
+ throw new WSDLException(WSDLException.PARSER_ERROR, msg, e);
}
}
@@ -192,11 +207,11 @@
}
/*
- * TODO Testing with ws-commons XmlSchema
+ * TODO use ws-commons XmlSchema, instead of Xerces XML Schema API
*/
private Schema parseSchema(Element schemaEl,
- TypesElement desc)
- throws WSDLException
+ DescriptionElement desc)
+ throws WSDLException
{
SchemaImpl schema = new SchemaImpl();
@@ -205,22 +220,95 @@
schema.setTargetNamespace(
DOMUtils.getAttribute(schemaEl, Constants.ATTR_TARGET_NAMESPACE));
+ /*
+ * TODO Limitations in ws-commons XmlSchema slowing down Woden progress
+ * for M1, so reverting to Xerces XMLSchema API for the time being.
+ *
XmlSchemaCollection xsc =
new XmlSchemaCollection();
XmlSchema xs = xsc.read(schemaEl);
schema.setSchemaContent(xs);
+ */
+
+ try {
+ //create an LSInput object to hold the schema string
+ System.setProperty(DOMImplementationRegistry.PROPERTY,
+ "org.apache.xerces.dom.DOMImplementationSourceImpl");
+ DOMImplementationRegistry domRegistry =
DOMImplementationRegistry.newInstance();
+
+ DOMImplementationLS domImpl =
+ (DOMImplementationLS)domRegistry.getDOMImplementation("LS");
+
+ LSInput lsInput = domImpl.createLSInput();
+
+ //store the schema as a string in the LSInput
+ String schemaString = DOM2Writer.nodeToString(schemaEl);
+ lsInput.setStringData(schemaString);
+
+ //Use DOM level 3 bootstrap to get an XSLoader
+ System.setProperty(DOMImplementationRegistry.PROPERTY,
+ "org.apache.xerces.dom.DOMXSImplementationSourceImpl");
+ DOMImplementationRegistry xsRegistry =
DOMImplementationRegistry.newInstance();
+
+ XSImplementation xsImpl =
+ (XSImplementation)
xsRegistry.getDOMImplementation("XS-Loader");
+
+ XSLoader xsLoader = xsImpl.createXSLoader(null);
+
+ //load the XSModel from the schema string
+ XSModel xsModel = xsLoader.load(lsInput);
+
+ schema.setSchemaContent(xsModel);
+
+ /*
+ * print out the schema elements
+ *
+ XSNamedMap xsNamedMap =
xsModel.getComponents(XSConstants.ELEMENT_DECLARATION);
+ System.out.println("\nInline schema elements (" +
xsNamedMap.getLength() +"):");
+ for(int i = 0; i < xsNamedMap.getLength(); i++)
+ {
+ System.out.println( (xsNamedMap.item(i)).getName() );
+ }
+ */
+
+ } catch (ClassCastException e) {
+ getErrorReporter().reportError(
+ "WSDL002", new Object[] {"Schema"},
ErrorReporter.SEVERITY_FATAL_ERROR, e);
+ } catch (XSException e) {
+ getErrorReporter().reportError(
+ "WSDL002", new Object[] {"Schema"},
ErrorReporter.SEVERITY_FATAL_ERROR, e);
+ } catch (ClassNotFoundException e) {
+ getErrorReporter().reportError(
+ "WSDL002", new Object[] {"Schema"},
ErrorReporter.SEVERITY_FATAL_ERROR, e);
+ } catch (InstantiationException e) {
+ getErrorReporter().reportError(
+ "WSDL002", new Object[] {"Schema"},
ErrorReporter.SEVERITY_FATAL_ERROR, e);
+ } catch (IllegalAccessException e) {
+ getErrorReporter().reportError(
+ "WSDL002", new Object[] {"Schema"},
ErrorReporter.SEVERITY_FATAL_ERROR, e);
+ }
return schema;
}
/*
- * TODO Testing with ws-commons XmlSchema
+ * Parse the <.xs:import>. element and retrieve the imported
+ * schema document if schemaLocation specified. Failure to retrieve
+ * the schema will only matter if any WSDL components contain elements or
+ * constraints that refer to the schema, and typically this will be
+ * determined later by WSDL validation. So just report any such errors
+ * and return the SchemaImport object (i.e. with a null schema property).
+ *
+ * WSDL 2.0 spec validation:
+ * - namespace attribute is REQUIRED
+ * - imported schema MUST have a targetNamespace
+ * - namespace and targetNamespace MUST be the same
*/
private SchemaImport parseSchemaImport(Element importEl,
- TypesElement types)
+ DescriptionElement desc)
throws WSDLException
{
SchemaImportImpl schemaImport = new SchemaImportImpl();
@@ -231,12 +319,98 @@
schemaImport.setSchemaLocation(
DOMUtils.getAttribute(importEl,
SchemaConstants.ATTR_SCHEMA_LOCATION));
+ if(schemaImport.getNamespace() == null)
+ {
+ //The namespace attribute is REQUIRED on xs:import.
+ //(WSDL 2.0 W3C spec, Part 2: 3.1.1 'Importing XML Schema')
+
+ String schemaURI = schemaImport.getSchemaLocation() != null ?
+ schemaImport.getSchemaLocation() : "null";
+ String baseURI = desc.getDocumentBaseURI() != null ?
+ desc.getDocumentBaseURI() : "null";
+
+ getErrorReporter().reportError(
+ "WSDL500",
+ new Object[] {schemaURI, baseURI},
+ ErrorReporter.SEVERITY_ERROR);
+
+ return schemaImport;
+ }
+
+ if(schemaImport.getSchemaLocation() == null)
+ {
+ //no location URI so we cannot retrieve a schema
+ return schemaImport;
+ }
+
+ //Now try to retrieve the schema import using schemaLocation
- //TODO use SAX/DOM to get schema Element for this import
- //and call parseSchema method to get Schema object to pass
- //to the setSchema method. Or create and InputSource with
- //the schema loc URI and use XmlSchemaCollection.read.
- //schemaImport.setSchema(null);
+ Document importedSchemaDoc = null;
+ Element schemaEl = null;
+ URL url = null;
+
+ try
+ {
+ String contextURI = desc.getDocumentBaseURI();
+ URL contextURL = (contextURI != null) ?
+ StringUtils.getURL(null, contextURI) : null;
+ url = StringUtils.getURL(contextURL,
schemaImport.getSchemaLocation());
+
+ } catch (MalformedURLException e) {
+
+ String locURI = schemaImport.getSchemaLocation();
+ String baseURI = desc.getDocumentBaseURI() != null ?
+ desc.getDocumentBaseURI() : "null";
+
+ //the bad URL is a non-terminating error.
+ getErrorReporter().reportError("WSDL013",
+ new Object[] {baseURI, locURI},
+ ErrorReporter.SEVERITY_ERROR);
+ return schemaImport;
+ }
+
+ String schemaURL = url.toString();
+
+ try {
+ importedSchemaDoc = getDocument(new InputSource(schemaURL),
schemaURL);
+
+ } catch (IOException e4) {
+
+ //the failed retrieval is reported as a warning, not an error.
+ getErrorReporter().reportError(
+ "WSDL015", new Object[] {schemaURL},
ErrorReporter.SEVERITY_WARNING, e4);
+ return schemaImport;
+ }
+
+ schemaEl = importedSchemaDoc.getDocumentElement();
+ Schema schema = parseSchema(schemaEl, desc);
+
+ if(schema.getTargetNamespace() == null)
+ {
+ //Schema imported by WSDL must have a target namespace.
+ //(WSDL 2.0 W3C spec, Part 2: 3.1.1 'Importing XML Schema')
+
+ getErrorReporter().reportError(
+ "WSDL501", new Object[] {schemaURL},
ErrorReporter.SEVERITY_ERROR);
+ return schemaImport;
+ }
+
+ if(!schema.getTargetNamespace().equals(schemaImport.getNamespace()))
+ {
+ //The target namespace of the imported schema must match
+ //the namespace on the xs:import.
+ //(WSDL 2.0 W3C spec, Part 2: 3.1.1 'Importing XML Schema')
+
+ getErrorReporter().reportError(
+ "WSDL502",
+ new Object[] {schemaImport.getNamespace(),
+ schema.getTargetNamespace(),
+ schemaURL},
+ ErrorReporter.SEVERITY_ERROR);
+ return schemaImport;
+ }
+
+ schemaImport.setSchema(schema);
return schemaImport;
@@ -271,11 +445,11 @@
}
else if
(SchemaConstants.XSD_IMPORT_QNAME_LIST.contains(tempElType))
{
- types.addSchemaImport(parseSchemaImport(tempEl, types));
+ types.addSchemaImport(parseSchemaImport(tempEl, desc));
}
else if
(SchemaConstants.XSD_SCHEMA_QNAME_LIST.contains(tempElType))
{
- types.addSchema(parseSchema(tempEl, types));
+ types.addSchema(parseSchema(tempEl, desc));
}
else
{
@@ -310,8 +484,11 @@
}
}
- private Document getDocument(InputSource inputSource, String desc)
+ private Document getDocument(InputSource inputSource, String desc)
+ throws WSDLException, IOException
{
+ //TODO use 'desc' URL in any error message(s) for problem resolution.
+
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
@@ -324,20 +501,21 @@
DocumentBuilder builder = factory.newDocumentBuilder();
doc = builder.parse(inputSource);
- } catch (ParserConfigurationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (SAXException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
+ }
+ catch (ParserConfigurationException e)
+ {
+ String msg = getErrorReporter().getFormattedMessage("WSDL002", new
Object[] {"XML"});
+ throw new WSDLException(WSDLException.CONFIGURATION_ERROR, msg, e);
+ }
+ catch (SAXException e)
+ {
+ getErrorReporter().reportError(
+ "WSDL002", new Object[] {"SAX", desc},
ErrorReporter.SEVERITY_FATAL_ERROR, e);
+ }
//TODO - potentially returns null. correct after deciding how
//to handle exceptions (e.g. return inside try block).
return doc;
}
-
+
}
Modified: incubator/woden/java/src/org/apache/woden/internal/ErrorReporter.java
URL:
http://svn.apache.org/viewcvs/incubator/woden/java/src/org/apache/woden/internal/ErrorReporter.java?rev=291912&r1=291911&r2=291912&view=diff
==============================================================================
--- incubator/woden/java/src/org/apache/woden/internal/ErrorReporter.java
(original)
+++ incubator/woden/java/src/org/apache/woden/internal/ErrorReporter.java Tue
Sep 27 04:37:42 2005
@@ -224,7 +224,8 @@
String message = fMessageFormatter.formatMessage(fLocale, key,
arguments);
//TODO need to properly initialize ErrorInfo
- ErrorInfo errorInfo = new ErrorInfoImpl(null, null, 0, 0, key,
message);
+ ErrorInfo errorInfo =
+ new ErrorInfoImpl(null, null, 0, 0, key, message, targetException);
ErrorHandler eh =
(fErrorHandler != null) ? fErrorHandler : fDefaultErrorHandler;
@@ -246,15 +247,18 @@
//processing to continue after a fatal error and hence, the use of
the
//fContinueAfterFatalError flag.
- if(targetException != null) {
- throw new WSDLException(WSDLException.PARSER_ERROR,
- "Stopping due to XML parser error",
- targetException);
- } else {
+ if(targetException == null) {
throw new WSDLException(WSDLException.INVALID_WSDL,
- "Stopping due to WSDL processing error:\n" +
errorInfo.toString());
+ "Fatal WSDL error:\n" + errorInfo.toString());
+ }
+ else if(targetException instanceof WSDLException) {
+ throw (WSDLException)targetException;
+ }
+ else {
+ throw new WSDLException(WSDLException.OTHER_ERROR,
+ "Fatal error.",
+ targetException);
}
-
/*
* TODO fContinueAfterFatalError and related code has been
commented out for
Modified: incubator/woden/java/src/org/apache/woden/internal/Messages.properties
URL:
http://svn.apache.org/viewcvs/incubator/woden/java/src/org/apache/woden/internal/Messages.properties?rev=291912&r1=291911&r2=291912&view=diff
==============================================================================
--- incubator/woden/java/src/org/apache/woden/internal/Messages.properties
(original)
+++ incubator/woden/java/src/org/apache/woden/internal/Messages.properties Tue
Sep 27 04:37:42 2005
@@ -6,20 +6,43 @@
# Each message is keyed by a message number. The file is used as
# a ResourceBundle by Woden.
#
+# The messages are separated into two groups - those that relate
+# to System type problems (e.g. Woden or parser configuration)
+# and those that relate specifically to processing WSDL documents
+# (i.e. related to the rules defined in the WSDL spec). The
+# latter group of messages will eventually correspond to asserts
+# being added to the W3C WSDL spec and the message numbers will
+# be replaced with corresponding assert references.
+#
############################################################
-# TODO - create message keys that represent the point in the WSDL specification
-# that the error relates to (e.g. spec document & section no.)
-WSDL001=An error message.
-WSDL002=Another error message.
-WSDL003=Parameter test msg. The parms are {0} and {1}.
+# ------------SECTION 1: System errors -------------------------
+WSDL001=###Not used yet###
+WSDL002={0} Parser configuration error.
+WSDL003={0} Runtime parsing error.
WSDL004=Expected a "{0}" element, but found a "{1}" element instead.
WSDL005=The feature name must not be null when attempting to get or set a
named feature.
WSDL006=The feature name "{0}" is not recognized.
WSDL007=The property name must not be null when attempting to get or set a
named property.
WSDL008=The property name "{0}" is not recognized.
+WSDL009=###Not used yet###
+WSDL013=Could not create a URL from context URI "{0}" and location URI "{1}".
+WSDL014=Could not locate the WSDL document at URL "{0}".
+WSDL015=Could not locate the schema document at URL "{0}"
+# ------------SECTION 2: WSDL-related errors -------------------
-############### End of Messages ############################
\ No newline at end of file
+# TODO - replace WSDL5xx error codes with reference numbers from the asserts
+# to be defined in the WSDL spec (i.e. err msg nos. that point to the
+# specific part of the WSDL spec that the error relates to).
+
+
+WSDL500=The namespace attribute is missing from a schema import element
<xs:import>. The schemaLocation attribute is "{0}". The base document URI of
the importing WSDL is "{1}".
+WSDL501=The XML schema imported from "{0}" must specify a target namespace.
+WSDL502=The namespace "{0}" specified on the schema import element must match
the target namespace "{1}" of the schema imported from "{2}".
+
+
+
+------------------- End of Messages ----------------------------
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]