ws-woden-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jkapu...@apache.org
Subject svn commit: r293236 - in /incubator/woden/java/src: javax/xml/namespace/QName.java org/apache/woden/internal/util/StringUtils.java org/apache/woden/internal/util/dom/DOMUtils.java org/apache/woden/internal/util/dom/QNameUtils.java
Date Mon, 03 Oct 2005 04:49:48 GMT
Author: jkaputin
Date: Sun Oct  2 21:49:36 2005
New Revision: 293236

URL: http://svn.apache.org/viewcvs?rev=293236&view=rev
Log:
Added some utility behaviour for handling QNames.

Modified:
    incubator/woden/java/src/javax/xml/namespace/QName.java
    incubator/woden/java/src/org/apache/woden/internal/util/StringUtils.java
    incubator/woden/java/src/org/apache/woden/internal/util/dom/DOMUtils.java
    incubator/woden/java/src/org/apache/woden/internal/util/dom/QNameUtils.java

Modified: incubator/woden/java/src/javax/xml/namespace/QName.java
URL: http://svn.apache.org/viewcvs/incubator/woden/java/src/javax/xml/namespace/QName.java?rev=293236&r1=293235&r2=293236&view=diff
==============================================================================
--- incubator/woden/java/src/javax/xml/namespace/QName.java (original)
+++ incubator/woden/java/src/javax/xml/namespace/QName.java Sun Oct  2 21:49:36 2005
@@ -15,7 +15,9 @@
  */
 package javax.xml.namespace;
 
-import java.io.*;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.Serializable;
 
 /**
  * <code>QName</code> class represents the value of a qualified name
@@ -26,10 +28,14 @@
  * The localPart provides the local part of the qualified name. The
  * namespaceURI is a URI reference identifying the namespace.
  *
- * Note: Some of this impl code was taken from Axis.
- *
+ * This QName class mostly copied from wsdl4j, which borrowed from Axis.
+ * Updated to reflect the QName interface defined by J2EE 1.4.
+ * 
+ * TODO illegalArgEx in ctor if localpart is null or "" or if prefix is null.
+ * 
  * @author axis-dev
  * @author Matthew J. Duftler (duftler@us.ibm.com)
+ * @author jkaputin@apache.org
  */
 public class QName implements Serializable
 {
@@ -41,8 +47,8 @@
 
   // Field localPart.
   private String localPart;
-
-  private static final long serialVersionUID = -9120448754896609940L;
+  
+  private String prefix;
 
   /**
    * Constructor for the QName.
@@ -55,6 +61,7 @@
     this.localPart    = (localPart == null)
                         ? emptyString
                         : localPart.intern();
+    this.prefix       = emptyString;
   }
 
   /**
@@ -71,6 +78,27 @@
     this.localPart    = (localPart == null)
                         ? emptyString
                         : localPart.intern();
+    this.prefix       = emptyString;
+  }
+
+  /**
+   * Constructor for the QName.
+   *
+   * @param namespaceURI Namespace URI for the QName
+   * @param localPart Local part of the QName.
+   * @param prefix Prefix for the namespace.
+   */
+  public QName(String namespaceURI, String localPart, String prefix)
+  {
+    this.namespaceURI = (namespaceURI == null)
+                        ? emptyString
+                        : namespaceURI.intern();
+    this.localPart    = (localPart == null)
+                        ? emptyString
+                        : localPart.intern();
+    this.prefix       = (prefix == null)
+                        ? emptyString
+                        : prefix.intern();; 
   }
 
   /**
@@ -91,6 +119,16 @@
   public String getLocalPart()
   {
     return localPart;
+  }
+
+  /**
+   * Gets the Prefix for this QName
+   *
+   * @return prefix
+   */
+  public String getPrefix()
+  {
+    return prefix;
   }
 
   /**

Modified: incubator/woden/java/src/org/apache/woden/internal/util/StringUtils.java
URL: http://svn.apache.org/viewcvs/incubator/woden/java/src/org/apache/woden/internal/util/StringUtils.java?rev=293236&r1=293235&r2=293236&view=diff
==============================================================================
--- incubator/woden/java/src/org/apache/woden/internal/util/StringUtils.java (original)
+++ incubator/woden/java/src/org/apache/woden/internal/util/StringUtils.java Sun Oct  2 21:49:36
2005
@@ -196,7 +196,12 @@
     
     public static List parseNMTokens(String nmTokens)
     {
-      StringTokenizer strTok = new StringTokenizer(nmTokens, " ");
+      return parseNMTokens(nmTokens, " ");
+    }
+
+    public static List parseNMTokens(String nmTokens, String delimiter)
+    {
+      StringTokenizer strTok = new StringTokenizer(nmTokens, delimiter);
       List tokens = new Vector();
 
       while (strTok.hasMoreTokens())

Modified: incubator/woden/java/src/org/apache/woden/internal/util/dom/DOMUtils.java
URL: http://svn.apache.org/viewcvs/incubator/woden/java/src/org/apache/woden/internal/util/dom/DOMUtils.java?rev=293236&r1=293235&r2=293236&view=diff
==============================================================================
--- incubator/woden/java/src/org/apache/woden/internal/util/dom/DOMUtils.java (original)
+++ incubator/woden/java/src/org/apache/woden/internal/util/dom/DOMUtils.java Sun Oct  2 21:49:36
2005
@@ -15,7 +15,6 @@
  */
 package org.apache.woden.internal.util.dom;
 
-import java.io.PrintWriter;
 import java.util.List;
 import java.util.ListIterator;
 import java.util.Vector;
@@ -23,6 +22,7 @@
 import javax.xml.namespace.QName;
 
 import org.apache.woden.WSDLException;
+import org.apache.woden.wsdl20.xml.DescriptionElement;
 import org.w3c.dom.Attr;
 import org.w3c.dom.CharacterData;
 import org.w3c.dom.Element;
@@ -276,7 +276,7 @@
     {
       Element tempEl = (Element) tempNode;
       String namespaceURI = (prefix == null)
-                            ? getAttribute (tempEl, "xmlns")
+                            ? getAttribute (tempEl, ATTR_XMLNS)
                             : getAttributeNS (tempEl, NS_URI_XMLNS, prefix);
 
       if (namespaceURI != null)
@@ -292,10 +292,9 @@
     return null;
   }
   
-  /*
   public static QName getQName(String prefixedValue,
                                Element contextEl,
-                               Definition def)
+                               DescriptionElement desc)
                                  throws WSDLException
   {
     int    index        = prefixedValue.indexOf(':');
@@ -307,12 +306,16 @@
 
     if (namespaceURI != null)
     {
-      registerUniquePrefix(prefix, namespaceURI, def);
+      registerUniquePrefix(prefix, namespaceURI, desc);
 
+      //TODO pass prefix to QName ctor too, but what about if it was modified
+      //when registered because of name clash (pass original or modification)?
       return new QName(namespaceURI, localPart);
     }
     else
     {
+      //TODO use ErrorReporter here or in callers to report the problem
+        
       String faultCode = (prefix == null)
                          ? WSDLException.NO_PREFIX_SPECIFIED
                          : WSDLException.UNBOUND_PREFIX;
@@ -327,13 +330,12 @@
       throw wsdlExc;
     }
   }
-  */
-  /*
+  
   public static void registerUniquePrefix(String prefix,
                                           String namespaceURI,
-                                          Definition def)
+                                          DescriptionElement desc)
   {
-    String tempNSUri = def.getNamespace(prefix);
+    String tempNSUri = desc.getNamespace(prefix);
 
     if (tempNSUri != null && tempNSUri.equals(namespaceURI))
     {
@@ -343,10 +345,10 @@
     while (tempNSUri != null && !tempNSUri.equals(namespaceURI))
     {
       prefix += "_";
-      tempNSUri = def.getNamespace(prefix);
+      tempNSUri = desc.getNamespace(prefix);
     }
 
-    def.addNamespace(prefix, namespaceURI);
+    desc.addNamespace(prefix, namespaceURI);
   }
 
   /**

Modified: incubator/woden/java/src/org/apache/woden/internal/util/dom/QNameUtils.java
URL: http://svn.apache.org/viewcvs/incubator/woden/java/src/org/apache/woden/internal/util/dom/QNameUtils.java?rev=293236&r1=293235&r2=293236&view=diff
==============================================================================
--- incubator/woden/java/src/org/apache/woden/internal/util/dom/QNameUtils.java (original)
+++ incubator/woden/java/src/org/apache/woden/internal/util/dom/QNameUtils.java Sun Oct  2
21:49:36 2005
@@ -15,7 +15,11 @@
  */
 package org.apache.woden.internal.util.dom;
 
+import java.util.List;
+
 import javax.xml.namespace.QName;
+
+import org.apache.woden.internal.util.StringUtils;
 import org.w3c.dom.Node;
 
 public class QNameUtils
@@ -33,7 +37,38 @@
     }
     else
     {
-      return new QName(null, null);
+      return null;
     }
+  }
+  
+  /*
+   * TODO can use DOMUtils.getQName instead. Remove this method if it's not used.
+   * 
+   * We expect the qnString to be in qname format 'prefix:localname', 
+   * but will also accept just a 'localname'. If it is null or in
+   * any other format we cannot create a qname from it, so return null.
+   */
+  public static QName newQName(String qnString)
+  {
+      QName qname = null;
+      
+      if(qnString != null)
+      {
+          int i = qnString.indexOf(":");
+          int j = qnString.lastIndexOf(":");
+
+          if(i == -1)
+          {
+              //no ":" delimiter so assume localname only, no prefix
+              qname = new QName(null, qnString);
+          }
+          else if(i == j && i < qnString.length()-1)
+          {
+              //we have one ":" delimiter and it is not the last character
+              qname = new QName(qnString.substring(0,i), qnString.substring(i+1));
+          }
+      }
+      
+      return qname;
   }
 }



---------------------------------------------------------------------
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