ws-woden-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Kaputin <KAPU...@uk.ibm.com>
Subject Re: svn commit: r321330 - in /incubator/woden/java: src/javax/xml/namespace/QName.java test/javax/xml/namespace/QNameTest.java test/javax/xml/namespace/serialized_QName_no_prefix test/org/apache/woden/tests/AllWodenTests.java
Date Mon, 17 Oct 2005 14:34:28 GMT
Good point. I'll change it back.

I changed '==' to .equals() to conform with the QName javadoc at:

http://java.sun.com/j2ee/1.4/docs/api/javax/xml/namespace/QName.html#equals(java.lang.Object)

which explicitly mentions String.equals().  However, because we are using
interned strings, the result will always be the same and '==' is faster as
you say.

thanks,
John Kaputin



                                                                           
             Jeremy Hughes                                                 
             <hughesj@apache.o                                             
             rg>                                                        To 
             Sent by:                  woden-dev@ws.apache.org             
             jpjhughes@gmail.c                                          cc 
             om                                                            
                                                                   Subject 
                                       Re: svn commit: r321330 - in        
             17/10/2005 11:50          /incubator/woden/java:              
                                       src/javax/xml/namespace/QName.java  
                                       test/javax/xml/namespace/QNameTest. 
             Please respond to         java                                
                 woden-dev             test/javax/xml/namespace/serialized 
                                       _QName_no_prefix                    
                                       test/org/apache/woden/tests/AllWode 
                                       nTests.java                         
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           




Hi John,
I noticed you changed:

    if ((namespaceURI == ((QName)obj).namespaceURI)
        && (localPart == ((QName)obj).localPart))

to

    if (namespaceURI.equals(((QName)obj).namespaceURI)
        && localPart.equals(((QName)obj).localPart))

this shouldn't be necessary as QName uses 'interned' strings, so the
old way should work and be more performant.

Jeremy

On 10/15/05, jkaputin@apache.org <jkaputin@apache.org> wrote:
> Author: jkaputin
> Date: Sat Oct 15 06:13:28 2005
> New Revision: 321330
>
> URL: http://svn.apache.org/viewcvs?rev=321330&view=rev
> Log:
> QName updated to v1.1 to include 'prefix', IllegalArgExc
>
> in ctors for null 'localPart', a readObject() method
>
> to initialize deserialized v1.0 QNames with an empty
>
> string 'prefix' and improved string validation in
>
> valueOf() method. Also, junit testcases for QName.
>
> Added:
>     incubator/woden/java/test/javax/xml/namespace/QNameTest.java
>
incubator/woden/java/test/javax/xml/namespace/serialized_QName_no_prefix
(with props)
> Modified:
>     incubator/woden/java/src/javax/xml/namespace/QName.java
>     incubator/woden/java/test/org/apache/woden/tests/AllWodenTests.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=321330&r1=321329&r2=321330&view=diff

>
==============================================================================

> --- incubator/woden/java/src/javax/xml/namespace/QName.java (original)
> +++ incubator/woden/java/src/javax/xml/namespace/QName.java Sat Oct 15
06:13:28 2005
> @@ -15,21 +15,46 @@
>   */
>
>  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
>
>   * as specified in <a href="http://www.w3.org/TR/xmlschema-2/#QName">XML
>
>   * Schema Part2: Datatypes specification</a>.
>
>   * <p>
>
> - * The value of a QName contains a <b>namespaceURI</b> and a
<b>localPart</b>.
>
> + * The WSDL4J version of QName has been copied and updated for Apache
Woden.
>
> + * It now conforms to the version 1.1 QName described in the Javadoc at
>
> + * <code>
>
> + * "http://java.sun.com/j2ee/1.4/docs/api/javax/xml/namespace/QName.html
".
>
> + * </code>
>
> + * <p>
>
> + * The value of a QName contains a <b>namespaceURI</b>, a
<b>localPart</b>
>
> + * and a <b>prefix</b>.
>
>   * The localPart provides the local part of the qualified name. The
>
> - * namespaceURI is a URI reference identifying the namespace.
>
> + * namespaceURI is a URI reference identifying the namespace. The prefix
>
> + * corresponds to a namespace declaration 'xmlns:somePrefix' in the
underlying xml.
>
>   *
>
>   * Note: Some of this impl code was taken from Axis.
>
> + * <p>
>
> + * The constructors throw an IllegalArgumentException if the 'localPart'
>
> + * argument is null, but if it is the empty string ("") they just create
>
> + * the QName object with the localPart set to the empty string.
>
> + * The 'prefix' property defaults to the empty string for the two
>
> + * constructors that do not take a 'prefix' argument.
>
> + * The constructor that does take a 'prefix' argument will throw an
>
> + * IllegalArgumentException if a null value is used (i.e. the absence
>
> + * of any 'prefix' must be specified explicitly as the empty string "").
>
> + * To support the deserialization of objects that were serialized with
an
>
> + * older version of QName (i.e. without a 'prefix' field), the
>
> + * <code>readObject</code> method will check if the 'prefix'
>
> + * value is null after default deserialization and if so, change it to
the
>
> + * empty string.
>
>   *
>
>   * @author axis-dev
>
>   * @author Matthew J. Duftler (duftler@us.ibm.com)
>
> + * @author jkaputin@apache.org
>
>   */
>
>  public class QName implements Serializable
>
>  {
>
> @@ -41,39 +66,98 @@
>
>
>    // Field localPart.
>
>    private String localPart;
>
> +
>
> +  // Field prefix.
>
> +  private String prefix;
>
>
>
>    private static final long serialVersionUID = -9120448754896609940L;
>
>
>
>    /**
>
>     * Constructor for the QName.
>
> +   * Takes a localPart and sets the namespace and prefix to
>
> +   * the empty string "".
>
>     *
>
>     * @param localPart Local part of the QName
>
> +   *
>
> +   * @throws IllegalArgumentException if localPart is null.
>
>     */
>
>    public QName(String localPart)
>
>    {
>
>      this.namespaceURI = emptyString;
>
> -    this.localPart    = (localPart == null)
>
> -                        ? emptyString
>
> -                        : localPart.intern();
>
> +    if(localPart != null)
>
> +    {
>
> +        this.localPart = localPart.intern();
>
> +    }
>
> +    else
>
> +    {
>
> +        throw new IllegalArgumentException("localpart is null.");
>
> +    }
>
> +    this.prefix       = emptyString;
>
>    }
>
>
>
>    /**
>
>     * Constructor for the QName.
>
> +   * Takes a localPart and a namespace and sets the prefix to
>
> +   * the empty string "". If namespace is null, it defaults to
>
> +   * the empty string.
>
>     *
>
>     * @param namespaceURI Namespace URI for the QName
>
>     * @param localPart Local part of the QName.
>
> +   *
>
> +   * @throws IllegalArgumentException if localPart is null.
>
>     */
>
>    public QName(String namespaceURI, String localPart)
>
>    {
>
>      this.namespaceURI = (namespaceURI == null)
>
>                          ? emptyString
>
>                          : namespaceURI.intern();
>
> -    this.localPart    = (localPart == null)
>
> -                        ? emptyString
>
> -                        : localPart.intern();
>
> +    if(localPart != null)
>
> +    {
>
> +        this.localPart = localPart.intern();
>
> +    }
>
> +    else
>
> +    {
>
> +        throw new IllegalArgumentException("localpart is null.");
>
> +    }
>
> +    this.prefix       = emptyString;
>
>    }
>
>
>
>    /**
>
> +   * Constructor for the QName.
>
> +   * Takes a localPart, a namespace and a prefix. If the namespace is
>
> +   * null, it defaults to the empty string "". The prefix cannot be
>
> +   * null. If there is no prefix, an empty string "" must be used.
>
> +   *
>
> +   * @param namespaceURI Namespace URI for the QName
>
> +   * @param localPart Local part of the QName.
>
> +   * @param prefix the xmlns-declared prefix for this namespaceURI
>
> +   *
>
> +   * @throws IllegalArgumentException if localPart is null.
>
> +   */
>
> +  public QName(String namespaceURI, String localPart, String prefix)
>
> +  {
>
> +    this.namespaceURI = (namespaceURI == null)
>
> +                        ? emptyString
>
> +                        : namespaceURI.intern();
>
> +    if(localPart != null)
>
> +    {
>
> +        this.localPart = localPart.intern();
>
> +    }
>
> +    else
>
> +    {
>
> +        throw new IllegalArgumentException("localpart is null.");
>
> +    }
>
> +    if(prefix != null)
>
> +    {
>
> +        this.prefix = prefix.intern();
>
> +    }
>
> +    else
>
> +    {
>
> +        throw new IllegalArgumentException("prefix is null.");
>
> +    }
>
> +  }
>
> +
>
> +  /**
>
>     * Gets the Namespace URI for this QName
>
>     *
>
>     * @return Namespace URI
>
> @@ -92,6 +176,16 @@
>    {
>
>      return localPart;
>
>    }
>
> +
>
> +  /**
>
> +   * Gets the prefix for this QName
>
> +   *
>
> +   * @return prefix of this QName
>
> +   */
>
> +  public String getPrefix()
>
> +  {
>
> +      return prefix;
>
> +  }
>
>
>
>    /**
>
>     * Returns a string representation of this QName
>
> @@ -114,7 +208,8 @@
>     * For two QNames to be considered equal requires that both
>
>     * localPart and namespaceURI must be equal. This method uses
>
>     * <code>String.equals</code> to check equality of localPart
>
> -   * and namespaceURI. Any class that extends QName is required
>
> +   * and namespaceURI. The prefix is NOT used to determine equality.
>
> +   * Any class that extends QName is required
>
>     * to satisfy this equality contract.
>
>     * <p>
>
>     * This method satisfies the general contract of the
<code>Object.equals</code> method.
>
> @@ -136,8 +231,8 @@
>        return false;
>
>      }
>
>
>
> -    if ((namespaceURI == ((QName)obj).namespaceURI)
>
> -        && (localPart == ((QName)obj).localPart))
>
> +    if (namespaceURI.equals(((QName)obj).namespaceURI)
>
> +        && localPart.equals(((QName)obj).localPart))
>
>      {
>
>        return true;
>
>      }
>
> @@ -151,6 +246,11 @@
>     * The string must be in the form returned by the QName.toString()
>
>     * method, i.e. "{namespaceURI}localPart", with the "{namespaceURI}"
>
>     * part being optional.
>
> +   * If the Namespace URI .equals(""), only the local part should be
>
> +   * provided.
>
> +   * <p>
>
> +   * The prefix value CANNOT be represented in the String and will be
>
> +   * set to "".
>
>     * <p>
>
>     * This method doesn't do a full validation of the resulting QName.
>
>     * In particular, it doesn't check that the resulting namespace URI
>
> @@ -164,32 +264,47 @@
>     */
>
>    public static QName valueOf(String s)
>
>    {
>
> -    if ((s == null) || s.equals(""))
>
> +    if (s == null)
>
>      {
>
> -      throw new IllegalArgumentException("Invalid QName literal.");
>
> +      throw new IllegalArgumentException(
>
> +                  "Invalid QName literal - null string.");
>
>      }
>
>
>
> +    if (s.equals(""))
>
> +    {
>
> +      throw new IllegalArgumentException(
>
> +                  "Invalid QName literal - empty string.");
>
> +    }
>
> +
>
> +    int a = s.indexOf("{");
>
> +    int b = s.lastIndexOf("{");
>
> +    int c = s.indexOf("}");
>
> +    int d = s.lastIndexOf("}");
>
> +
>
> +    if(   a > 0                //'{' is not the first character
>
> +       || a != b               //more than one '{' exists
>
> +       || a != -1 && c == -1   //'{' not matched by a '}'
>
> +       || a == -1 && c != -1   //'}' not matched by a '{'
>
> +       || c != d               //more than one '}' exists
>
> +       || c == s.length() - 1  //namespace only, no local part
>
> +      )
>
> +    {
>
> +        throw new IllegalArgumentException(
>
> +                "Invalid QName literal '" + s + "'.");
>
> +    }
>
> +
>
> +    //We have confirmed that if the qname-as-string contains
>
> +    //'{' and '}' braces then they are correctly formatted.
>
> +
>
>      if (s.charAt(0) == '{')
>
>      {
>
> -      int i = s.indexOf('}');
>
> -
>
> -      if (i == -1)
>
> -      {
>
> -        throw new IllegalArgumentException("Invalid QName literal.");
>
> -      }
>
> -
>
> -      if (i == s.length() - 1)
>
> -      {
>
> -        throw new IllegalArgumentException("Invalid QName literal.");
>
> -      }
>
> -      else
>
> -      {
>
> -        return new QName(s.substring(1, i), s.substring(i + 1));
>
> -      }
>
> +        //namespace and local part
>
> +        return new QName(s.substring(1, c), s.substring(c + 1));
>
>      }
>
>      else
>
>      {
>
> -      return new QName(s);
>
> +        //local part only
>
> +        return new QName(s);
>
>      }
>
>    }
>
>
>
> @@ -206,6 +321,17 @@
>      return namespaceURI.hashCode() ^ localPart.hashCode();
>
>    }
>
>
>
> +  /**
>
> +   * Sets the object variables to internal strings matching the values
>
> +   * from the input stream. If the serialized object represents an
>
> +   * older version of QName that did not support the 'prefix' variable,
>
> +   * then 'prefix' will be set to null by
<code>defaultReadObject()</code>.
>
> +   * In this case, change the 'prefix' to the empty string "".
>
> +   *
>
> +   * @param in
>
> +   * @throws IOException
>
> +   * @throws ClassNotFoundException
>
> +   */
>
>    private void readObject(ObjectInputStream in) throws IOException,
>
>
ClassNotFoundException
>
>    {
>
> @@ -213,5 +339,16 @@
>
>
>      namespaceURI = namespaceURI.intern();
>
>      localPart    = localPart.intern();
>
> +    if(prefix == null)
>
> +    {
>
> +        //The serialized object did not have a 'prefix'.
>
> +        //i.e. it was serialized from an old version of QName.
>
> +        prefix = emptyString;
>
> +    }
>
> +    else
>
> +    {
>
> +        prefix = prefix.intern();
>
> +    }
>
>    }
>
> +
>
>  }
>
> Added: incubator/woden/java/test/javax/xml/namespace/QNameTest.java
> URL:
http://svn.apache.org/viewcvs/incubator/woden/java/test/javax/xml/namespace/QNameTest.java?rev=321330&view=auto

>
==============================================================================

> --- incubator/woden/java/test/javax/xml/namespace/QNameTest.java (added)
> +++ incubator/woden/java/test/javax/xml/namespace/QNameTest.java Sat Oct
15 06:13:28 2005
> @@ -0,0 +1,539 @@
> +/**
>
> + * Copyright 2005 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 javax.xml.namespace;
>
> +
>
> +import java.io.ByteArrayInputStream;
>
> +import java.io.ByteArrayOutputStream;
>
> +import java.io.File;
>
> +import java.io.FileInputStream;
>
> +import java.io.IOException;
>
> +import java.io.ObjectInputStream;
>
> +import java.io.ObjectOutputStream;
>
> +import java.net.URL;
>
> +
>
> +import junit.framework.Test;
>
> +import junit.framework.TestCase;
>
> +import junit.framework.TestSuite;
>
> +
>
> +/**
>
> + * junit tests for the QName class.
>
> + *
>
> + * @author jkaputin@apache.org
>
> + */
>
> +public class QNameTest extends TestCase {
>
> +
>
> +    private static final String emptyString = "";
>
> +    private QName qname;
>
> +
>
> +
>
> +    public static Test suite()
>
> +    {
>
> +        return new TestSuite(QNameTest.class);
>
> +    }
>
> +
>
> +    /* ************************************************
>
> +     * Tests for ctor QName(locPart)
>
> +     * ************************************************/
>
> +
>
> +    public void testOneArgCtorGoodLocalPart()
>
> +    {
>
> +        qname = new QName("myLocalPart");
>
> +
>
> +        if(qname != null)
>
> +        {
>
> +            assertTrue("QName was not initialized correctly",
>
> +                       (qname.getNamespaceURI().equals(emptyString) &&
>
> +                        qname.getLocalPart().equals("myLocalPart") &&
>
> +                        qname.getPrefix().equals(emptyString))
>
> +                      );
>
> +        }
>
> +        else
>
> +        {
>
> +            fail("QName was not instantiated.");
>
> +        }
>
> +    }
>
> +
>
> +    public void testOneArgCtorGoodLocalPartEmptyString()
>
> +    {
>
> +        qname = new QName("");
>
> +
>
> +        if(qname != null)
>
> +        {
>
> +            assertTrue("QName was not initialized correctly",
>
> +                       (qname.getNamespaceURI().equals(emptyString) &&
>
> +                        qname.getLocalPart().equals(emptyString) &&
>
> +                        qname.getPrefix().equals(emptyString))
>
> +                      );
>
> +        }
>
> +        else
>
> +        {
>
> +            fail("QName was not instantiated.");
>
> +        }
>
> +    }
>
> +
>
> +    public void testOneArgCtorBadLocalPartNull()
>
> +    {
>
> +        boolean b = false;
>
> +
>
> +        try {
>
> +            qname = new QName(null);
>
> +        } catch (IllegalArgumentException e) {
>
> +            b = true;
>
> +        }
>
> +
>
> +        assertTrue("Expected an IllegalArgumentException because of null
localPart.", b);
>
> +    }
>
> +
>
> +    /* ************************************************
>
> +     * Tests for ctor QName(NS, locPart)
>
> +     * ************************************************/
>
> +
>
> +    public void testTwoArgCtorGoodNonEmptyStrings()
>
> +    {
>
> +        qname = new QName("myNamespace", "myLocalPart");
>
> +
>
> +        if(qname != null)
>
> +        {
>
> +            assertTrue("QName was not initialized correctly",
>
> +                       (qname.getNamespaceURI().equals("myNamespace") &&
>
> +                        qname.getLocalPart().equals("myLocalPart") &&
>
> +                        qname.getPrefix().equals(emptyString))
>
> +                      );
>
> +        }
>
> +        else
>
> +        {
>
> +            fail("QName was not instantiated.");
>
> +        }
>
> +    }
>
> +
>
> +    public void testTwoArgCtorGoodEmptyStrings()
>
> +    {
>
> +        qname = new QName("", "");
>
> +
>
> +        if(qname != null)
>
> +        {
>
> +            assertTrue("QName was not initialized correctly",
>
> +                       (qname.getNamespaceURI().equals(emptyString) &&
>
> +                        qname.getLocalPart().equals(emptyString) &&
>
> +                        qname.getPrefix().equals(emptyString))
>
> +                      );
>
> +        }
>
> +        else
>
> +        {
>
> +            fail("QName was not instantiated.");
>
> +        }
>
> +    }
>
> +
>
> +    public void testTwoArgCtorGoodNullNamespaceURI()
>
> +    {
>
> +        qname = new QName(null, "myLocalPart");
>
> +
>
> +        if(qname != null)
>
> +        {
>
> +            assertTrue("QName was not initialized correctly",
>
> +                       (qname.getNamespaceURI().equals(emptyString) &&
>
> +                        qname.getLocalPart().equals("myLocalPart") &&
>
> +                        qname.getPrefix().equals(emptyString))
>
> +                      );
>
> +        }
>
> +        else
>
> +        {
>
> +            fail("QName was not instantiated.");
>
> +        }
>
> +    }
>
> +
>
> +    public void testTwoArgCtorBadNullLocalPart()
>
> +    {
>
> +        boolean b = false;
>
> +
>
> +        try {
>
> +            qname = new QName("myNamespace", null);
>
> +        } catch (IllegalArgumentException e) {
>
> +            b = true;
>
> +        }
>
> +
>
> +        assertTrue("Expected an IllegalArgumentException because of null
localPart.", b);
>
> +    }
>
> +
>
> +    /* ************************************************
>
> +     * Tests for ctor QName(NS, locPart, prefix)
>
> +     * ************************************************/
>
> +
>
> +    public void testThreeArgCtorGoodNonEmptyStrings()
>
> +    {
>
> +        qname = new QName("myNamespace", "myLocalPart", "myPrefix");
>
> +
>
> +        if(qname != null)
>
> +        {
>
> +            assertTrue("QName was not initialized correctly",
>
> +                       (qname.getNamespaceURI().equals("myNamespace") &&
>
> +                        qname.getLocalPart().equals("myLocalPart") &&
>
> +                        qname.getPrefix().equals("myPrefix"))
>
> +                      );
>
> +        }
>
> +        else
>
> +        {
>
> +            fail("QName was not instantiated.");
>
> +        }
>
> +    }
>
> +
>
> +    public void testThreeArgCtorGoodEmptyStrings()
>
> +    {
>
> +        qname = new QName("", "", "");
>
> +
>
> +        if(qname != null)
>
> +        {
>
> +            assertTrue("QName was not initialized correctly",
>
> +                       (qname.getNamespaceURI().equals(emptyString) &&
>
> +                        qname.getLocalPart().equals(emptyString) &&
>
> +                        qname.getPrefix().equals(emptyString))
>
> +                      );
>
> +        }
>
> +        else
>
> +        {
>
> +            fail("QName was not instantiated.");
>
> +        }
>
> +    }
>
> +
>
> +    public void testThreeArgCtorGoodNullNamespaceURI()
>
> +    {
>
> +        qname = new QName(null, "myLocalPart", "myPrefix");
>
> +
>
> +        if(qname != null)
>
> +        {
>
> +            assertTrue("QName was not initialized correctly",
>
> +                       (qname.getNamespaceURI().equals(emptyString) &&
>
> +                        qname.getLocalPart().equals("myLocalPart") &&
>
> +                        qname.getPrefix().equals("myPrefix"))
>
> +                      );
>
> +        }
>
> +        else
>
> +        {
>
> +            fail("QName was not instantiated.");
>
> +        }
>
> +    }
>
> +
>
> +    public void testThreeArgCtorBadNullLocalPart()
>
> +    {
>
> +        boolean b = false;
>
> +
>
> +        try {
>
> +            qname = new QName("myNamespace", null, "myPrefix");
>
> +        } catch (IllegalArgumentException e) {
>
> +            b = true;
>
> +        }
>
> +
>
> +        assertTrue("Expected an IllegalArgumentException because of null
localPart.", b);
>
> +    }
>
> +
>
> +    public void testThreeArgCtorBadNullPrefix()
>
> +    {
>
> +        boolean b = false;
>
> +
>
> +        try {
>
> +            qname = new QName("myNamespace", "myLocalPart", null);
>
> +        } catch (IllegalArgumentException e) {
>
> +            b = true;
>
> +        }
>
> +
>
> +        assertTrue("Expected an IllegalArgumentException because of null
prefix.", b);
>
> +    }
>
> +
>
> +    /* ************************************************
>
> +     * Tests for valueOf(String) method
>
> +     * ************************************************/
>
> +
>
> +    public void testValueOfGoodNamespaceAndLocalPart()
>
> +    {
>
> +        qname = QName.valueOf("{myNamespace}myLocalPart");
>
> +
>
> +        if(qname != null)
>
> +        {
>
> +            assertTrue("QName was not initialized correctly",
>
> +                       (qname.getNamespaceURI().equals("myNamespace") &&
>
> +                        qname.getLocalPart().equals("myLocalPart") &&
>
> +                        qname.getPrefix().equals(emptyString))
>
> +                      );
>
> +        }
>
> +        else
>
> +        {
>
> +            fail("QName was not instantiated.");
>
> +        }
>
> +    }
>
> +
>
> +    public void testValueOfGoodLocalPartOnly()
>
> +    {
>
> +        qname = QName.valueOf("myLocalPart");
>
> +
>
> +        if(qname != null)
>
> +        {
>
> +            assertTrue("QName was not initialized correctly",
>
> +                       (qname.getNamespaceURI().equals(emptyString) &&
>
> +                        qname.getLocalPart().equals("myLocalPart") &&
>
> +                        qname.getPrefix().equals(emptyString))
>
> +                      );
>
> +        }
>
> +        else
>
> +        {
>
> +            fail("QName was not instantiated.");
>
> +        }
>
> +    }
>
> +
>
> +    public void testValueOfBadNullString()
>
> +    {
>
> +        boolean b = false;
>
> +
>
> +        try {
>
> +            qname = QName.valueOf(null);
>
> +        } catch (IllegalArgumentException e) {
>
> +            b = true;
>
> +        }
>
> +
>
> +        assertTrue("Expected an IllegalArgumentException because " +
>
> +                   "qname string argument cannot be null.",
>
> +                   b);
>
> +    }
>
> +
>
> +    public void testValueOfBadEmptyString()
>
> +    {
>
> +        boolean b = false;
>
> +
>
> +        try {
>
> +            qname = QName.valueOf("");
>
> +        } catch (IllegalArgumentException e) {
>
> +            b = true;
>
> +        }
>
> +
>
> +        assertTrue("Expected an IllegalArgumentException because " +
>
> +                   "qname string argument cannot be the empty string
\"\".",
>
> +                   b);
>
> +    }
>
> +
>
> +    public void testValueOfBadLeftBraceNotLeftmost()
>
> +    {
>
> +        boolean b = false;
>
> +
>
> +        try {
>
> +            qname = QName.valueOf("x{myNamespace}myLocalPart");
>
> +        } catch (IllegalArgumentException e) {
>
> +            b = true;
>
> +        }
>
> +
>
> +        assertTrue("Expected an IllegalArgumentException because " +
>
> +                   "'{' is not the leftmost character.",
>
> +                   b);
>
> +    }
>
> +
>
> +    public void testValueOfBadMultipleLeftBraces()
>
> +    {
>
> +        boolean b = false;
>
> +
>
> +        try {
>
> +            qname = QName.valueOf("{myNam{espace}myLocalPart");
>
> +        } catch (IllegalArgumentException e) {
>
> +            b = true;
>
> +        }
>
> +
>
> +        assertTrue("Expected an IllegalArgumentException because " +
>
> +                   "there is more that one '{'.",
>
> +                   b);
>
> +    }
>
> +
>
> +    public void testValueOfBadUnmatchedLeftBrace()
>
> +    {
>
> +        boolean b = false;
>
> +
>
> +        try {
>
> +            qname = QName.valueOf("{myNamespacemyLocalPart");
>
> +        } catch (IllegalArgumentException e) {
>
> +            b = true;
>
> +        }
>
> +
>
> +        assertTrue("Expected an IllegalArgumentException because " +
>
> +                   "a '{' does not have a matching '}'.",
>
> +                   b);
>
> +    }
>
> +
>
> +    public void testValueOfBadUnmatchedRightBrace()
>
> +    {
>
> +        boolean b = false;
>
> +
>
> +        try {
>
> +            qname = QName.valueOf("myNamespace}myLocalPart");
>
> +        } catch (IllegalArgumentException e) {
>
> +            b = true;
>
> +        }
>
> +
>
> +        assertTrue("Expected an IllegalArgumentException because " +
>
> +                   "a '}' does not have a matching '{'.",
>
> +                   b);
>
> +    }
>
> +
>
> +    public void testValueOfBadMultipleRightBraces()
>
> +    {
>
> +        boolean b = false;
>
> +
>
> +        try {
>
> +            qname = QName.valueOf("{myNam}espace}myLocalPart");
>
> +        } catch (IllegalArgumentException e) {
>
> +            b = true;
>
> +        }
>
> +
>
> +        assertTrue("Expected an IllegalArgumentException because " +
>
> +                   "there is more that one '}'.",
>
> +                   b);
>
> +    }
>
> +
>
> +    public void testValueOfBadNoLocalpart()
>
> +    {
>
> +        boolean b = false;
>
> +
>
> +        try {
>
> +            qname = QName.valueOf("{myNamespace}");
>
> +        } catch (IllegalArgumentException e) {
>
> +            b = true;
>
> +        }
>
> +
>
> +        assertTrue("Expected an IllegalArgumentException because " +
>
> +                   "the string only has a namespaceURI, but no
localPart.",
>
> +                   b);
>
> +    }
>
> +
>
> +    /* ************************************************
>
> +     * Tests for deserializing.
>
> +     * ************************************************/
>
> +
>
> +    public void testGoodSerializeThenDeserialize() throws IOException,
>
> +
ClassNotFoundException
>
> +    {
>
> +        //Serialize a QName then deserialize it to test it has been
initialized
>
> +        //correctly by the readObject() method.
>
> +
>
> +        qname = new QName("myNamespace", "myLocalPart", "myPrefix");
>
> +
>
> +        ByteArrayOutputStream baos = new ByteArrayOutputStream();
>
> +        ObjectOutputStream oos = new ObjectOutputStream(baos);
>
> +        oos.writeObject(qname);
>
> +        oos.close();
>
> +
>
> +        QName qnameCopy = null;
>
> +
>
> +        ObjectInputStream ois =
>
> +            new ObjectInputStream(new
ByteArrayInputStream(baos.toByteArray()));
>
> +        Object o = ois.readObject();
>
> +        qnameCopy = (QName)o;
>
> +        ois.close();
>
> +
>
> +        assertTrue("QName was not initialized correctly after
deserialization.",
>
> +                (qnameCopy.getNamespaceURI().equals("myNamespace") &&
>
> +                 qnameCopy.getLocalPart().equals("myLocalPart") &&
>
> +                 qnameCopy.getPrefix().equals("myPrefix")));
>
> +
>
> +    }
>
> +
>
> +    public void testGoodDeserializeQNameWithoutPrefix() throws
IOException,
>
> +
ClassNotFoundException, Exception
>
> +    {
>
> +        /*
>
> +         * Test that 'prefix' is initialized correctly when
deserializing a v1.0 QName.
>
> +         * The v1.0 QName does not have a 'prefix' field, so when it's
deserialized using
>
> +         * the v1.1 QName, its 'prefix' field should be set to the empty
string "", not
>
> +         * just initialized as null.
>
> +         *
>
> +         * The input to this testcase is a file containing a v1.0 QName
serialized
>
> +         * from the WSDL4J version of QName.
>
> +         */
>
> +
>
> +        URL url =
ClassLoader.getSystemResource("./javax/xml/namespace/serialized_QName_no_prefix");

>
> +
>
> +        File f = new File(url.getFile());
>
> +
>
> +        ObjectInputStream ois =
>
> +            new ObjectInputStream(new FileInputStream(f));
>
> +
>
> +        Object o = ois.readObject();
>
> +        qname = (QName)o;
>
> +
>
> +        assertTrue("Expected a null 'prefix' to be initialized to the
empty string \"\".",
>
> +                    qname.getPrefix() != null);
>
> +
>
> +    }
>
> +
>
> +
>
> +    /* ************************************************
>
> +     * Tests for equals(obj) method
>
> +     * ************************************************/
>
> +
>
> +    public void testEqualsGoodSameValues()
>
> +    {
>
> +        QName qn1, qn2;
>
> +        qn1 = new QName("myNamespace", "myLocalPart");
>
> +        qn2 = QName.valueOf("{myNamespace}myLocalPart");
>
> +
>
> +        assertTrue("Expected two QNames objects with the same values to
be equal.",
>
> +                   qn1.equals(qn2));
>
> +    }
>
> +
>
> +    public void testEqualsGoodDifferentPrefix()
>
> +    {
>
> +        /* the prefix is not used to determine equality, so even though
the prefixes
>
> +         * are different, the namespacesURIs and localParts are
equivalent so the
>
> +         * objects are equal.
>
> +         */
>
> +
>
> +        QName qn1, qn2;
>
> +        qn1 = new QName("myNamespace", "myLocalPart", "myPrefix");
>
> +        qn2 = QName.valueOf("{myNamespace}myLocalPart");   //prefix
defaults to ""
>
> +
>
> +        assertTrue("Expected two QNames objects with the same values to
be equal.",
>
> +                   qn1.equals(qn2));
>
> +    }
>
> +
>
> +    public void testEqualsGoodDifferentNamespaceAndLocalPart()
>
> +    {
>
> +        QName qn1, qn2;
>
> +        qn1 = new QName("myNamespace", "myLocalPart", "");
>
> +        qn2 = QName.valueOf("{yourNamespace}yourLocalPart"); //prefix
defaults to ""
>
> +
>
> +        assertFalse("Expected two QNames objects with different values
to be not equal.",
>
> +                   qn1.equals(qn2));
>
> +    }
>
> +
>
> +    public void testEqualsGoodSameObjectRef()
>
> +    {
>
> +        QName qn1, qn2;
>
> +        qn1 = new QName("myNamespace", "myLocalPart", "");
>
> +        qn2 = qn1;
>
> +
>
> +        //qn1 and qn2 now refer to the same object.
>
> +
>
> +        assertTrue("Expected two QNames with the same object reference
to be equal.",
>
> +                    qn1.equals(qn2));
>
> +    }
>
> +
>
> +    public void testEqualsGoodNotAQName()
>
> +    {
>
> +        QName qn1;
>
> +        qn1 = new QName("myNamespace", "myLocalPart", "");
>
> +        Object o = new Object();
>
> +
>
> +        assertFalse("Expected a QName and a different type of object to
be not equal.",
>
> +                   qn1.equals(o));
>
> +    }
>
> +
>
> +
>
> +
>
> +}
>
>
> Added:
incubator/woden/java/test/javax/xml/namespace/serialized_QName_no_prefix
> URL:
http://svn.apache.org/viewcvs/incubator/woden/java/test/javax/xml/namespace/serialized_QName_no_prefix?rev=321330&view=auto

>
==============================================================================

> Binary file - no diff available.
>
> Propchange:
incubator/woden/java/test/javax/xml/namespace/serialized_QName_no_prefix
>
------------------------------------------------------------------------------

>     svn:mime-type = application/octet-stream
>
> Modified:
incubator/woden/java/test/org/apache/woden/tests/AllWodenTests.java
> URL:
http://svn.apache.org/viewcvs/incubator/woden/java/test/org/apache/woden/tests/AllWodenTests.java?rev=321330&r1=321329&r2=321330&view=diff

>
==============================================================================

> --- incubator/woden/java/test/org/apache/woden/tests/AllWodenTests.java
(original)
> +++ incubator/woden/java/test/org/apache/woden/tests/AllWodenTests.java
Sat Oct 15 06:13:28 2005
> @@ -15,10 +15,13 @@
>   */
>
>  package org.apache.woden.tests;
>
>
>
> +import javax.xml.namespace.QNameTest;
>
> +
>
>  import junit.framework.Test;
>
>  import junit.framework.TestSuite;
>
>
>
>  import org.apache.woden.WSDLFactoryTest;
>
> +import org.apache.woden.WSDLReaderTest;
>
>  import org.apache.woden.internal.ReaderFeaturesTest;
>
>  import org.apache.woden.tests.wsdl20.W3CTestSuiteTest;
>
>
>
> @@ -40,8 +43,9 @@
>    public AllWodenTests()
>
>    {
>
>      super("AllWodenTests");
>
> +    addTest(QNameTest.suite());
>
>         addTest(WSDLFactoryTest.suite());
>
> -       //addTest(WSDLReaderTest.suite());
>
> +       addTest(WSDLReaderTest.suite());
>
>         addTest(W3CTestSuiteTest.suite());
>
>         addTestSuite(ReaderFeaturesTest.class);
>
>    }
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: woden-dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: woden-dev-help@ws.apache.org
>
>
>

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




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