Author: jkaputin
Date: Wed Jun 7 08:04:51 2006
New Revision: 412421
URL: http://svn.apache.org/viewvc?rev=412421&view=rev
Log:
Initial commit of WSDLSource and new WSDLReader methods
that take a WSDLSource arg. Also add a new error to
Messages.properties and a testcase for WSDLReader.
Added:
incubator/woden/java/src/org/apache/woden/WSDLSource.java
Modified:
incubator/woden/java/src/org/apache/woden/WSDLReader.java
incubator/woden/java/src/org/apache/woden/internal/DOMWSDLReader.java
incubator/woden/java/src/org/apache/woden/internal/Messages.properties
incubator/woden/java/test/org/apache/woden/WSDLReaderTest.java
Modified: incubator/woden/java/src/org/apache/woden/WSDLReader.java
URL:
http://svn.apache.org/viewvc/incubator/woden/java/src/org/apache/woden/WSDLReader.java?rev=412421&r1=412420&r2=412421&view=diff
==============================================================================
--- incubator/woden/java/src/org/apache/woden/WSDLReader.java (original)
+++ incubator/woden/java/src/org/apache/woden/WSDLReader.java Wed Jun 7
08:04:51 2006
@@ -32,7 +32,7 @@
* feature will be turned on or off with a boolean. A named property will be
* set with some object representing the property value.
*
- * @author [EMAIL PROTECTED]
+ * @author John Kaputin ([EMAIL PROTECTED])
*/
public interface WSDLReader {
@@ -135,6 +135,47 @@
* for checked exceptions.
*/
public DescriptionElement readWSDL(String wsdlURI, ErrorHandler
errorHandler) throws WSDLException;
+
+ /**
+ * Read the WSDL document contained in the specified WSDLSource object.
+ * The WSDLSource must contain the WSDL in a format compatible with the
+ * concrete WSDLReader implementation.
+ * <p>
+ * For example, if the WSDLReader implementation is Woden's DOMWSDLReader
+ * then the WSDLSource may contain a DOM Element or Document representing
+ * the <wsdl:description> element.
+ * <p>
+ * TODO update this Javadoc comment at development of WSDLSource
progresses.
+ *
+ * @param wsdlURI the URI of the base WSDL document
+ * @param wsdlSource contains an object representing the WSDL
+ * @return the DescriptionElement representing the parsed WSDL
+ * @throws WSDLException for terminating errors and as a wrapper
+ * for checked exceptions
+ */
+ public DescriptionElement readWSDL(String wsdlURI, WSDLSource wsdlSource)
throws WSDLException;
+
+ /**
+ * Read the WSDL document contained in the specified WSDLSource object,
+ * using the specified custom ErrorHandler to report any errors.
+ * The WSDLSource must contain the WSDL in a format compatible with the
+ * concrete WSDLReader implementation.
+ * <p>
+ * For example, if the WSDLReader implementation is Woden's DOMWSDLReader
+ * then the WSDLSource may contain a DOM Element or Document representing
+ * the <wsdl:description> element.
+ * <p>
+ * TODO update this Javadoc comment at development of WSDLSource
progresses.
+ *
+ * @param wsdlURI the URI of the base WSDL document
+ * @param wsdlSource contains an object representing the WSDL
+ * @param errorHandler a custom error handler that overrides the default
handler
+ * @return the DescriptionElement representing the parsed WSDL
+ * @throws WSDLException for terminating errors and as a wrapper
+ * for checked exceptions
+ */
+ public DescriptionElement readWSDL(String wsdlURI, WSDLSource wsdlsource,
ErrorHandler errorHandler) throws WSDLException;
+
//TODO - a readWSDL method that returns a Description (eg a component)
/**
Added: incubator/woden/java/src/org/apache/woden/WSDLSource.java
URL:
http://svn.apache.org/viewvc/incubator/woden/java/src/org/apache/woden/WSDLSource.java?rev=412421&view=auto
==============================================================================
--- incubator/woden/java/src/org/apache/woden/WSDLSource.java (added)
+++ incubator/woden/java/src/org/apache/woden/WSDLSource.java Wed Jun 7
08:04:51 2006
@@ -0,0 +1,66 @@
+/**
+ * Copyright 2006 Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.woden;
+
+/**
+ * This class represents WSDL in some format to be interpreted
+ * by the WSDLReader implementation . It is a wrapper that permits
+ * WSDL in various forms to be passed to the WSDLReader without making the
+ * WSDLReader API dependent on any particular XML parser or XML object model.
+ * <p>
+ * Initially, at the Woden Milestone 5 release, this class represents the
+ * WSDL source as a java.lang.Object, without type safety. This is
+ * a temporary 'placeholder' to allow Woden's early adopters to read
+ * WSDL from a DOM Element or Document by passing an org.w3c.dom.Element
+ * or org.w3c.dom.Document to the WSDLSource constructor, then passing the
+ * WSDLSource object to a readWSDL method on the WSDLReader.
+ * <p>
+ * For Example, using the WSDLReader.readWSDL(String, WSDLSource) method:
+ * <pre>
+ * //wsdlUri is the URI string of the base wsdl document.
+ *
+ * //myDOMElement is an org.w3c.dom.Element representing a WSDL description
element.
+ * myWSDLReader.readWSDL(wsdlUri, new WSDLSource(myDOMElement);
+ *
+ * //myDOMDocument is an org.w3c.dom.Document representing a WSDL document.
+ * myWSDLReader.readWSDL(wsdlUri, new WSDLSource(myDOMDocument);
+ * </pre>
+ * Pending further consideration about support for different XML
+ * parsers and how to represent this support in the API, this WSDLSource
+ * class will be developed further, possibly even changing it to an
+ * interface with the concrete implemention determined by the WSDLFactory.
+ * The intention is that WSDLReader.readWSDL(WSDLSource) will remain in the
+ * Woden API, but the interface and underlying behaviour of WSDLSource
+ * may be developed further.
+ * <p>
+ * TODO consider how to use this class to support multiple XML parsing
strategies
+ * in the Woden API without introducing parser or XML API dependencies (post
M5).
+ *
+ * @author John Kaputin ([EMAIL PROTECTED])
+ */
+public class WSDLSource {
+
+ private Object fSource = null;
+
+ public WSDLSource(Object source) {
+ fSource = source;
+ }
+
+ public Object getSource() {
+ return fSource;
+ }
+
+}
Modified: incubator/woden/java/src/org/apache/woden/internal/DOMWSDLReader.java
URL:
http://svn.apache.org/viewvc/incubator/woden/java/src/org/apache/woden/internal/DOMWSDLReader.java?rev=412421&r1=412420&r2=412421&view=diff
==============================================================================
--- incubator/woden/java/src/org/apache/woden/internal/DOMWSDLReader.java
(original)
+++ incubator/woden/java/src/org/apache/woden/internal/DOMWSDLReader.java Wed
Jun 7 08:04:51 2006
@@ -33,6 +33,7 @@
import org.apache.woden.ErrorReporter;
import org.apache.woden.WSDLException;
import org.apache.woden.WSDLReader;
+import org.apache.woden.WSDLSource;
import org.apache.woden.internal.schema.ImportedSchemaImpl;
import org.apache.woden.internal.schema.InlinedSchemaImpl;
import org.apache.woden.internal.schema.SchemaConstants;
@@ -91,7 +92,7 @@
/**
* Implements the WSDLReader behaviour for DOM-based parsing.
*
- * @author [EMAIL PROTECTED]
+ * @author John Kaputin ([EMAIL PROTECTED])
*/
public class DOMWSDLReader extends BaseWSDLReader {
@@ -124,8 +125,6 @@
public DescriptionElement readWSDL(String wsdlURI) throws WSDLException
{
try {
- //System.out.println("readWSDL at " + wsdlURI);
-
//TODO add WSDL locator for resolving URIs
URL url = StringUtils.getURL(null, wsdlURI);
@@ -181,6 +180,85 @@
getErrorReporter().setErrorHandler(errorHandler);
return readWSDL(wsdlURI);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.woden.WSDLReader#readWSDL(java.lang.String,
org.apache.woden.WSDLSource)
+ */
+ public DescriptionElement readWSDL(String wsdlURI, WSDLSource wsdlSource)
throws WSDLException {
+
+ //TODO decide on how to handle null args in readWSDL methods (e.g.
+ //IllegalArgExc, WSDLExc, return null, etc).
+
+ Object source = wsdlSource.getSource();
+
+ if(source instanceof Element) {
+ return readWSDL(wsdlURI, (Element)source);
+ }
+ else if(source instanceof Document) {
+ return readWSDL(wsdlURI, (Document)source);
+ }
+ else {
+ String sourceClass = source.getClass().getName();
+ String readerClass = this.getClass().getName();
+ String msg = getErrorReporter().getFormattedMessage(
+ "WSDL017", new Object[] {sourceClass, readerClass});
+ throw new WSDLException(WSDLException.PARSER_ERROR, msg);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.woden.WSDLReader#readWSDL(java.lang.String,
org.apache.woden.WSDLSource, org.apache.woden.ErrorHandler)
+ */
+ public DescriptionElement readWSDL(String wsdlURI, WSDLSource wsdlSource,
ErrorHandler errorHandler)
+ throws WSDLException {
+
+ if(errorHandler != null)
+ getErrorReporter().setErrorHandler(errorHandler);
+
+ return readWSDL(wsdlURI, wsdlSource);
+ }
+
+ private DescriptionElement readWSDL(String wsdlURI, Element docEl)
+ throws WSDLException {
+
+ URL url;
+ try {
+ url = StringUtils.getURL(null, wsdlURI);
+ } catch (MalformedURLException e) {
+
+ String msg = getErrorReporter().getFormattedMessage(
+ "WSDL502", new Object[] {null, wsdlURI});
+ throw new WSDLException(WSDLException.PARSER_ERROR, msg, e);
+
+ }
+ String wsdlURL = url.toString();
+
+ DescriptionElement desc = parseDescription(wsdlURL, docEl, null);
+
+ // Validate the model if validation is enabled.
+ if(features.getValue(WSDLReader.FEATURE_VALIDATION))
+ {
+ if(docValidator == null)
+ {
+ docValidator = new WSDLDocumentValidator();
+ }
+ if(docValidator.validate(desc, getErrorReporter()))
+ {
+ if(compValidator == null)
+ {
+ compValidator = new WSDLComponentValidator();
+ }
+ compValidator.validate(desc.toComponent(), getErrorReporter());
+ }
+ }
+ return desc;
+ }
+
+ private DescriptionElement readWSDL(String wsdlURI, Document domDoc)
+ throws WSDLException {
+
+ return readWSDL(wsdlURI, domDoc.getDocumentElement());
}
/* ************************************************************
Modified: incubator/woden/java/src/org/apache/woden/internal/Messages.properties
URL:
http://svn.apache.org/viewvc/incubator/woden/java/src/org/apache/woden/internal/Messages.properties?rev=412421&r1=412420&r2=412421&view=diff
==============================================================================
--- incubator/woden/java/src/org/apache/woden/internal/Messages.properties
(original)
+++ incubator/woden/java/src/org/apache/woden/internal/Messages.properties Wed
Jun 7 08:04:51 2006
@@ -50,6 +50,7 @@
WSDL014=No Extension Registry was set on the DescriptionElement so cannot
handle the extension element "{0}" in the context of "{1}".
WSDL015=The extension namespace "{0}" in the context of "{1}" does not have a
Java class registered.
WSDL016=The Java class "{0}" does not implement the "ComponentExtensions"
interface.
+WSDL017=The Java class "{0}" representing the WSDL source is not compatible
with the WSDLReader implementation class "{1}".
# ------------ Parsing errors -------------------
Modified: incubator/woden/java/test/org/apache/woden/WSDLReaderTest.java
URL:
http://svn.apache.org/viewvc/incubator/woden/java/test/org/apache/woden/WSDLReaderTest.java?rev=412421&r1=412420&r2=412421&view=diff
==============================================================================
--- incubator/woden/java/test/org/apache/woden/WSDLReaderTest.java (original)
+++ incubator/woden/java/test/org/apache/woden/WSDLReaderTest.java Wed Jun 7
08:04:51 2006
@@ -15,14 +15,23 @@
*/
package org.apache.woden;
+import java.io.IOException;
import java.net.URL;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.FactoryConfigurationError;
+import javax.xml.parsers.ParserConfigurationException;
+
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.woden.tests.TestErrorHandler;
import org.apache.woden.wsdl20.xml.DescriptionElement;
+import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
public class WSDLReaderTest extends TestCase
{
@@ -83,6 +92,39 @@
assertTrue("Expected a WSDLException with message containing
\"WSDL501\", but got: " + e.getMessage() ,
e.getMessage().indexOf("WSDL501") > -1);
}
+ }
+
+ public void testReadWSDLSource()
+ {
+ DescriptionElement desc = null;
+ try
+ {
+ URL wsdlURL =
getClass().getClassLoader().getResource("org/apache/woden/primer-hotelReservationService.wsdl");
+ String wsdlURLStr = wsdlURL.toString();
+
+ Document doc = null;
+ try {
+ DocumentBuilderFactory dbFactory =
DocumentBuilderFactory.newInstance();
+ dbFactory.setNamespaceAware(true);
+ DocumentBuilder builder = dbFactory.newDocumentBuilder();
+ doc = builder.parse(new InputSource(wsdlURLStr));
+ } catch (FactoryConfigurationError e1) {
+ fail("Unexpected exception: " + e1.getMessage());
+ } catch (ParserConfigurationException e1) {
+ fail("Unexpected exception: " + e1.getMessage());
+ } catch (SAXException e1) {
+ fail("Unexpected exception: " + e1.getMessage());
+ } catch (IOException e1) {
+ fail("Unexpected exception: " + e1.getMessage());
+ }
+
+ desc = reader.readWSDL(wsdlURLStr, new WSDLSource(doc), handler);
+ }
+ catch(WSDLException e)
+ {
+ fail("Unexpected exception: " + e.getMessage());
+ }
+ assertNotNull("The description returned is null.", desc);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]