ws-woden-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jkapu...@apache.org
Subject svn commit: r574704 - in /incubator/woden/branches/woden140: src/org/apache/woden/internal/ src/org/apache/woden/internal/util/dom/ src/org/apache/woden/internal/util/om/ src/org/apache/woden/internal/wsdl20/ src/org/apache/woden/types/ src/org/apache/...
Date Tue, 11 Sep 2007 21:41:50 GMT
Author: jkaputin
Date: Tue Sep 11 14:41:49 2007
New Revision: 574704

URL: http://svn.apache.org/viewvc?rev=574704&view=rev
Log:
Work in progress on support for namespace declarations
across the WSDL object model.

Added:
    incubator/woden/branches/woden140/src/org/apache/woden/types/NamespaceDeclaration.java
  (with props)
Modified:
    incubator/woden/branches/woden140/src/org/apache/woden/internal/DOMWSDLReader.java
    incubator/woden/branches/woden140/src/org/apache/woden/internal/OMWSDLReader.java
    incubator/woden/branches/woden140/src/org/apache/woden/internal/util/dom/DOMUtils.java
    incubator/woden/branches/woden140/src/org/apache/woden/internal/util/om/OMUtils.java
    incubator/woden/branches/woden140/src/org/apache/woden/internal/wsdl20/DescriptionImpl.java
    incubator/woden/branches/woden140/src/org/apache/woden/internal/wsdl20/WSDLElementImpl.java
    incubator/woden/branches/woden140/src/org/apache/woden/wsdl20/xml/DescriptionElement.java
    incubator/woden/branches/woden140/src/org/apache/woden/wsdl20/xml/WSDLElement.java
    incubator/woden/branches/woden140/test/org/apache/woden/wsdl20/xml/DescriptiontElementTest.java

Modified: incubator/woden/branches/woden140/src/org/apache/woden/internal/DOMWSDLReader.java
URL: http://svn.apache.org/viewvc/incubator/woden/branches/woden140/src/org/apache/woden/internal/DOMWSDLReader.java?rev=574704&r1=574703&r2=574704&view=diff
==============================================================================
--- incubator/woden/branches/woden140/src/org/apache/woden/internal/DOMWSDLReader.java (original)
+++ incubator/woden/branches/woden140/src/org/apache/woden/internal/DOMWSDLReader.java Tue
Sep 11 14:41:49 2007
@@ -530,10 +530,7 @@
         throws WSDLException {
 
     	Element elem = (Element)xmlElem.getSource();
-    	
-    	//TODO remove this cast when support for NS decls is expanded from DescriptionElement
to all WSDLElements
-    	DescriptionElement desc = (DescriptionElement)wsdlElem;
-    	
+    	    	
         NamedNodeMap attrs = elem.getAttributes();
         int size = attrs.getLength();
 
@@ -548,11 +545,11 @@
           {
             if (!(Constants.ATTR_XMLNS).equals(localPart))
             {
-              desc.addNamespace(localPart, getURI(value));  //a prefixed namespace
+              wsdlElem.addNamespace(localPart, getURI(value));  //a prefixed namespace
             }
             else
             {
-              desc.addNamespace(null, getURI(value));       //the default namespace
+              wsdlElem.addNamespace(null, getURI(value));       //the default namespace
             }
           }
         }

Modified: incubator/woden/branches/woden140/src/org/apache/woden/internal/OMWSDLReader.java
URL: http://svn.apache.org/viewvc/incubator/woden/branches/woden140/src/org/apache/woden/internal/OMWSDLReader.java?rev=574704&r1=574703&r2=574704&view=diff
==============================================================================
--- incubator/woden/branches/woden140/src/org/apache/woden/internal/OMWSDLReader.java (original)
+++ incubator/woden/branches/woden140/src/org/apache/woden/internal/OMWSDLReader.java Tue
Sep 11 14:41:49 2007
@@ -22,6 +22,7 @@
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
+import java.util.Arrays;
 import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.Map;
@@ -33,7 +34,6 @@
 import org.apache.woden.ErrorHandler;
 import org.apache.woden.ErrorReporter;
 import org.apache.woden.WSDLException;
-import org.apache.woden.WSDLFactory;
 import org.apache.woden.WSDLSource;
 import org.apache.woden.XMLElement;
 import org.apache.woden.internal.resolver.OMSchemaResolverAdapter;
@@ -46,6 +46,7 @@
 import org.apache.woden.internal.wsdl20.Constants;
 import org.apache.woden.internal.xpointer.OMXMLElementEvaluator;
 import org.apache.woden.schema.Schema;
+import org.apache.woden.types.NamespaceDeclaration;
 import org.apache.woden.wsdl20.Description;
 import org.apache.woden.wsdl20.xml.DescriptionElement;
 import org.apache.woden.wsdl20.xml.WSDLElement;
@@ -55,7 +56,6 @@
 import org.apache.ws.commons.schema.XmlSchemaCollection;
 import org.apache.ws.commons.schema.XmlSchemaException;
 import org.apache.ws.commons.schema.utils.NamespaceMap;
-import org.w3c.dom.Element;
 import org.xml.sax.InputSource;
 
 /**
@@ -334,7 +334,13 @@
 
             //Set the baseURI and the namespaces from the DescriptionElement in the XMLSchemaCollection
             xsc.setBaseUri(baseURI);
-            NamespaceMap namespaces = new NamespaceMap(desc.getNamespaces());
+            
+            NamespaceMap namespaces = new NamespaceMap();
+            Iterator it = Arrays.asList(desc.getDeclaredNamespaces()).iterator();
+            while(it.hasNext()) {
+                NamespaceDeclaration d = (NamespaceDeclaration)it.next();
+                namespaces.add(d.getPrefix(), d.getNamespaceURI().toString());
+            }
             xsc.setNamespaceContext(namespaces);
             
             // Plug in the selected woden URI Resolver
@@ -540,9 +546,6 @@
             throws WSDLException {
         OMElement omDescription = (OMElement)xmlElem.getSource();
         
-        //TODO remove this cast when support for NS decls is expanded from DescriptionElement
to all WSDLElements
-        DescriptionElement desc = (DescriptionElement)wsdlElem;
-        
         Iterator namespaces = omDescription.getAllDeclaredNamespaces();
         while(namespaces.hasNext()){
             OMNamespace namespace = (OMNamespace)namespaces.next();
@@ -550,10 +553,10 @@
             String value = namespace.getNamespaceURI();
 
           if (!(Constants.ATTR_XMLNS).equals(localPart)){
-            desc.addNamespace(localPart, getURI(value));  //a prefixed namespace
+            wsdlElem.addNamespace(localPart, getURI(value));  //a prefixed namespace
           }
           else{
-            desc.addNamespace(null, getURI(value));       //the default namespace
+            wsdlElem.addNamespace(null, getURI(value));       //the default namespace
           }
         }
     }

Modified: incubator/woden/branches/woden140/src/org/apache/woden/internal/util/dom/DOMUtils.java
URL: http://svn.apache.org/viewvc/incubator/woden/branches/woden140/src/org/apache/woden/internal/util/dom/DOMUtils.java?rev=574704&r1=574703&r2=574704&view=diff
==============================================================================
--- incubator/woden/branches/woden140/src/org/apache/woden/internal/util/dom/DOMUtils.java
(original)
+++ incubator/woden/branches/woden140/src/org/apache/woden/internal/util/dom/DOMUtils.java
Tue Sep 11 14:41:49 2007
@@ -248,192 +248,192 @@
     return nkids;
   }
 
-  /**
-   * Given a prefix and a node, return the namespace URI that the prefix
-   * has been associated with. This method is useful in resolving the
-   * namespace URI of attribute values which are being interpreted as
-   * QNames. If prefix is null, this method will return the default
-   * namespace.
-   *
-   * @param context the starting node (looks up recursively from here)
-   * @param prefix the prefix to find an xmlns:prefix=uri for
-   *
-   * @return the namespace URI or null if not found
-   */
-  public static String getNamespaceURIFromPrefix (Node context,
-                                                  String prefix) {
-    short nodeType = context.getNodeType ();
-    Node tempNode = null;
-
-    switch (nodeType)
-    {
-      case Node.ATTRIBUTE_NODE :
-      {
-        tempNode = ((Attr) context).getOwnerElement ();
-        break;
-      }
-      case Node.ELEMENT_NODE :
-      {
-        tempNode = context;
-        break;
-      }
-      default :
-      {
-        tempNode = context.getParentNode ();
-        break;
-      }
-    }
-
-    while (tempNode != null && tempNode.getNodeType () == Node.ELEMENT_NODE)
-    {
-      Element tempEl = (Element) tempNode;
-      String namespaceURI = (prefix == null)
-                            ? getAttribute (tempEl, ATTR_XMLNS)
-                            : getAttributeNS (tempEl, NS_URI_XMLNS, prefix);
-
-      if (namespaceURI != null)
-      {
-        return namespaceURI;
-      }
-      else
-      {
-        tempNode = tempEl.getParentNode ();
-      }
-    }
-
-    return null;
-  }
+//  /**
+//   * Given a prefix and a node, return the namespace URI that the prefix
+//   * has been associated with. This method is useful in resolving the
+//   * namespace URI of attribute values which are being interpreted as
+//   * QNames. If prefix is null, this method will return the default
+//   * namespace.
+//   *
+//   * @param context the starting node (looks up recursively from here)
+//   * @param prefix the prefix to find an xmlns:prefix=uri for
+//   *
+//   * @return the namespace URI or null if not found
+//   */
+//  public static String getNamespaceURIFromPrefix (Node context,
+//                                                  String prefix) {
+//    short nodeType = context.getNodeType ();
+//    Node tempNode = null;
+//
+//    switch (nodeType)
+//    {
+//      case Node.ATTRIBUTE_NODE :
+//      {
+//        tempNode = ((Attr) context).getOwnerElement ();
+//        break;
+//      }
+//      case Node.ELEMENT_NODE :
+//      {
+//        tempNode = context;
+//        break;
+//      }
+//      default :
+//      {
+//        tempNode = context.getParentNode ();
+//        break;
+//      }
+//    }
+//
+//    while (tempNode != null && tempNode.getNodeType () == Node.ELEMENT_NODE)
+//    {
+//      Element tempEl = (Element) tempNode;
+//      String namespaceURI = (prefix == null)
+//                            ? getAttribute (tempEl, ATTR_XMLNS)
+//                            : getAttributeNS (tempEl, NS_URI_XMLNS, prefix);
+//
+//      if (namespaceURI != null)
+//      {
+//        return namespaceURI;
+//      }
+//      else
+//      {
+//        tempNode = tempEl.getParentNode ();
+//      }
+//    }
+//
+//    return null;
+//  }
+//  
+//  /*
+//   * this is a new version of the original getQName method from WSDL4J, with the invocation
+//   * of registerUniquePrefix commented out and the 'desc' arg removed from the arg list.
+//   * TODO pending modification to original method post-M2 (see todo comments below).
+//   */
+//  public static QName getQName(String prefixedValue,
+//                               Element contextEl)
+//                               throws WSDLException
+//  {
+//      int    index        = prefixedValue.indexOf(':');
+//      String prefix       = (index != -1)
+//      ? prefixedValue.substring(0, index)
+//              : null;
+//      String localPart    = prefixedValue.substring(index + 1);
+//      String namespaceURI = getNamespaceURIFromPrefix(contextEl, prefix);
+//      
+//      if (namespaceURI != null)
+//      {
+//          //TODO investigate changing the registration of namespaces and prefixes (i.e.
namespace decls)
+//          //so it can happen within any WSDL element, not just Description (current behaviour
is copied from WSDL4J)
+//          //registerUniquePrefix(prefix, namespaceURI, desc);
+//          
+//          //TODO when passing prefix to QName ctor, what if it was modified by
+//          //registerUniquePrefix because of a name clash (pass original or modification)?
+//          return new QName(namespaceURI, 
+//                  localPart, 
+//                  prefix != null ? prefix : emptyString);
+//      }
+//      else
+//      {
+//          //TODO use ErrorReporter here or in callers to report the problem
+//          
+//          String faultCode = (prefix == null)
+//          ? WSDLException.NO_PREFIX_SPECIFIED
+//                  : WSDLException.UNBOUND_PREFIX;
+//          
+//          WSDLException wsdlExc = new WSDLException(faultCode,
+//                  "Unable to determine " +
+//                  "namespace of '" +
+//                  prefixedValue + "'.");
+//          
+//          wsdlExc.setLocation(XPathUtils.getXPathExprFromNode(contextEl));
+//          
+//          throw wsdlExc;
+//      }
+//  }
+//
+//  /*
+//   * this is the original version of the getQName method, per WSDL4J. See to do comment
below
+//   * about changing register unique prefix behaviour. TODO TBD post-M2 (JK)
+//   */
+//  public static QName getQName(String prefixedValue,
+//                               Element contextEl,
+//                               DescriptionElement desc)
+//                                 throws WSDLException
+//  {
+//    int    index        = prefixedValue.indexOf(':');
+//    String prefix       = (index != -1)
+//                          ? prefixedValue.substring(0, index)
+//                          : null;
+//    String localPart    = prefixedValue.substring(index + 1);
+//    String namespaceURI = getNamespaceURIFromPrefix(contextEl, prefix);
+//
+//    if (namespaceURI != null)
+//    {
+//      //TODO investigate changing the registration of namespaces and prefixes (i.e. namespace
decls)
+//      //so it can happen within any WSDL element, not just Description (current behaviour
is copied from WSDL4J)
+//      registerUniquePrefix(prefix, namespaceURI, desc);
+//      
+//      //TODO when passing prefix to QName ctor, what if it was modified by
+//      //registerUniquePrefix because of a name clash (pass original or modification)?
+//      return new QName(namespaceURI, 
+//                       localPart, 
+//                       prefix != null ? prefix : emptyString);
+//    }
+//    else
+//    {
+//      //TODO use ErrorReporter here or in callers to report the problem
+//        
+//      String faultCode = (prefix == null)
+//                         ? WSDLException.NO_PREFIX_SPECIFIED
+//                         : WSDLException.UNBOUND_PREFIX;
+//
+//      WSDLException wsdlExc = new WSDLException(faultCode,
+//                                                "Unable to determine " +
+//                                                "namespace of '" +
+//                                                prefixedValue + "'.");
+//
+//      wsdlExc.setLocation(XPathUtils.getXPathExprFromNode(contextEl));
+//
+//      throw wsdlExc;
+//    }
+//  }
+//  
+//  public static void registerUniquePrefix(String prefix,
+//                                          String namespaceURI,
+//                                          DescriptionElement desc)
+//  throws WSDLException
+//  {
+//    URI nsUri = desc.getNamespace(prefix);
+//    String tempNSUri = nsUri != null ? nsUri.toString() : null;
+//
+//    if (tempNSUri != null && tempNSUri.equals(namespaceURI))
+//    {
+//      return;
+//    }
+//
+//    while (tempNSUri != null && !tempNSUri.equals(namespaceURI))
+//    {
+//      prefix += "_";
+//      nsUri = desc.getNamespace(prefix);
+//      tempNSUri = nsUri != null ? nsUri.toString() : null;
+//    }
+//    
+//    URI uri = null;
+//    try {
+//        uri = new URI(namespaceURI);
+//    } catch (URISyntaxException e) {
+//        //TODO make sure custom err handler is used, if configured
+//        new ErrorReporterImpl().reportError(
+//                new ErrorLocatorImpl(),  //TODO line&col nos.
+//                "WSDL506", 
+//                new Object[] {namespaceURI}, 
+//                ErrorReporter.SEVERITY_ERROR, 
+//                e);
+//    }
+//
+//    desc.addNamespace(prefix, uri);
+//  }
   
-  /*
-   * this is a new version of the original getQName method from WSDL4J, with the invocation
-   * of registerUniquePrefix commented out and the 'desc' arg removed from the arg list.
-   * TODO pending modification to original method post-M2 (see todo comments below).
-   */
-  public static QName getQName(String prefixedValue,
-                               Element contextEl)
-                               throws WSDLException
-  {
-      int    index        = prefixedValue.indexOf(':');
-      String prefix       = (index != -1)
-      ? prefixedValue.substring(0, index)
-              : null;
-      String localPart    = prefixedValue.substring(index + 1);
-      String namespaceURI = getNamespaceURIFromPrefix(contextEl, prefix);
-      
-      if (namespaceURI != null)
-      {
-          //TODO investigate changing the registration of namespaces and prefixes (i.e. namespace
decls)
-          //so it can happen within any WSDL element, not just Description (current behaviour
is copied from WSDL4J)
-          //registerUniquePrefix(prefix, namespaceURI, desc);
-          
-          //TODO when passing prefix to QName ctor, what if it was modified by
-          //registerUniquePrefix because of a name clash (pass original or modification)?
-          return new QName(namespaceURI, 
-                  localPart, 
-                  prefix != null ? prefix : emptyString);
-      }
-      else
-      {
-          //TODO use ErrorReporter here or in callers to report the problem
-          
-          String faultCode = (prefix == null)
-          ? WSDLException.NO_PREFIX_SPECIFIED
-                  : WSDLException.UNBOUND_PREFIX;
-          
-          WSDLException wsdlExc = new WSDLException(faultCode,
-                  "Unable to determine " +
-                  "namespace of '" +
-                  prefixedValue + "'.");
-          
-          wsdlExc.setLocation(XPathUtils.getXPathExprFromNode(contextEl));
-          
-          throw wsdlExc;
-      }
-  }
-
-  /*
-   * this is the original version of the getQName method, per WSDL4J. See to do comment below
-   * about changing register unique prefix behaviour. TODO TBD post-M2 (JK)
-   */
-  public static QName getQName(String prefixedValue,
-                               Element contextEl,
-                               DescriptionElement desc)
-                                 throws WSDLException
-  {
-    int    index        = prefixedValue.indexOf(':');
-    String prefix       = (index != -1)
-                          ? prefixedValue.substring(0, index)
-                          : null;
-    String localPart    = prefixedValue.substring(index + 1);
-    String namespaceURI = getNamespaceURIFromPrefix(contextEl, prefix);
-
-    if (namespaceURI != null)
-    {
-      //TODO investigate changing the registration of namespaces and prefixes (i.e. namespace
decls)
-      //so it can happen within any WSDL element, not just Description (current behaviour
is copied from WSDL4J)
-      registerUniquePrefix(prefix, namespaceURI, desc);
-      
-      //TODO when passing prefix to QName ctor, what if it was modified by
-      //registerUniquePrefix because of a name clash (pass original or modification)?
-      return new QName(namespaceURI, 
-                       localPart, 
-                       prefix != null ? prefix : emptyString);
-    }
-    else
-    {
-      //TODO use ErrorReporter here or in callers to report the problem
-        
-      String faultCode = (prefix == null)
-                         ? WSDLException.NO_PREFIX_SPECIFIED
-                         : WSDLException.UNBOUND_PREFIX;
-
-      WSDLException wsdlExc = new WSDLException(faultCode,
-                                                "Unable to determine " +
-                                                "namespace of '" +
-                                                prefixedValue + "'.");
-
-      wsdlExc.setLocation(XPathUtils.getXPathExprFromNode(contextEl));
-
-      throw wsdlExc;
-    }
-  }
-  
-  public static void registerUniquePrefix(String prefix,
-                                          String namespaceURI,
-                                          DescriptionElement desc)
-  throws WSDLException
-  {
-    URI nsUri = desc.getNamespace(prefix);
-    String tempNSUri = nsUri != null ? nsUri.toString() : null;
-
-    if (tempNSUri != null && tempNSUri.equals(namespaceURI))
-    {
-      return;
-    }
-
-    while (tempNSUri != null && !tempNSUri.equals(namespaceURI))
-    {
-      prefix += "_";
-      nsUri = desc.getNamespace(prefix);
-      tempNSUri = nsUri != null ? nsUri.toString() : null;
-    }
-    
-    URI uri = null;
-    try {
-        uri = new URI(namespaceURI);
-    } catch (URISyntaxException e) {
-        //TODO make sure custom err handler is used, if configured
-        new ErrorReporterImpl().reportError(
-                new ErrorLocatorImpl(),  //TODO line&col nos.
-                "WSDL506", 
-                new Object[] {namespaceURI}, 
-                ErrorReporter.SEVERITY_ERROR, 
-                e);
-    }
-
-    desc.addNamespace(prefix, uri);
-  }
-
   /**
    * This method should be used for elements that support extension attributes
    * because it does not track the remaining attributes to test for unexpected 

Modified: incubator/woden/branches/woden140/src/org/apache/woden/internal/util/om/OMUtils.java
URL: http://svn.apache.org/viewvc/incubator/woden/branches/woden140/src/org/apache/woden/internal/util/om/OMUtils.java?rev=574704&r1=574703&r2=574704&view=diff
==============================================================================
--- incubator/woden/branches/woden140/src/org/apache/woden/internal/util/om/OMUtils.java (original)
+++ incubator/woden/branches/woden140/src/org/apache/woden/internal/util/om/OMUtils.java Tue
Sep 11 14:41:49 2007
@@ -114,43 +114,43 @@
         return new InputSource(inputStream);
     }
 
-    /**
-     * @param prefixedValue to which the QName is prefixed
-     * @param contextEl Element in which the QName is sought for
-     * @return  The relevant QName for the prefix
-     * @throws WSDLException
-     */
-    public static QName getQName(String prefixedValue,
-                                 OMElement contextEl)
-                                 throws WSDLException{
-        int index = prefixedValue.indexOf(':');
-        String prefix = (index != -1)
-                        ? prefixedValue.substring(0, index)
-                        : null;
-        String localPart    = prefixedValue.substring(index + 1);
-        String namespaceURI;
-
-        if (prefix != null){
-            namespaceURI = contextEl.findNamespaceURI(prefix).getNamespaceURI();
-            //TODO investigate changing the registration of namespaces and prefixes (i.e.
namespace decls)
-            //so it can happen within any WSDL element, not just Description (current behaviour
is copied from WSDL4J)
-            //registerUniquePrefix(prefix, namespaceURI, desc);
-
-            //TODO when passing prefix to QName ctor, what if it was modified by
-            //registerUniquePrefix because of a name clash (pass original or modification)?
-            return new QName(namespaceURI, localPart, prefix);
-        }
-        else{
-            //TODO use ErrorReporter here or in callers to report the problem
-
-            String faultCode = WSDLException.NO_PREFIX_SPECIFIED;
-
-            throw new WSDLException(faultCode,
-                    "Unable to determine " +
-                    "namespace of '" +
-                    prefixedValue + "'.");
-        }
-    }
+//    /**
+//     * @param prefixedValue to which the QName is prefixed
+//     * @param contextEl Element in which the QName is sought for
+//     * @return  The relevant QName for the prefix
+//     * @throws WSDLException
+//     */
+//    public static QName getQName(String prefixedValue,
+//                                 OMElement contextEl)
+//                                 throws WSDLException{
+//        int index = prefixedValue.indexOf(':');
+//        String prefix = (index != -1)
+//                        ? prefixedValue.substring(0, index)
+//                        : null;
+//        String localPart    = prefixedValue.substring(index + 1);
+//        String namespaceURI;
+//
+//        if (prefix != null){
+//            namespaceURI = contextEl.findNamespaceURI(prefix).getNamespaceURI();
+//            //TODO investigate changing the registration of namespaces and prefixes (i.e.
namespace decls)
+//            //so it can happen within any WSDL element, not just Description (current behaviour
is copied from WSDL4J)
+//            //registerUniquePrefix(prefix, namespaceURI, desc);
+//
+//            //TODO when passing prefix to QName ctor, what if it was modified by
+//            //registerUniquePrefix because of a name clash (pass original or modification)?
+//            return new QName(namespaceURI, localPart, prefix);
+//        }
+//        else{
+//            //TODO use ErrorReporter here or in callers to report the problem
+//
+//            String faultCode = WSDLException.NO_PREFIX_SPECIFIED;
+//
+//            throw new WSDLException(faultCode,
+//                    "Unable to determine " +
+//                    "namespace of '" +
+//                    prefixedValue + "'.");
+//        }
+//    }
 
     /**
      * @param el Element whose attrib is looked for
@@ -170,36 +170,36 @@
     }
 
 
-    /*This is the same method taken from DOMUtils*/
-    public static void registerUniquePrefix(String prefix, String namespaceURI, DescriptionElement
desc)
-            throws WSDLException {
-          URI nsUri = desc.getNamespace(prefix);
-          String tempNSUri = nsUri != null ? nsUri.toString() : null;
-
-          if (tempNSUri != null && tempNSUri.equals(namespaceURI)){
-            return;
-          }
-
-          while (tempNSUri != null && !tempNSUri.equals(namespaceURI)){
-            prefix += "_";
-            nsUri = desc.getNamespace(prefix);
-            tempNSUri = nsUri != null ? nsUri.toString() : null;
-          }
-
-          URI uri = null;
-          try {
-              uri = new URI(namespaceURI);
-          } catch (URISyntaxException e) {
-              //TODO make sure custom err handler is used, if configured
-              new ErrorReporterImpl().reportError(
-                      new ErrorLocatorImpl(),  //TODO line&col nos.
-                      "WSDL506",
-                      new Object[] {namespaceURI},
-                      ErrorReporter.SEVERITY_ERROR,
-                      e);
-          }
-          desc.addNamespace(prefix, uri);
-    }
+//    /*This is the same method taken from DOMUtils*/
+//    public static void registerUniquePrefix(String prefix, String namespaceURI, DescriptionElement
desc)
+//            throws WSDLException {
+//          URI nsUri = desc.getNamespace(prefix);
+//          String tempNSUri = nsUri != null ? nsUri.toString() : null;
+//
+//          if (tempNSUri != null && tempNSUri.equals(namespaceURI)){
+//            return;
+//          }
+//
+//          while (tempNSUri != null && !tempNSUri.equals(namespaceURI)){
+//            prefix += "_";
+//            nsUri = desc.getNamespace(prefix);
+//            tempNSUri = nsUri != null ? nsUri.toString() : null;
+//          }
+//
+//          URI uri = null;
+//          try {
+//              uri = new URI(namespaceURI);
+//          } catch (URISyntaxException e) {
+//              //TODO make sure custom err handler is used, if configured
+//              new ErrorReporterImpl().reportError(
+//                      new ErrorLocatorImpl(),  //TODO line&col nos.
+//                      "WSDL506",
+//                      new Object[] {namespaceURI},
+//                      ErrorReporter.SEVERITY_ERROR,
+//                      e);
+//          }
+//          desc.addNamespace(prefix, uri);
+//    }
 }
 
 

Modified: incubator/woden/branches/woden140/src/org/apache/woden/internal/wsdl20/DescriptionImpl.java
URL: http://svn.apache.org/viewvc/incubator/woden/branches/woden140/src/org/apache/woden/internal/wsdl20/DescriptionImpl.java?rev=574704&r1=574703&r2=574704&view=diff
==============================================================================
--- incubator/woden/branches/woden140/src/org/apache/woden/internal/wsdl20/DescriptionImpl.java
(original)
+++ incubator/woden/branches/woden140/src/org/apache/woden/internal/wsdl20/DescriptionImpl.java
Tue Sep 11 14:41:49 2007
@@ -29,6 +29,7 @@
 import org.apache.woden.WSDLException;
 import org.apache.woden.internal.MessageFormatter;
 import org.apache.woden.internal.WSDLContext;
+import org.apache.woden.types.NCName;
 import org.apache.woden.wsdl20.Binding;
 import org.apache.woden.wsdl20.Description;
 import org.apache.woden.wsdl20.ElementDeclaration;
@@ -405,7 +406,7 @@
         return fTargetNamespace;    
     }
 
-    public void addNamespace(String prefix, URI namespace) 
+/*  public void addNamespace(String prefix, URI namespace) 
     {
         String pfx = (prefix != null) ? prefix : "";
         if (namespace != null) {
@@ -430,7 +431,7 @@
     public Map getNamespaces() 
     {
         return fNamespaces;
-    }
+    }*/
 
     public ImportElement[] getImportElements()
     {
@@ -643,20 +644,17 @@
             return getTargetNamespaceAndPrefix(parent);
         }
         
-        //we have a description element
-        String[] namespace = new String[] {"",""};
-        URI tns = ((DescriptionElement) wElem).getTargetNamespace();
+        //We have a description element
+        DescriptionElement desc = ((DescriptionElement) wElem);
+        
+        //Find its target name and prefix.
+        String[] namespace = new String[] {"", ""};
+        URI tns = desc.getTargetNamespace();
         if (tns != null) {
             namespace[0] = tns.toString();
-            Set nsDecls = ((DescriptionElement) wElem).getNamespaces().entrySet();
-            if(nsDecls != null) {
-                Iterator i = nsDecls.iterator();
-                while(i.hasNext()) {
-                    Map.Entry entry = (Map.Entry)i.next();
-                    if(tns.equals(entry.getValue())) {
-                        namespace[1] = (String)entry.getKey();
-                    }
-                }
+            String prefix = desc.getNamespacePrefix(tns);
+            if(prefix != null) {
+                namespace[1] = prefix;
             }
         }
         return namespace;

Modified: incubator/woden/branches/woden140/src/org/apache/woden/internal/wsdl20/WSDLElementImpl.java
URL: http://svn.apache.org/viewvc/incubator/woden/branches/woden140/src/org/apache/woden/internal/wsdl20/WSDLElementImpl.java?rev=574704&r1=574703&r2=574704&view=diff
==============================================================================
--- incubator/woden/branches/woden140/src/org/apache/woden/internal/wsdl20/WSDLElementImpl.java
(original)
+++ incubator/woden/branches/woden140/src/org/apache/woden/internal/wsdl20/WSDLElementImpl.java
Tue Sep 11 14:41:49 2007
@@ -16,6 +16,10 @@
  */
 package org.apache.woden.internal.wsdl20;
 
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Iterator;
 import java.net.URI;
 
 import javax.xml.namespace.QName;
@@ -23,11 +27,13 @@
 import org.apache.woden.internal.WSDLContext;
 import org.apache.woden.internal.wsdl20.extensions.AttributeExtensibleImpl;
 import org.apache.woden.internal.wsdl20.extensions.ElementExtensibleImpl;
+import org.apache.woden.types.NamespaceDeclaration;
 import org.apache.woden.wsdl20.extensions.ExtensionElement;
 import org.apache.woden.wsdl20.xml.NestedElement;
 import org.apache.woden.wsdl20.xml.WSDLElement;
 import org.apache.woden.xml.XMLAttr;
 
+
 /**
  * This abstract class defines the behaviour common to all WSDL elements.
  * That is, it implements support for extension attributes and elements.
@@ -40,6 +46,8 @@
 {
     private AttributeExtensibleImpl fAttrExt = new AttributeExtensibleImpl();
     private ElementExtensibleImpl fElemExt = new ElementExtensibleImpl();
+    private Map namespaceToPrefixMap = new HashMap();
+    private Map prefixToNamespaceMap = new HashMap();
     
     /* (non-Javadoc)
      * @see org.apache.woden.wsdl20.extensions.AttributeExtensible#setExtensionAttribute(javax.xml.namespace.QName,
org.apache.woden.xml.XMLAttr)
@@ -135,5 +143,76 @@
         //This is not a nested element, so the WSDL context is in this element, at the top
of the tree.
         //This element will override the getWsdlContext() method defined in WSDLElementImpl.
         return ((WSDLElementImpl)wElem).getWsdlContext();
+    }
+    
+    public void addNamespace(String prefix, URI namespace) {
+        prefix = (prefix != null) ? prefix : "";
+        if (namespace == null) {
+            removeNamespace(prefix);
+        } else {
+            namespaceToPrefixMap.put(namespace, prefix);
+            prefixToNamespaceMap.put(prefix, namespace);
+        }
+    }
+    
+    public URI removeNamespace(String prefix) {
+        prefix = (prefix != null) ? prefix : "";
+        URI namespaceURI = (URI)prefixToNamespaceMap.remove(prefix);
+        namespaceToPrefixMap.remove(namespaceURI);
+        return namespaceURI;
+    }
+    
+    public String getNamespacePrefix(URI namespace) {
+        //See if the prefix is local.
+        String prefix = (String)namespaceToPrefixMap.get(namespace);
+        if (prefix == null && this instanceof NestedElement) { //If not call parents
to find prefix if I'm nested.
+            return ((NestedElement)this).getParentElement().getNamespacePrefix(namespace);
+        } else { //Otherwise return the found prefix or null.
+            return prefix;
+        }
+    }
+    
+    public URI getNamespaceURI(String prefix) {
+        //See if the prefix is local.
+        URI namespace = (URI)prefixToNamespaceMap.get(prefix);
+        if (namespace == null && this instanceof NestedElement) { //If not call parents
to find prefix if I'm nested.
+            return ((NestedElement)this).getParentElement().getNamespaceURI(prefix);
+        } else { //Otherwise return the found namespace or null.
+            return namespace;
+        }
+    }
+    
+    public NamespaceDeclaration[] getInScopeNamespaces() {
+        ArrayList namespaces = addInScopeNamespaces(new ArrayList());
+        return (NamespaceDeclaration[])namespaces.toArray();
+    }
+    
+    private ArrayList addInScopeNamespaces(ArrayList namespaces) {
+         //Add my namespaces. 
+        Iterator it = namespaceToPrefixMap.keySet().iterator();
+        while(it.hasNext()){
+            URI namespace = (URI)it.next();
+            namespaces.add(new NamespaceDeclaration((String)namespaceToPrefixMap.get(namespace),
namespace));
+        }
+        //Add my parent namespaces if I'm a child.
+        if (this instanceof NestedElement) {
+            return ((WSDLElementImpl)((NestedElement)this).getParentElement()).addInScopeNamespaces(namespaces);
+        } else {
+            return namespaces;
+        }
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see org.apache.woden.wsdl20.xml.WSDLElement#getLocalNamespaceDeclarations()
+     */
+    public NamespaceDeclaration[] getDeclaredNamespaces() {
+        ArrayList namespaces = new ArrayList();
+        Iterator it = namespaceToPrefixMap.keySet().iterator();
+        while(it.hasNext()){
+            URI namespace = (URI)it.next();
+            namespaces.add(new NamespaceDeclaration((String)namespaceToPrefixMap.get(namespace),
namespace));
+        }
+        return (NamespaceDeclaration[])namespaces.toArray();
     }
 }

Added: incubator/woden/branches/woden140/src/org/apache/woden/types/NamespaceDeclaration.java
URL: http://svn.apache.org/viewvc/incubator/woden/branches/woden140/src/org/apache/woden/types/NamespaceDeclaration.java?rev=574704&view=auto
==============================================================================
--- incubator/woden/branches/woden140/src/org/apache/woden/types/NamespaceDeclaration.java
(added)
+++ incubator/woden/branches/woden140/src/org/apache/woden/types/NamespaceDeclaration.java
Tue Sep 11 14:41:49 2007
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.types;
+
+import java.net.URI;
+
+/**
+ * Represents an XML namespace declaration, consisting of a namespace prefix
+ * and a namespace URI. This is an immutable class.
+ * 
+ * @author John Kaputin (jkaputin@apache.org)
+ */
+public class NamespaceDeclaration {
+    
+    public static final String XMLNS_NS_STRING = "http://www.w3.org/2000/xmlns/";
+    
+    public static final URI XMLNS_NS_URI  = URI.create("http://www.w3.org/2000/xmlns/");
+    
+    private final String prefix;
+    private final URI namespaceURI;
+    
+    public NamespaceDeclaration(String prefix, URI namespaceURI) {
+        this.prefix = prefix;
+        this.namespaceURI = namespaceURI;
+    }
+    
+    public String getPrefix() {
+        return this.prefix;
+    }
+    
+    public URI getNamespaceURI() {
+        return this.namespaceURI;
+    }
+
+}

Propchange: incubator/woden/branches/woden140/src/org/apache/woden/types/NamespaceDeclaration.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/woden/branches/woden140/src/org/apache/woden/wsdl20/xml/DescriptionElement.java
URL: http://svn.apache.org/viewvc/incubator/woden/branches/woden140/src/org/apache/woden/wsdl20/xml/DescriptionElement.java?rev=574704&r1=574703&r2=574704&view=diff
==============================================================================
--- incubator/woden/branches/woden140/src/org/apache/woden/wsdl20/xml/DescriptionElement.java
(original)
+++ incubator/woden/branches/woden140/src/org/apache/woden/wsdl20/xml/DescriptionElement.java
Tue Sep 11 14:41:49 2007
@@ -17,7 +17,6 @@
 package org.apache.woden.wsdl20.xml;
 
 import java.net.URI;
-import java.util.Map;
 
 import org.apache.woden.WSDLException;
 import org.apache.woden.wsdl20.Description;
@@ -73,54 +72,6 @@
      */
     public URI getTargetNamespace();
 
-    /**
-     * Associate the specified prefix with the specified namespace URI.
-     * This equates to adding an <code>xmlns</code> namespace declaration to
the 
-     * &lt;description&gt; element. 
-     * To define the default namespace, specify null or the empty string "" for the prefix.
-     * If null is specified for the namespace URI, the prefix/namespace association will
be
-     * removed (i.e. the same behaviour as the <code>removeNamespace</code> method).
-     * If the specified prefix is already associated with a namespace URI, 
-     * that association will be replaced by the specified prefix/namespace association. 
-     *
-     * @param prefix the prefix String associated with <code>namespace</code>
-     * @param namespace the namespace URI associated with <code>prefix</code>
-     */
-    public void addNamespace(String prefix, URI namespace);
-    
-    /**
-     * Remove the namespace URI associated with the specified prefix.
-     * This equates to removing an <code>xmlns</code> namespace declaration from
the 
-     * &lt;description&gt; element.
-     * To remove the default namespace, specify null or the empty string "" for the prefix.
-     * If the specified prefix is not associated with a namespace, no action is performed.
-     * 
-     * @param prefix the prefix String associated with a namespace
-     */
-    public void removeNamespace(String prefix);
-    
-    /**
-     * Return the namespace URI associated with the specified prefix.
-     * This equates to an <code>xmlns</code> namespace declaration on the 
-     * &lt;description&gt; element.
-     * To return the default namespace, specify null or the empty string "" for the prefix.
-     * If the specified prefix is not associated with a namespace, null is returned.
-     * 
-     * @param prefix the prefix String associated with a namespace
-     */
-    public URI getNamespace(String prefix);
-    
-    /**
-     * Return the set of all prefix/namespace URI associations.
-     * This equates to all of the <code>xmlns</code> namespace declaration on
the 
-     * &lt;description&gt; element.
-     * 
-     * @deprecated in M7, to be replaced in M8 with a type-safe return type (WODEN-140)
-     * 
-     * @return a Map of prefix String / namespace URI pairs 
-     */
-    public Map getNamespaces(); //TODO type-safe return type
-    
     /*
      * Element factory methods
      */

Modified: incubator/woden/branches/woden140/src/org/apache/woden/wsdl20/xml/WSDLElement.java
URL: http://svn.apache.org/viewvc/incubator/woden/branches/woden140/src/org/apache/woden/wsdl20/xml/WSDLElement.java?rev=574704&r1=574703&r2=574704&view=diff
==============================================================================
--- incubator/woden/branches/woden140/src/org/apache/woden/wsdl20/xml/WSDLElement.java (original)
+++ incubator/woden/branches/woden140/src/org/apache/woden/wsdl20/xml/WSDLElement.java Tue
Sep 11 14:41:49 2007
@@ -16,6 +16,8 @@
  */
 package org.apache.woden.wsdl20.xml;
 
+import java.net.URI;
+import org.apache.woden.types.NamespaceDeclaration;
 import org.apache.woden.wsdl20.extensions.AttributeExtensible;
 import org.apache.woden.wsdl20.extensions.ElementExtensible;
 
@@ -32,4 +34,72 @@
      * element extensibility, so by inheriting directly or indirectly from this 
      * interface they also inherit the extensibility interfaces.
      */
+    
+    /**
+     * Associate the specified prefix with the specified namespace URI.
+     * This equates to adding an <code>xmlns</code> namespace declaration to
this 
+     * WSDL element. 
+     * To define the default namespace, specify null or the empty string "" for the prefix.
+     * If null is specified for the namespace URI, the prefix/namespace association will
be
+     * removed (i.e. the same behaviour as the <code>removeNamespace</code> method).
+     * If the specified prefix is already associated with a namespace URI, 
+     * that association will be replaced by the specified prefix/namespace association. 
+     *
+     * @param prefix the prefix String associated with <code>namespaceURI</code>
+     * @param namespaceURI the namespace URI associated with <code>prefix</code>
+     */
+    public void addNamespace(String prefix, URI namespaceURI);
+    
+    /**
+     * Remove the namespace URI associated with the specified prefix.
+     * This equates to removing an <code>xmlns</code> namespace declaration from
this
+     * WSDL element.
+     * To remove the default namespace, specify null or the empty string "" for the prefix.
+     * 
+     * @param prefix the prefix String associated with the namespace to be removed
+     * @return the removed namespace URI or null if no prefix/namespace association exists
+     */
+    public URI removeNamespace(String prefix);
+    
+    
+    /**
+     * Return the namespace URI associated with the specified prefix.
+     * The scope of the search correponds to the scope of namespace declarations 
+     * in XML. That is, from the current element upwards to the root element
+     * (to the wsdl:description).
+     *  
+     * @param prefix the prefix whose associated namespace URI is required
+     * @return the associated namespace URI
+     */
+    public URI getNamespaceURI(String prefix);
+    
+    /**
+     * Return the prefix associated with the specified namespace URI.
+     * The scope of the search corresponds to the scope of namespace declarations
+     * in XML. That is, from the current element upwards to the root element
+     * (to the wsdl:description).
+     * 
+     * @param namespaceURI the namespace URI whose associated prefix is required
+     * @return the associated prefix String
+     */
+    public String getNamespacePrefix(URI namespaceURI);
+    
+    /**
+     * Return the namespaces and their associated prefixes declared directly
+     * within this WSDL element.
+     * 
+     * @return an array of NamespaceDeclaration
+     */
+    public NamespaceDeclaration[] getDeclaredNamespaces();
+    
+    /**
+     * Return all namespaces and their associated prefixes that are in-scope
+     * to this WSDL element. That is, those declared directly within this element
+     * and those declared in ancestor elements upwards to the root element
+     * (to the wsdl:description).
+     * 
+     * @return an array of NamespaceDeclaration
+     */
+    public NamespaceDeclaration[] getInScopeNamespaces();
+    
 }

Modified: incubator/woden/branches/woden140/test/org/apache/woden/wsdl20/xml/DescriptiontElementTest.java
URL: http://svn.apache.org/viewvc/incubator/woden/branches/woden140/test/org/apache/woden/wsdl20/xml/DescriptiontElementTest.java?rev=574704&r1=574703&r2=574704&view=diff
==============================================================================
--- incubator/woden/branches/woden140/test/org/apache/woden/wsdl20/xml/DescriptiontElementTest.java
(original)
+++ incubator/woden/branches/woden140/test/org/apache/woden/wsdl20/xml/DescriptiontElementTest.java
Tue Sep 11 14:41:49 2007
@@ -89,38 +89,6 @@
 		assertEquals("Retrieved target Namespace URI differs from that set", fNamespace1, retrievedTNS);
 	}
 
-	public void testAddGetNamespace() {
-		fDescriptionElement.addNamespace(fPrefix1,fNamespace1);
-		URI uri = fDescriptionElement.getNamespace(fPrefix1);
-		assertEquals("Retrieved NamespaceURI does not match that set", fNamespace1, uri);
-	}
-	
-	/*
-	 * Test getNamespace() when the prefix & namespace pair has not been previously added
-	 */
-	public void testGetNullNamespace() {
-		assertNull("Null was not returned when a non-existent prefix was given", fDescriptionElement.getNamespace("nosuchprefix"));
-	}
-
-	public void testRemoveNamespace() {
-		fDescriptionElement.addNamespace(fPrefix1,fNamespace1);
-		assertNotNull(fDescriptionElement.getNamespace(fPrefix1));
-		fDescriptionElement.removeNamespace(fPrefix1);
-		assertNull(fDescriptionElement.getNamespace(fPrefix1));
-	}
-
-	public void testAddGetNamespaces() {
-		fDescriptionElement.addNamespace(fPrefix1,fNamespace1);
-		fDescriptionElement.addNamespace(fPrefix2,fNamespace2);
-		Map uriMap = fDescriptionElement.getNamespaces();
-		assertEquals("Expected 2 namespaces", uriMap.size(),2);
-		URI uri1 = (URI)uriMap.get(fPrefix1);
-		URI uri2 = (URI)uriMap.get(fPrefix2);
-		assertEquals("Expected NamespaceURI not found", fNamespace1, uri1);
-		assertEquals("Expected NamespaceURI not found", fNamespace2, uri2);	
-	}
-	
-
 	public void testAddGetImportElements() {
 		ImportElement importElement1 = fDescriptionElement.addImportElement();
 		ImportElement importElement2 = fDescriptionElement.addImportElement();



---------------------------------------------------------------------
To unsubscribe, e-mail: woden-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: woden-dev-help@ws.apache.org


Mime
View raw message