Author: jkaputin
Date: Fri Nov 10 09:50:06 2006
New Revision: 473398

URL: http://svn.apache.org/viewvc?view=rev&rev=473398
Log:
WODEN-14 Applied woden-14-patch5.txt contributed
by Graham Turrell to support running Woden offline
with an XML catalog.

Modified:
    incubator/woden/trunk/java/src/org/apache/woden/internal/DOMWSDLReader.java
    incubator/woden/trunk/java/src/org/apache/woden/internal/OMWSDLReader.java
    
incubator/woden/trunk/java/src/org/apache/woden/internal/resolver/SchemaResolverAdapter.java
    
incubator/woden/trunk/java/src/org/apache/woden/internal/resolver/SimpleURIResolver.java

Modified: 
incubator/woden/trunk/java/src/org/apache/woden/internal/DOMWSDLReader.java
URL: 
http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/internal/DOMWSDLReader.java?view=diff&rev=473398&r1=473397&r2=473398
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/internal/DOMWSDLReader.java 
(original)
+++ incubator/woden/trunk/java/src/org/apache/woden/internal/DOMWSDLReader.java 
Fri Nov 10 09:50:06 2006
@@ -31,6 +31,7 @@
 import org.apache.woden.WSDLReader;
 import org.apache.woden.WSDLSource;
 import org.apache.woden.XMLElement;
+import org.apache.woden.internal.resolver.EntityResolverAdapter;
 import org.apache.woden.internal.resolver.SchemaResolverAdapter;
 import org.apache.woden.internal.schema.ImportedSchemaImpl;
 import org.apache.woden.internal.schema.InlinedSchemaImpl;
@@ -117,8 +118,9 @@
             throw new WSDLException(WSDLException.PARSER_ERROR, msg, e);
         }
         String wsdlURL = url.toString();
-            
-        InputSource inputSource = new InputSource(wsdlURL);
+           
+        // ensure InputSource runs thru the URI Resolver
+        InputSource inputSource = new InputSource(resolveURI(wsdlURL));
         return readWSDL(wsdlURL, inputSource);
     }
     
@@ -357,7 +359,25 @@
         
         try 
         {
-            contextURI = desc.getDocumentBaseURI();
+               /*
+                * For simple resolvers, we resolve the parent (Description) URI
+                * to be used as the context. This allows for relative 
locationURIs
+                * to be resolved implicitly - they are considered to be 
located 
+                * relative to the resolved parent. Therefore, relative URIs 
such as these
+                * need not be listed in the catalog file.
+                */
+               
+               /* TODO
+                * OASIS-style catalogs have a convenience notation to define 
root URIs
+                * thus grouping related URLs together. In this case the 
context URI here
+                * should be left alone, but the resultant locationURL resolved 
instead.
+                * 
+                * Implement a boolean system property like 
org.apache.woden.resolver.useRelativeURLs
+                * (set by the resolver ctor). SimpleURIResolver (et al) should 
set this to true,
+                * OASISCatalogResolver should set to false. 
+                */
+               // contextURI = desc.getDocumentBaseURI();
+               contextURI = resolveURI(desc.getDocumentBaseURI());
             URL contextURL = (contextURI != null) ? contextURI.toURL() : null;
             schemaLoc = schema.getSchemaLocation().toString();
             url = StringUtils.getURL(contextURL, schemaLoc);
@@ -633,7 +653,8 @@
           Document schemaDoc = 
DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
           Element schemaElem = 
schemaDoc.createElementNS("http://www.w3.org/2001/XMLSchema";, "import");
           schemaElem.setAttribute("namespace", 
"http://www.w3.org/2001/XMLSchema";);
-          schemaElem.setAttribute("schemaLocation", 
"http://www.w3.org/2001/XMLSchema.xsd";);
+          schemaElem.setAttribute("schemaLocation", 
resolveURI("http://www.w3.org/2001/XMLSchema.xsd";));
+          
           XMLElement xmlEl = createXMLElement(schemaElem);
           desc.getTypesElement().addSchema(parseSchemaImport(xmlEl, desc));
         }
@@ -726,6 +747,8 @@
 //        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);
@@ -751,7 +774,9 @@
                        
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/2006/01/wsdl http://www.w3.org/2006/01/wsdl/wsdl20.xsd 
http://www.w3.org/2006/01/wsdl-extensions 
http://www.w3.org/2006/01/wsdl-extensions.xsd http://www.w3.org/2001/XMLSchema 
http://www.w3.org/2001/XMLSchema.xsd";);
+                       
+                       
//parser.setProperty(org.apache.xerces.impl.Constants.XERCES_PROPERTY_PREFIX + 
org.apache.xerces.impl.Constants.SCHEMA_LOCATION, 
"http://www.w3.org/2006/01/wsdl http://www.w3.org/2006/01/wsdl/wsdl20.xsd 
http://www.w3.org/2006/01/wsdl-extensions 
http://www.w3.org/2006/01/wsdl-extensions.xsd http://www.w3.org/2001/XMLSchema 
http://www.w3.org/2001/XMLSchema.xsd";);
+                       
parser.setProperty(org.apache.xerces.impl.Constants.XERCES_PROPERTY_PREFIX + 
org.apache.xerces.impl.Constants.SCHEMA_LOCATION, 
"http://www.w3.org/2006/01/wsdl " + 
resolveURI("http://www.w3.org/2006/01/wsdl/wsdl20.xsd";) + " 
http://www.w3.org/2006/01/wsdl-extensions " + 
resolveURI("http://www.w3.org/2006/01/wsdl-extensions.xsd";) + " 
http://www.w3.org/2001/XMLSchema " + 
resolveURI("http://www.w3.org/2001/XMLSchema.xsd";));
                }
             catch(SAXNotRecognizedException e)
             {
@@ -817,8 +842,26 @@
         URI contextURI = null;
         
         try 
-        {
-            contextURI = desc.getDocumentBaseURI();
+        {         
+               /*
+                * For simple resolvers, we resolve the parent (Description) URI
+                * to be used as the context. This allows for relative 
locationURIs
+                * to be resolved implicitly - they are considered to be 
located 
+                * relative to the resolved parent. Therefore, relative URIs 
such as these
+                * need not be listed in the catalog file.
+                */
+               
+               /* TODO
+                * OASIS-style catalogs have a convenience notation to define 
root URIs
+                * thus grouping related URLs together. In this case the 
context URI here
+                * should be left alone, but the resultant locationURL resolved 
instead.
+                * 
+                * Implement a boolean system property like 
org.apache.woden.resolver.useRelativeURLs
+                * (set by the resolver ctor). SimpleURIResolver (et al) should 
set this to true,
+                * OASISCatalogResolver should set to false. 
+                */
+               // contextURI = desc.getDocumentBaseURI();
+               contextURI = resolveURI(desc.getDocumentBaseURI());
             URL contextURL = (contextURI != null) ? contextURI.toURL() : null;
             locationURL = StringUtils.getURL(contextURL, locationURI);
         } 

Modified: 
incubator/woden/trunk/java/src/org/apache/woden/internal/OMWSDLReader.java
URL: 
http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/internal/OMWSDLReader.java?view=diff&rev=473398&r1=473397&r2=473398
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/internal/OMWSDLReader.java 
(original)
+++ incubator/woden/trunk/java/src/org/apache/woden/internal/OMWSDLReader.java 
Fri Nov 10 09:50:06 2006
@@ -76,7 +76,8 @@
             throw new WSDLException(WSDLException.PARSER_ERROR, msg, e);
         }
 
-        OMElement wsdlDescription = OMUtils.getElement(url.toString());
+        // perform URI Resolution here
+        OMElement wsdlDescription = 
OMUtils.getElement(resolveURI(url.toString()));
 
         XMLElement descEl = createXMLElement(wsdlDescription);
         return parseDescription(url.toString(), descEl, null);
@@ -180,7 +181,25 @@
         URL url = null;
 
         try{
-            contextURI = desc.getDocumentBaseURI();
+               /*
+                * For simple resolvers, we resolve the parent (Description) URI
+                * to be used as the context. This allows for relative 
locationURIs
+                * to be resolved implicitly - they are considered to be 
located 
+                * relative to the resolved parent. Therefore, relative URIs 
such as these
+                * need not be listed in the catalog file.
+                */
+               
+               /* TODO
+                * OASIS-style catalogs have a convenience notation to define 
root URIs
+                * thus grouping related URLs together. In this case the 
context URI here
+                * should be left alone, but the resultant locationURL resolved 
instead.
+                * 
+                * Implement a boolean system property like 
org.apache.woden.resolver.useRelativeURLs
+                * (set by the resolver ctor). SimpleURIResolver (et al) should 
set this to true,
+                * OASISCatalogResolver should set to false. 
+                */
+               // contextURI = desc.getDocumentBaseURI();
+               contextURI = resolveURI(desc.getDocumentBaseURI());
             System.out.println(contextURI);
             System.out.println(contextURI.toURL());
             URL contextURL = (contextURI != null) ? contextURI.toURL() : null;
@@ -364,7 +383,25 @@
         URI contextURI = null;
 
         try{
-            contextURI = desc.getDocumentBaseURI();
+               /*
+                * For simple resolvers, we resolve the parent (Description) URI
+                * to be used as the context. This allows for relative 
locationURIs
+                * to be resolved implicitly - they are considered to be 
located 
+                * relative to the resolved parent. Therefore, relative URIs 
such as these
+                * need not be listed in the catalog file.
+                */
+               
+               /* TODO
+                * OASIS-style catalogs have a convenience notation to define 
root URIs
+                * thus grouping related URLs together. In this case the 
context URI here
+                * should be left alone, but the resultant locationURL resolved 
instead.
+                * 
+                * Implement a boolean system property like 
org.apache.woden.resolver.useRelativeURLs
+                * (set by the resolver ctor). SimpleURIResolver (et al) should 
set this to true,
+                * OASISCatalogResolver should set to false. 
+                */
+               // contextURI = desc.getDocumentBaseURI();
+               contextURI = resolveURI(desc.getDocumentBaseURI());
             URL contextURL = (contextURI != null) ? contextURI.toURL() : null;
             locationURL = StringUtils.getURL(contextURL, locationURI);
         }

Modified: 
incubator/woden/trunk/java/src/org/apache/woden/internal/resolver/SchemaResolverAdapter.java
URL: 
http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/internal/resolver/SchemaResolverAdapter.java?view=diff&rev=473398&r1=473397&r2=473398
==============================================================================
--- 
incubator/woden/trunk/java/src/org/apache/woden/internal/resolver/SchemaResolverAdapter.java
 (original)
+++ 
incubator/woden/trunk/java/src/org/apache/woden/internal/resolver/SchemaResolverAdapter.java
 Fri Nov 10 09:50:06 2006
@@ -35,7 +35,11 @@
        public SchemaResolverAdapter(org.apache.woden.resolver.URIResolver 
actualResolver) {
                fActualResolver = actualResolver;
        }
-               
+       
+       /**
+        * returns resolved URI if one can be found, otherwise the URI 
constructed from
+        * the arguments. Conforms to the interface spec.
+        */
        public InputSource resolveEntity(String targetNamespace,
                String schemaLocation,
                String baseUri
@@ -47,13 +51,43 @@
                URI uri = null;
                try 
                {
-                       uri = buildUri(targetNamespace, schemaLocation, 
baseUri); 
+           /* 
+           * Its necessary to provide an absolute URI from the 
+           * given schemaLocation. If SchemaLocation is relative
+           * we first try to resolve the base uri (ie that of the enclosing
+           * document), so that all schemaLocation references will be relative
+           * to the resolved base uri. This behaviour is consistent 
+           * with the EntityResolverAdapter callback used with wsdl2 parsing.
+           * This removes the need to list relative URIs in the catalog.
+           */
+                  
+          /*
+           * TODO may want to have this behaviour switchable?
+           * currently a convenience for Simple URI resolvers, where 
+           * root URI's cannot be specified for groups of URLs.
+           * It removes the need to specify relative URL from source documents
+           * in the catalog. This is at the cost of flexibility, as relative
+           * URLs in the source documents must now have the same relative 
location
+           * to the resolved source document.
+           *
+           * OASIS XML Catalog resolvers do allow a flexible use of root URI's 
+           * and here it may be better to *not* resolve the base URI here.
+           * If so, EntityResolverAdapter should be changed to similar 
behaviour.
+           */
+          
+                       
+                       URI resolvedBaseUri = fActualResolver.resolveURI(new 
URI(baseUri));
+                       uri = buildUri(targetNamespace, schemaLocation, 
resolvedBaseUri == null ? baseUri : resolvedBaseUri.toString()); 
                } 
-               catch (URISyntaxException e) 
+               catch (Exception e) 
                {
+                       /* IOException
+                        * WSDLException
+                        * URISyntaxException
+                        */
                        throw new RuntimeException(e);
                }
-               
+
                /* resolve with target resolver
                 * 
                 */             
@@ -79,7 +113,7 @@
                String schemaLocation,
                String baseUri) throws URISyntaxException {
                
-       if (baseUri!=null) 
+       if (baseUri != null) 
         {
 
           File baseFile = new File(baseUri);

Modified: 
incubator/woden/trunk/java/src/org/apache/woden/internal/resolver/SimpleURIResolver.java
URL: 
http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/internal/resolver/SimpleURIResolver.java?view=diff&rev=473398&r1=473397&r2=473398
==============================================================================
--- 
incubator/woden/trunk/java/src/org/apache/woden/internal/resolver/SimpleURIResolver.java
 (original)
+++ 
incubator/woden/trunk/java/src/org/apache/woden/internal/resolver/SimpleURIResolver.java
 Fri Nov 10 09:50:06 2006
@@ -17,6 +17,7 @@
  */
 package org.apache.woden.internal.resolver;
 
+import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
@@ -69,39 +70,14 @@
 
 public class SimpleURIResolver implements URIResolver {
                
-       private final String 
RESOLVER_PROPERTIES_PROPERTY="org.apache.woden.resolver.simpleresolver.catalog";
+       private static final String 
RESOLVER_PROPERTIES_PROPERTY="org.apache.woden.resolver.simpleresolver.catalog";
+       private static final String 
RESOLVER_BASE_PROPERTY="org.apache.woden.resolver.simpleresolver.base";
        private final String ResolverPropertiesFile = 
PropertyUtils.findProperty(RESOLVER_PROPERTIES_PROPERTY);
        private Hashtable uriTable = null;
        
        public SimpleURIResolver() throws WSDLException {
                
-               // read & retain the resolver references from properties file.
-               Properties properties = new Properties();
-           try 
-           {
-               if (ResolverPropertiesFile != null) {
-                       properties.load(new 
FileInputStream(ResolverPropertiesFile));
-               }
-           } 
-           catch (FileNotFoundException e) {
-               // treat missing properties file as empty file, ie no resolves 
specified.
-               // TODO log this
-           }
-           catch (IOException e) {
-               // load() failed, continue with no resolves
-               // TODO log this
-           }
-           
-           // convert keys and values to URIs
-           try 
-           {
-               uriTable = toURI(properties);
-           } 
-           catch (URISyntaxException e) {
-                       throw new 
WSDLException(WSDLException.CONFIGURATION_ERROR,
-                    "Problem instantiating the URI resolution table.",
-                    e);
-               }
+               this(PropertyUtils.findProperty(RESOLVER_BASE_PROPERTY));
        }
 
        /** 
@@ -172,20 +148,10 @@
         * @return
         * @throws URISyntaxException
         */
-       // TODO could replace with a call to toURI(p, null)
        private Hashtable toURI(Properties p) throws URISyntaxException {
-               Hashtable h = new Hashtable();
-               if (p != null)
-               {
-                       Enumeration keys = p.keys();
-                       while (keys.hasMoreElements()) {
-                               String key = (String)keys.nextElement();
-                               String value = p.getProperty(key);
-                               h.put(new URI(key), new URI(value));            
        
-                       }
-               }
-               return h;
+               return toURI(p, null);
        }
+       
        /**
         * Convert resolve elements Properties (Hashtable of Strings) to 
Hashtable of URIs
         * 
@@ -195,6 +161,9 @@
         * @throws URISyntaxException
         */
        private Hashtable toURI(Properties p, String root) throws 
URISyntaxException {
+               if (root == null) {
+                       root = "";
+               }               
                Hashtable h = new Hashtable();
                if (p != null)
                {
@@ -202,7 +171,14 @@
                        while (keys.hasMoreElements()) {
                                String key = (String)keys.nextElement();
                                String value = root + p.getProperty(key);
-                               h.put(new URI(key), new URI(value));            
        
+                               URI valueURI = null;
+                               try {
+                                       valueURI = new URI(value); // string 
representation of a URI
+                               }
+                               catch (URISyntaxException e) {
+                                       valueURI = new File(value).toURI(); // 
string representation of a file path
+                               }
+                               h.put(new URI(key), valueURI);                  
                        }
                }
                return h;



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

Reply via email to