Author: jkaputin
Date: Wed Jun  7 13:38:40 2006
New Revision: 412530

URL: http://svn.apache.org/viewvc?rev=412530&view=rev
Log:
Changed WSDLSource from a class to an interface and did
intial commit of implementations in BaseWSDLSource and
DOMWSDLSource. Modified WSDLReader and DOMWSDLReader to
support new WSDLSource usage and updated Javadoc
to reflect this approach. Also update the test case.

Added:
    incubator/woden/java/src/org/apache/woden/internal/BaseWSDLSource.java
    incubator/woden/java/src/org/apache/woden/internal/DOMWSDLSource.java
Modified:
    incubator/woden/java/src/org/apache/woden/WSDLReader.java
    incubator/woden/java/src/org/apache/woden/WSDLSource.java
    incubator/woden/java/src/org/apache/woden/internal/DOMWSDLReader.java
    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=412530&r1=412529&r2=412530&view=diff
==============================================================================
--- incubator/woden/java/src/org/apache/woden/WSDLReader.java (original)
+++ incubator/woden/java/src/org/apache/woden/WSDLReader.java Wed Jun  7 
13:38:40 2006
@@ -147,13 +147,12 @@
      * <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;
+    public DescriptionElement readWSDL(WSDLSource wsdlSource) throws 
WSDLException;
     
     /**
      * Read the WSDL document contained in the specified WSDLSource object,
@@ -167,16 +166,27 @@
      * <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;
+    public DescriptionElement readWSDL(WSDLSource wsdlsource, ErrorHandler 
errorHandler) throws WSDLException;
    
     //TODO - a readWSDL method that returns a Description (eg a component)
+    
+    /**
+     * Returns a concrete implementation of WSDLSource that is compatible with
+     * the WSDLReader implementation. That is, it will accept objects 
representing
+     * WSDL source in formats that the WSDLReader implementation can 
understand.
+     * For example, a DOM-based implementation of WSDLReader will return a DOM-
+     * based implementation of WSDLSource that accepts WSDL source as a DOM
+     * Element or Document.
+     * 
+     * @return the WSDLSource class compatible with the WSDLReader 
implementation.
+     */
+    public WSDLSource createWSDLSource();
     
     /**
      * @return the ErrorReporter used by this reader

Modified: 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=412530&r1=412529&r2=412530&view=diff
==============================================================================
--- incubator/woden/java/src/org/apache/woden/WSDLSource.java (original)
+++ incubator/woden/java/src/org/apache/woden/WSDLSource.java Wed Jun  7 
13:38:40 2006
@@ -15,52 +15,50 @@
  */
 package org.apache.woden;
 
+import java.net.URI;
+
 /**
- * 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.
+ * This interface represents WSDL source in a format to be interpreted by the 
+ * WSDLReader implementation. It permits WSDL source 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>
+ * Each concrete implementation of WSDLReader will have a concrete 
implementation
+ * of WSDLSource that can handle the types of WSDL source formats that are
+ * compatible with the WSDLReader implementation. For example, a DOM-based 
+ * implementation of WSDLReader will return a DOM-based implementation of 
+ * WSDLSource via its <code>WSDLReader.createWSDLSource</code> method and this
+ * DOM-based WSDLSource implemenation will accept as WSDL source an
+ * org.w3c.dom.Element or org.w3c.dom.Document object via its
+ * <code>WSDLSource.setSource</code> method.
  * <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.
+ * The WSDL source is set via the <code>setSource(java.lang.Object)</code>
+ * method. Runtime type safety should be provided in the implementation of 
+ * the <code>setSource</code> method, which should check that the Object 
+ * argument is of a type compatible with the WSDLReader implementation that 
+ * created the WSDLSource object.
  * <p>
- * For Example, using the WSDLReader.readWSDL(String, WSDLSource) method:
+ * Programming example:
  * <pre>
- *   //wsdlUri is the URI string of the base wsdl document.
+ *   //wsdlURI is the URI of the base wsdl document.
+ *   //domReader is an instance of DOMWSDLReader
+ *   //domElement is an org.w3c.dom.Element representing a description element.
  * 
- *   //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);
+ *   WSDLSource wsdlSource = domReader.createWSDLSource();
+ *   wsdlSource.setBaseURI(wsdlURI);
+ *   wsdlSource.setSource(domElement);
+ *   DescriptionElement desc = reader.readWSDL(wsdlSource);
  * </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 {
+public interface WSDLSource {
     
-    private Object fSource = null;
+    public void setSource(Object wsdlSource) throws WSDLException;
     
-    public WSDLSource(Object source) {
-        fSource = source;
-    }
+    public Object getSource();
     
-    public Object getSource() {
-        return fSource;
-    }
-
+    public void setBaseURI(URI baseURI);
+    
+    public URI getBaseURI();
 }

Added: incubator/woden/java/src/org/apache/woden/internal/BaseWSDLSource.java
URL: 
http://svn.apache.org/viewvc/incubator/woden/java/src/org/apache/woden/internal/BaseWSDLSource.java?rev=412530&view=auto
==============================================================================
--- incubator/woden/java/src/org/apache/woden/internal/BaseWSDLSource.java 
(added)
+++ incubator/woden/java/src/org/apache/woden/internal/BaseWSDLSource.java Wed 
Jun  7 13:38:40 2006
@@ -0,0 +1,68 @@
+/**
+ * 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.internal;
+
+import java.net.URI;
+
+import org.apache.woden.ErrorReporter;
+import org.apache.woden.WSDLException;
+import org.apache.woden.WSDLSource;
+
+/**
+ * This abstract class implements methods of the WSDLSource interface that are
+ * common across all concrete implementations. The only method on this 
interface
+ * that is specific to each concrete implementation is the 
<code>setSource</code>
+ * method and this method is declared abstract on this class.
+ * 
+ * @author John Kaputin ([EMAIL PROTECTED])
+ */
+public abstract class BaseWSDLSource implements WSDLSource {
+    
+    private URI fBaseURI = null;
+    protected Object fSource = null;
+    protected ErrorReporter fErrorReporter = null;
+    
+    protected BaseWSDLSource(ErrorReporter errorReporter) {
+        fErrorReporter = errorReporter;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.woden.WSDLSource#setSource(java.lang.Object)
+     */
+    abstract public void setSource(Object wsdlSource) throws WSDLException;
+
+    /* (non-Javadoc)
+     * @see org.apache.woden.WSDLSource#getSource()
+     */
+    public Object getSource() {
+        return fSource;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.woden.WSDLSource#setBaseURI(java.net.URI)
+     */
+    public void setBaseURI(URI baseURI) {
+        fBaseURI = baseURI;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.woden.WSDLSource#getBaseURI()
+     */
+    public URI getBaseURI() {
+        return fBaseURI;
+    }
+
+}

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=412530&r1=412529&r2=412530&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 13:38:40 2006
@@ -117,7 +117,12 @@
      *  API public methods
      * ************************************************************/
     
-    //TODO add other types of readWSDL methods.
+    /* (non-Javadoc)
+     * @see org.apache.woden.WSDLReader#createWSDLSource()
+     */
+    public WSDLSource createWSDLSource() {
+        return new DOMWSDLSource(getErrorReporter());
+    }
     
     /*
      * @see org.apache.woden.WSDLReader#readWSDL(String)
@@ -183,22 +188,27 @@
     }
     
     /* (non-Javadoc)
-     * @see org.apache.woden.WSDLReader#readWSDL(java.lang.String, 
org.apache.woden.WSDLSource)
+     * @see org.apache.woden.WSDLReader#readWSDL(org.apache.woden.WSDLSource)
      */
-    public DescriptionElement readWSDL(String wsdlURI, WSDLSource wsdlSource) 
throws WSDLException {
+    public DescriptionElement readWSDL(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();
+        URI baseURI = wsdlSource.getBaseURI();
+        String baseURIStr = baseURI != null ? baseURI.toString() : null;
         
         if(source instanceof Element) {
-            return readWSDL(wsdlURI, (Element)source);
+            return readWSDL(baseURIStr, (Element)source);
         }
         else if(source instanceof Document) {
-            return readWSDL(wsdlURI, (Document)source);
+            return readWSDL(baseURIStr, (Document)source);
         }
         else {
+            //This exception is checked in WSDLSource.setSource but we check
+            //again here in case the wrong type of WSDLSource has been used
+            //with this type of WSDLReader.
             String sourceClass = source.getClass().getName();
             String readerClass = this.getClass().getName();
             String msg = getErrorReporter().getFormattedMessage(
@@ -208,17 +218,20 @@
     }
     
     /* (non-Javadoc)
-     * @see org.apache.woden.WSDLReader#readWSDL(java.lang.String, 
org.apache.woden.WSDLSource, org.apache.woden.ErrorHandler)
+     * @see org.apache.woden.WSDLReader#readWSDL(org.apache.woden.WSDLSource, 
org.apache.woden.ErrorHandler)
      */
-    public DescriptionElement readWSDL(String wsdlURI, WSDLSource wsdlSource, 
ErrorHandler errorHandler) 
+    public DescriptionElement readWSDL(WSDLSource wsdlSource, ErrorHandler 
errorHandler) 
         throws WSDLException {
         
         if(errorHandler != null)
             getErrorReporter().setErrorHandler(errorHandler);
         
-        return readWSDL(wsdlURI, wsdlSource);
+        return readWSDL(wsdlSource);
     }
     
+    /*
+     * Helper method for readWSDL(WSDLSource)
+     */
     private DescriptionElement readWSDL(String wsdlURI, Element docEl) 
         throws WSDLException {
         
@@ -255,11 +268,15 @@
         return desc;
     }
     
+    /*
+     * Helper method for readWSDL(WSDLSource)
+     */
     private DescriptionElement readWSDL(String wsdlURI, Document domDoc) 
         throws WSDLException {
         
         return readWSDL(wsdlURI, domDoc.getDocumentElement());
     }
+    
     
     /* ************************************************************
      *  Parsing methods - e.g. parseXXXX()

Added: incubator/woden/java/src/org/apache/woden/internal/DOMWSDLSource.java
URL: 
http://svn.apache.org/viewvc/incubator/woden/java/src/org/apache/woden/internal/DOMWSDLSource.java?rev=412530&view=auto
==============================================================================
--- incubator/woden/java/src/org/apache/woden/internal/DOMWSDLSource.java 
(added)
+++ incubator/woden/java/src/org/apache/woden/internal/DOMWSDLSource.java Wed 
Jun  7 13:38:40 2006
@@ -0,0 +1,59 @@
+/**
+ * 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.internal;
+
+import org.apache.woden.ErrorReporter;
+import org.apache.woden.WSDLException;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+
+/**
+ * This class provides a WSDLSource implementation that supports a
+ * DOM-based representation of the WSDL source. Specifically, it
+ * may accept via its <code>setSource</code> method an object of type
+ * org.w3c.dom.Element or org.w3c.dom.Document. Any other type of 
+ * object passed to this method will result in a WSDLException being 
+ * thrown.
+ * 
+ * @author John Kaputin ([EMAIL PROTECTED])
+ */
+public class DOMWSDLSource extends BaseWSDLSource {
+    
+    public DOMWSDLSource(ErrorReporter errorReporter) {
+        super(errorReporter);
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.woden.WSDLSource#setSource(java.lang.Object)
+     */
+    public void setSource(Object wsdlSource) throws WSDLException {
+        
+        //TODO check if any other types of wsdl source should be supported
+        if(wsdlSource instanceof Element ||
+           wsdlSource instanceof Document) {
+            fSource = wsdlSource;
+        }
+        else {
+            String sourceClass = wsdlSource.getClass().getName();
+            String readerClass = "DOMWSDLReader";
+            String msg = fErrorReporter.getFormattedMessage(
+                    "WSDL017", new Object[] {sourceClass, readerClass});
+            throw new WSDLException(WSDLException.PARSER_ERROR, msg);
+        }
+    }
+
+}

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=412530&r1=412529&r2=412530&view=diff
==============================================================================
--- incubator/woden/java/test/org/apache/woden/WSDLReaderTest.java (original)
+++ incubator/woden/java/test/org/apache/woden/WSDLReaderTest.java Wed Jun  7 
13:38:40 2006
@@ -16,6 +16,7 @@
 package org.apache.woden;
 
 import java.io.IOException;
+import java.net.URI;
 import java.net.URL;
 
 import javax.xml.parsers.DocumentBuilder;
@@ -118,7 +119,11 @@
             fail("Unexpected exception: " + e1.getMessage());
         }
         
-        desc = reader.readWSDL(wsdlURLStr, new WSDLSource(doc), handler);
+        URI wsdlURI = URI.create(wsdlURLStr);
+        WSDLSource wsdlSource = reader.createWSDLSource();
+        wsdlSource.setBaseURI(wsdlURI);
+        wsdlSource.setSource(doc);
+        desc = reader.readWSDL(wsdlSource, handler);
       }
       catch(WSDLException e)
       {



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to