Author: lmandel
Date: Tue Dec 6 15:03:26 2005
New Revision: 354602
URL: http://svn.apache.org/viewcvs?rev=354602&view=rev
Log:
Updated document builder to require Xerces. Xerces is necessary for schema
validation of WSDL 2.0 documents. This should be modified post M2 to support
any parser and warn of no schema validation.
Modified:
incubator/woden/java/src/org/apache/woden/internal/DOMWSDLReader.java
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=354602&r1=354601&r2=354602&view=diff
==============================================================================
--- incubator/woden/java/src/org/apache/woden/internal/DOMWSDLReader.java
(original)
+++ incubator/woden/java/src/org/apache/woden/internal/DOMWSDLReader.java Tue
Dec 6 15:03:26 2005
@@ -26,9 +26,6 @@
import java.util.Map;
import javax.xml.namespace.QName;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
import org.apache.woden.ErrorReporter;
import org.apache.woden.WSDLException;
@@ -75,6 +72,7 @@
import org.apache.woden.xml.XMLAttr;
import org.apache.ws.commons.schema.XmlSchema;
import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.xerces.parsers.DOMParser;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -84,6 +82,9 @@
import org.w3c.dom.Text;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
+import org.xml.sax.SAXNotRecognizedException;
+import org.xml.sax.SAXNotSupportedException;
+import org.xml.sax.SAXParseException;
/**
* Implements the WSDLReader behaviour for DOM-based parsing.
@@ -1576,34 +1577,67 @@
{
//TODO use 'desc' URL in any error message(s) for problem resolution.
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-
- factory.setNamespaceAware(true);
+// DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
+//
+// factory.setNamespaceAware(true);
+
+ DOMParser parser = new DOMParser();
+ try
+ {
+ parser.setFeature("http://xml.org/sax/features/namespaces",
true);
+
parser.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
+ }
+ catch(SAXNotRecognizedException e)
+ {
+
+ }
+ catch(SAXNotSupportedException e)
+ {
+
+ }
// Enable validation on the XML parser if it has been enabled
// for the Woden parser.
if(features.getValue(ReaderFeatures.VALIDATION_FEATURE_ID))
{
- factory.setValidating(true);
+ //factory.setValidating(true);
+ try
+ {
+
parser.setFeature("http://xml.org/sax/features/validation", true);
+
parser.setFeature("http://apache.org/xml/features/validation/schema", true);
+ }
+ catch(SAXNotRecognizedException e)
+ {
+ System.out.println("validation not supported by parser.");
+ }
+ catch(SAXNotSupportedException e)
+ {
+
+ }
}
else
{
- factory.setValidating(false);
+ //factory.setValidating(false);
}
Document doc = null;
try {
+
+ //DocumentBuilder builder = factory.newDocumentBuilder();
+ //builder.getDOMImplementation().hasFeature();
+ //builder.setErrorHandler(new
ErrorHandlerWrapper(getErrorReporter()));
+ //builder.setEntityResolver(new DefaultHandler());
+ //doc = builder.parse(inputSource);
+ parser.parse(inputSource);
+ doc = parser.getDocument();
- DocumentBuilder builder = factory.newDocumentBuilder();
- doc = builder.parse(inputSource);
-
- }
- catch (ParserConfigurationException e)
- {
- String msg = getErrorReporter().getFormattedMessage("WSDL002", new
Object[] {"XML"});
- throw new WSDLException(WSDLException.CONFIGURATION_ERROR, msg, e);
}
+// catch (ParserConfigurationException e)
+// {
+// String msg = getErrorReporter().getFormattedMessage("WSDL002",
new Object[] {"XML"});
+// throw new WSDLException(WSDLException.CONFIGURATION_ERROR, msg,
e);
+// }
catch (SAXException e)
{
getErrorReporter().reportError(
@@ -1641,6 +1675,97 @@
}
}
return uri;
+ }
+
+ /**
+ * A wrapper that plugs Woden's error reporter mechanism into the
+ * XML parser used to parse the WSDL document.
+ */
+ class ErrorHandlerWrapper implements org.xml.sax.ErrorHandler
+ {
+ /**
+ * The error reporter used to report errors in Woden.
+ */
+ private ErrorReporter errorReporter;
+
+ /**
+ * Constructor.
+ *
+ * @param errorReporter The error reporter to be wrapped.
+ */
+ public ErrorHandlerWrapper(ErrorReporter errorReporter)
+ {
+ this.errorReporter = errorReporter;
+ }
+
+ /* (non-Javadoc)
+ * @see
org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException)
+ */
+ public void error(SAXParseException error) throws SAXException
+ {
+ ErrorLocatorImpl locator = new ErrorLocatorImpl();
+ locator.setLineNumber(error.getLineNumber());
+ locator.setColumnNumber(error.getColumnNumber());
+ try
+ {
+ errorReporter.reportError(locator, null,
error.getMessage(), ErrorReporter.SEVERITY_ERROR, error.getException());
+ }
+ catch(WSDLException e)
+ {
+ throw new SAXException("A problem occurred
setting the error in the Woden error reporter wrapper.", e);
+ }
+
+ }
+
+ /* (non-Javadoc)
+ * @see
org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException)
+ */
+ public void fatalError(SAXParseException error) throws
SAXException
+ {
+ ErrorLocatorImpl locator = new ErrorLocatorImpl();
+ locator.setLineNumber(error.getLineNumber());
+ locator.setColumnNumber(error.getColumnNumber());
+ try
+ {
+ errorReporter.reportError(locator, null,
error.getMessage(), ErrorReporter.SEVERITY_FATAL_ERROR, error.getException());
+ }
+ catch(WSDLException e)
+ {
+ throw new SAXException("A problem occurred
setting the error in the Woden error reporter wrapper.", e);
+ }
+
+ }
+
+ /* (non-Javadoc)
+ * @see
org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException)
+ */
+ public void warning(SAXParseException warning) throws
SAXException
+ {
+ ErrorLocatorImpl locator = new ErrorLocatorImpl();
+ locator.setLineNumber(warning.getLineNumber());
+ locator.setColumnNumber(warning.getColumnNumber());
+ try
+ {
+ errorReporter.reportError(locator, null,
warning.getMessage(), ErrorReporter.SEVERITY_WARNING, warning.getException());
+ }
+ catch(WSDLException e)
+ {
+ throw new SAXException("A problem occurred
setting the error in the Woden error reporter wrapper.", e);
+ }
+
+ }
+
+ }
+
+ class WSDLEntityResolver implements org.xml.sax.EntityResolver
+ {
+
+ public InputSource resolveEntity(String publicId, String
systemId) throws SAXException, IOException {
+ // TODO Auto-generated method stub
+
+ return null;
+ }
+
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]