You are viewing a plain text version of this content. The canonical link for it is here.
Posted to woden-dev@ws.apache.org by sa...@apache.org on 2009/09/16 17:25:48 UTC
svn commit: r815833 -
/webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/DOMWSDLReader.java
Author: sagara
Date: Wed Sep 16 15:25:45 2009
New Revision: 815833
URL: http://svn.apache.org/viewvc?rev=815833&view=rev
Log:
fixed WODEN-152 - Woden shouldn't be dependent on Xerces
Modified:
webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/DOMWSDLReader.java
Modified: webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/DOMWSDLReader.java
URL: http://svn.apache.org/viewvc/webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/DOMWSDLReader.java?rev=815833&r1=815832&r2=815833&view=diff
==============================================================================
--- webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/DOMWSDLReader.java (original)
+++ webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/DOMWSDLReader.java Wed Sep 16 15:25:45 2009
@@ -25,7 +25,9 @@
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;
@@ -57,15 +59,14 @@
import org.apache.ws.commons.schema.XmlSchema;
import org.apache.ws.commons.schema.XmlSchemaCollection;
import org.apache.ws.commons.schema.XmlSchemaException;
-import org.apache.xerces.parsers.DOMParser;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.ErrorHandler;
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;
/**
@@ -77,6 +78,30 @@
private static final String emptyString = "".intern();
+ static final String JAXP_SCHEMA_LANGUAGE =
+ "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
+
+ static final String W3C_XML_SCHEMA =
+ "http://www.w3.org/2001/XMLSchema";
+
+ static final String JAXP_SCHEMA_SOURCE =
+ "http://java.sun.com/xml/jaxp/properties/schemaSource";
+
+ // TODO: This external schema location should be removed once an URI resolution framework
+ // with a catalog is added to Woden.
+ static final String WSDL120_SCHEMA_SOURCE =
+ "http://www.w3.org/2007/03/wsdl/wsdl20.xsd";
+ static final String WSDL120_EXTENSIONS_SCHEMA_SOURCE =
+ "http://www.w3.org/2007/03/wsdl/wsdl20-extensions.xsd";
+ static final String W3C_XML_SCHEMA_SCHEMA_SOURCE =
+ "http://www.w3.org/2001/XMLSchema.xsd";
+
+ static final String[] schemas = {
+ WSDL120_SCHEMA_SOURCE,
+ WSDL120_EXTENSIONS_SCHEMA_SOURCE,
+ W3C_XML_SCHEMA_SCHEMA_SOURCE,
+ };
+
//a map of imported schema definitions keyed by schema location URI
private Map fImportedSchemas = new Hashtable();
@@ -669,88 +694,110 @@
return schemaDef;
}
- private Document getDocument(InputSource inputSource, String desc)
- throws WSDLException, IOException
- {
+ // replaced with JAXP API
+ /*
+ 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);
-
+
+ //DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ //
+ //factory.setNamespaceAware(true);
+
DOMParser parser = new DOMParser();
parser.setEntityResolver(new EntityResolverAdapter(getURIResolver()));
-
- try
- {
- parser.setFeature(org.apache.xerces.impl.Constants.SAX_FEATURE_PREFIX + org.apache.xerces.impl.Constants.NAMESPACES_FEATURE, true);
- parser.setFeature(org.apache.xerces.impl.Constants.SAX_FEATURE_PREFIX + org.apache.xerces.impl.Constants.NAMESPACE_PREFIXES_FEATURE, true);
- }
- catch(SAXNotRecognizedException e)
- {
-
- }
- catch(SAXNotSupportedException e)
- {
-
+
+ try {
+ parser.setFeature(org.apache.xerces.impl.Constants.SAX_FEATURE_PREFIX
+ + org.apache.xerces.impl.Constants.NAMESPACES_FEATURE, true);
+ parser.setFeature(org.apache.xerces.impl.Constants.SAX_FEATURE_PREFIX
+ + org.apache.xerces.impl.Constants.NAMESPACE_PREFIXES_FEATURE, 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(WSDLReader.FEATURE_VALIDATION))
- {
- //factory.setValidating(true);
- try
- {
- parser.setFeature(org.apache.xerces.impl.Constants.SAX_FEATURE_PREFIX + org.apache.xerces.impl.Constants.VALIDATION_FEATURE, true);
- parser.setFeature(org.apache.xerces.impl.Constants.XERCES_FEATURE_PREFIX + org.apache.xerces.impl.Constants.SCHEMA_VALIDATION_FEATURE, true);
- // TODO: This external schema location should be removed once an URI resolution framework
- // with a catalog is added to Woden.
-
- parser.setProperty(org.apache.xerces.impl.Constants.XERCES_PROPERTY_PREFIX + org.apache.xerces.impl.Constants.SCHEMA_LOCATION, "http://www.w3.org/ns/wsdl " + resolveURI("http://www.w3.org/2007/03/wsdl/wsdl20.xsd") + " http://www.w3.org/ns/wsdl-extensions " + resolveURI("http://www.w3.org/2007/03/wsdl/wsdl20-extensions.xsd") + " http://www.w3.org/2001/XMLSchema " + resolveURI("http://www.w3.org/2001/XMLSchema.xsd"));
- }
- catch(SAXNotRecognizedException e)
- {
- System.out.println("validation not supported by parser.");
- }
- catch(SAXNotSupportedException e)
- {
-
+ if (features.getValue(WSDLReader.FEATURE_VALIDATION)) {
+ //factory.setValidating(true);
+ try {
+ parser.setFeature(org.apache.xerces.impl.Constants.SAX_FEATURE_PREFIX
+ + org.apache.xerces.impl.Constants.VALIDATION_FEATURE, true);
+ parser.setFeature(org.apache.xerces.impl.Constants.XERCES_FEATURE_PREFIX
+ + org.apache.xerces.impl.Constants.SCHEMA_VALIDATION_FEATURE, true);
+ // TODO: This external schema location should be removed once an URI resolution framework
+ // with a catalog is added to Woden.
+
+ parser
+ .setProperty(
+ org.apache.xerces.impl.Constants.XERCES_PROPERTY_PREFIX
+ + org.apache.xerces.impl.Constants.SCHEMA_LOCATION,
+ "http://www.w3.org/ns/wsdl "
+ + resolveURI("http://www.w3.org/2007/03/wsdl/wsdl20.xsd")
+ + " http://www.w3.org/ns/wsdl-extensions "
+ + resolveURI("http://www.w3.org/2007/03/wsdl/wsdl20-extensions.xsd")
+ + " http://www.w3.org/2001/XMLSchema "
+ + resolveURI("http://www.w3.org/2001/XMLSchema.xsd"));
+ } catch (SAXNotRecognizedException e) {
+ System.out.println("validation not supported by parser.");
+ } catch (SAXNotSupportedException e) {
+
}
+ } else {
+ //factory.setValidating(false);
}
- else
- {
- //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();
-
- }
-// catch (ParserConfigurationException e)
-// {
-// String msg = getErrorReporter().getFormattedMessage("WSDL002", new Object[] {"XML"});
-// throw new WSDLException(WSDLException.CONFIGURATION_ERROR, msg, e);
-// }
- catch (SAXException e)
- {
- getErrorReporter().reportError(
- new ErrorLocatorImpl(), //TODO line&col nos.
- "WSDL500",
- new Object[] {"SAX", desc},
- ErrorReporter.SEVERITY_FATAL_ERROR,
- e);
- }
-
+ parser.parse(inputSource);
+ doc = parser.getDocument();
+
+ }
+ //catch (ParserConfigurationException e)
+ //{
+ //String msg = getErrorReporter().getFormattedMessage("WSDL002", new Object[] {"XML"});
+ //throw new WSDLException(WSDLException.CONFIGURATION_ERROR, msg, e);
+ //}
+ catch (SAXException e) {
+ getErrorReporter().reportError(new ErrorLocatorImpl(), //TODO line&col nos.
+ "WSDL500", 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;
+ }
+
+ */
+
+ private Document getDocument(InputSource inputSource, String desc) throws WSDLException,
+ IOException {
+ //TODO use 'desc' URL in any error message(s) for problem resolution.
+ Document doc = null;
+ try {
+ DocumentBuilderFactory factory = createDocumentBuilderFactory(true);
+ EntityResolverAdapter entityResolver = new EntityResolverAdapter(getURIResolver());
+ ErrorHandler errorHandler = new ErrorHandlerWrapper(getErrorReporter());
+ DocumentBuilder builder = createDocumentBuilder(factory, entityResolver, errorHandler);
+ doc = builder.parse(inputSource);
+
+ } catch (ParserConfigurationException e) {
+ String msg = getErrorReporter().getFormattedMessage("WSDL002", new Object[] { "XML" });
+ throw new WSDLException(WSDLException.CONFIGURATION_ERROR, msg, e);
+ } catch (SAXException e) {
+ getErrorReporter().reportError(new ErrorLocatorImpl(), //TODO line&col nos.
+ "WSDL500", 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;
@@ -868,6 +915,66 @@
}
/**
+ * Create the JAXP DocumentBuilderFactory instance.Use JAXP 1.2 API for validation.
+ * @param namespaceAware whether the returned factory is to provide support for XML namespaces
+ * @return the JAXP DocumentBuilderFactory
+ * @throws ParserConfigurationException if we failed to build a proper DocumentBuilderFactory
+ */
+ protected DocumentBuilderFactory createDocumentBuilderFactory(boolean namespaceAware)
+ throws ParserConfigurationException, WSDLException {
+
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setNamespaceAware(namespaceAware);
+
+ // Enable validation on the XML parser if it has been enabled
+ // for the Woden parser.
+ if (features.getValue(WSDLReader.FEATURE_VALIDATION)) {
+ factory.setValidating(true);
+ // Enforce namespace aware for XSD...
+ factory.setNamespaceAware(true);
+ try {
+ factory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
+ factory.setAttribute(JAXP_SCHEMA_SOURCE, schemas);
+
+ } catch (IllegalArgumentException e) {
+ getErrorReporter().reportError(
+ new ErrorLocatorImpl(), //TODO line&col nos.
+ "WSDL515",
+ new Object[] {factory.getClass().getName()},
+ ErrorReporter.SEVERITY_FATAL_ERROR,
+ e);
+ }
+ }else{
+ factory.setValidating(false);
+ }
+
+ return factory;
+ }
+
+ /**
+ * Create a JAXP DocumentBuilder will use for parsing XML documents.
+ * @param factory the JAXP DocumentBuilderFactory that the DocumentBuilder
+ * should be created with
+ * @param entityResolver the SAX EntityResolver to use
+ * @param errorHandler the SAX ErrorHandler to use
+ * @return the JAXP DocumentBuilder
+ * @throws ParserConfigurationException if thrown by JAXP methods
+ */
+ protected DocumentBuilder createDocumentBuilder(DocumentBuilderFactory factory,
+ EntityResolver entityResolver, ErrorHandler errorHandler)
+ throws ParserConfigurationException {
+
+ DocumentBuilder docBuilder = factory.newDocumentBuilder();
+ if (entityResolver != null) {
+ docBuilder.setEntityResolver(entityResolver);
+ }
+ if (errorHandler != null) {
+ docBuilder.setErrorHandler(errorHandler);
+ }
+ return docBuilder;
+ }
+
+ /**
* A wrapper that plugs Woden's error reporter mechanism into the
* XML parser used to parse the WSDL document.
*/
---------------------------------------------------------------------
To unsubscribe, e-mail: woden-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: woden-dev-help@ws.apache.org