axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sc...@apache.org
Subject cvs commit: xml-axis/java/src/org/apache/axis/message PrefixedQName.java
Date Wed, 10 Apr 2002 18:49:40 GMT
scheu       02/04/10 11:49:40

  Modified:    java/src/javax/xml/rpc/namespace QName.java
               java/src/org/apache/axis/message PrefixedQName.java
  Log:
  Changed QName to final, intern'd NamespaceURI and LocalPart.
  
  Changed PrefixedQName so that it no longer extends QName.
  
  Revision  Changes    Path
  1.12      +31 -37    xml-axis/java/src/javax/xml/rpc/namespace/QName.java
  
  Index: QName.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/javax/xml/rpc/namespace/QName.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- QName.java	2 Apr 2002 22:05:18 -0000	1.11
  +++ QName.java	10 Apr 2002 18:49:40 -0000	1.12
  @@ -63,15 +63,19 @@
    * Upgraded the implementation so that the namespaceURI and localPart are
    * always non-null.  This simplifies the implementation, increases performance,
    * and cleans up NullPointerException problems.
  + * 
  + * Upgraded the implemenation to make QName a final class, changed the 
  + * namespaceURI and localPart to final (and interned) Strings, changed equals()
  + * to use == comparison on interned Strings.
    * @version 0.1
    */
  -public class QName {
  +public final class QName {
   
       /** Field namespaceURI           */
  -    private String namespaceURI = "";
  +    private final String namespaceURI;
   
       /** Field localPart           */
  -    private String localPart = "";
  +    private final String localPart;
   
       /**
        * Constructor for the QName.
  @@ -79,8 +83,7 @@
        * @param localPart - Local part of the QName
        */
       public QName(String localPart) {
  -        setNamespaceURI("");
  -        setLocalPart(localPart);
  +        this("", localPart);
       }
       
       /**
  @@ -90,20 +93,16 @@
        * @param localPart - Local part of the QName
        */
       public QName(String namespaceURI, String localPart) {
  -        setNamespaceURI(namespaceURI);
  -        setLocalPart(localPart);
  -    }
  -
  -    /**
  -     * Sets the Namespace URI for this QName
  -     *
  -     * @param namespaceURI
  -     */
  -    private void setNamespaceURI(String namespaceURI) {
  -        if (namespaceURI == null)
  -// should throw exception, but gotta clean up first            throw new IllegalArgumentException("namespaceURI
== null");
  -            namespaceURI = "";
  -        this.namespaceURI = namespaceURI;
  +        if (namespaceURI == null) {
  +            this.namespaceURI = ""; 
  +        } else {
  +            this.namespaceURI = namespaceURI.intern();
  +        }
  +        if (localPart == null) {
  +            this.localPart = ""; // This should really be an IllegalArgumentException
  +        } else {
  +            this.localPart = localPart.intern();
  +        }
       }
   
       /**
  @@ -112,19 +111,7 @@
        * @return namespaceURI
        */
       public String getNamespaceURI() {
  -        return (namespaceURI);
  -    }
  -
  -    /**
  -     * Sets the Local part for this QName
  -     *
  -     * @param localPart
  -     */
  -    private void setLocalPart(String localPart) {
  -        if (localPart == null)
  -// should throw exception, but gotta clean up first            throw new IllegalArgumentException("localPart
== null");
  -            localPart = "";
  -        this.localPart = localPart;
  +        return namespaceURI;
       }
   
       /**
  @@ -133,7 +120,7 @@
        * @return the Local part for this QName.
        */
       public String getLocalPart() {
  -        return (localPart);
  +        return localPart;
       }
   
       /**
  @@ -146,7 +133,7 @@
           if (namespaceURI.equals("")) {
               return localPart;
           } else {
  -            return namespaceURI + ":" + localPart;
  +            return (namespaceURI + ":" + localPart);
           }
       }
   
  @@ -165,11 +152,18 @@
           if (!(p1 instanceof QName)) {
               return false;
           }
  -
  -        if (namespaceURI.equals(((QName)p1).namespaceURI) &&
  -            localPart.equals(((QName)p1).localPart)) {
  +        
  +        if (namespaceURI == ((QName)p1).namespaceURI &&
  +            localPart == ((QName) p1).localPart) {
               return true;
           }
  +
  +        // Since the strings are interned, a direct == of the strings
  +        // is all that is needed.  Here is the old code.
  +        //    if (namespaceURI.equals(((QName)p1).namespaceURI) &&
  +        //        localPart.equals(((QName)p1).localPart)) {
  +        //        return true;
  +        //    }
           return false;
       }
   
  
  
  
  1.2       +22 -5     xml-axis/java/src/org/apache/axis/message/PrefixedQName.java
  
  Index: PrefixedQName.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/PrefixedQName.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PrefixedQName.java	25 Mar 2002 16:12:16 -0000	1.1
  +++ PrefixedQName.java	10 Apr 2002 18:49:40 -0000	1.2
  @@ -58,27 +58,44 @@
   import javax.xml.soap.Name;
   import javax.xml.rpc.namespace.QName;
   
  -public class PrefixedQName extends QName implements Name {
  +public class PrefixedQName implements Name {
       private String prefix;
  +    private QName qName;
       
       public PrefixedQName(String uri, String localName, String pre) {
  -        super(uri, localName);
  +        qName = new QName(uri, localName);
           prefix = pre;
       }
       
       public String getLocalName() {
  -        return super.getLocalPart();
  +        return qName.getLocalPart();
       }
       
       public String getQualifiedName() {
  -        return super.toString();
  +        return qName.toString();
       }
       
       public String getURI() {
  -        return super.getNamespaceURI();
  +        return qName.getNamespaceURI();
       }
       
       public String getPrefix() {
           return prefix;
  +    }
  +    public boolean equals(Object obj) {
  +        if (obj == this) {
  +            return true;
  +        }
  +        if (!(obj instanceof PrefixedQName)) {
  +            return false;
  +        }
  +        if (!qName.equals(((PrefixedQName)obj).qName)) {
  +            return false;
  +        }
  +        if ((prefix == null && ((PrefixedQName) obj).prefix == null) ||
  +            prefix.equals(((PrefixedQName)obj).prefix)) {
  +            return true;
  +        }
  +        return false;
       }
   }
  
  
  

Mime
View raw message