axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Davanum Srinivas <d...@yahoo.com>
Subject Re: cvs commit: ws-axis/java/test/types TestURI.java PackageTests.java
Date Sat, 03 Apr 2004 09:47:17 GMT
forgot to mention that i picked up a few fixes from latest xerces URI.java.

--- dims@apache.org wrote:
> dims        2004/04/03 01:43:19
> 
>   Modified:    java/src/org/apache/axis/types URI.java
>                java/test/types PackageTests.java
>   Added:       java/test/types TestURI.java
>   Log:
>   Fix for AXIS-814 - URI does not over-ride hashcode()
>   reported by Sam Meder
>   
>   Revision  Changes    Path
>   1.6       +40 -23    ws-axis/java/src/org/apache/axis/types/URI.java
>   
>   Index: URI.java
>   ===================================================================
>   RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/types/URI.java,v
>   retrieving revision 1.5
>   retrieving revision 1.6
>   diff -u -r1.5 -r1.6
>   --- URI.java	25 Feb 2004 14:02:47 -0000	1.5
>   +++ URI.java	3 Apr 2004 09:43:19 -0000	1.6
>   @@ -437,7 +437,7 @@
>      private void initialize(URI p_base, String p_uriSpec)
>                             throws MalformedURIException {
>    	  
>   -    String uriSpec = (p_uriSpec != null) ? p_uriSpec.trim() : null;
>   +    String uriSpec = p_uriSpec;
>        int uriSpecLen = (uriSpec != null) ? uriSpec.length() : 0;
>    	
>        if (p_base == null && uriSpecLen == 0) {
>   @@ -456,28 +456,33 @@
>        // Check for scheme, which must be before '/', '?' or '#'. Also handle
>        // names with DOS drive letters ('D:'), so 1-character schemes are not
>        // allowed.
>   -    int colonIdx    = uriSpec.indexOf(':');
>   -    int slashIdx    = uriSpec.indexOf('/');
>   -    int queryIdx    = uriSpec.indexOf('?');
>   -    int fragmentIdx = uriSpec.indexOf('#');
>   -
>   -    if ((colonIdx < 2) ||
>   -        (colonIdx > slashIdx && slashIdx != -1) ||
>   -        (colonIdx > queryIdx && queryIdx != -1) ||
>   -        (colonIdx > fragmentIdx && fragmentIdx != -1)) {
>   -      // A standalone base is a valid URI according to spec
>   -      if (colonIdx == 0 || (p_base == null && fragmentIdx != 0)) {
>   -        throw new MalformedURIException("No scheme found in URI.");
>   -      }
>   +    int colonIdx = uriSpec.indexOf(':');
>   +    if (colonIdx != -1) {
>   +        final int searchFrom = colonIdx - 1;
>   +        // search backwards starting from character before ':'.
>   +        int slashIdx = uriSpec.lastIndexOf('/', searchFrom);
>   +        int queryIdx = uriSpec.lastIndexOf('?', searchFrom);
>   +        int fragmentIdx = uriSpec.lastIndexOf('#', searchFrom);
>   +       
>   +        if (colonIdx < 2 || slashIdx != -1 || 
>   +            queryIdx != -1 || fragmentIdx != -1) {
>   +            // A standalone base is a valid URI according to spec
>   +            if (colonIdx == 0 || (p_base == null && fragmentIdx != 0)) {
>   +                throw new MalformedURIException("No scheme found in URI.");
>   +            }
>   +        }
>   +        else {
>   +            initializeScheme(uriSpec);
>   +            index = m_scheme.length()+1;
>   +            
>   +            // Neither 'scheme:' or 'scheme:#fragment' are valid URIs.
>   +            if (colonIdx == uriSpecLen - 1 || uriSpec.charAt(colonIdx+1) == '#') {
>   +            	throw new MalformedURIException("Scheme specific part cannot be empty.");

>   +            }
>   +        }
>        }
>   -    else {
>   -      initializeScheme(uriSpec);
>   -      index = m_scheme.length()+1;
>   -      
>   -      // Neither 'scheme:' or 'scheme:#fragment' are valid URIs.
>   -      if (colonIdx == uriSpecLen - 1 || uriSpec.charAt(colonIdx+1) == '#') {
>   -      	throw new MalformedURIException("Scheme specific part cannot be empty.");	
>   -      }
>   +    else if (p_base == null && uriSpec.indexOf('#') != 0) {
>   +        throw new MalformedURIException("No scheme found in URI.");    
>        }
>    
>        // Two slashes means we may have authority, but definitely means we're either
>   @@ -1488,6 +1493,17 @@
>        return false;
>      }
>    
>   +    /**
>   +     * Returns a hash-code value for this URI.  The hash code is based upon all
>   +     * of the URI's components, and satisfies the general contract of the
>   +     * {@link java.lang.Object#hashCode() Object.hashCode} method. </p>
>   +     *
>   +     * @return  A hash-code value for this URI
>   +     */
>   +    public int hashCode() {
>   +        return toString().hashCode();
>   +    }
>   +    
>     /**
>      * Get the URI as a string specification. See RFC 2396 Section 5.2.
>      *
>   @@ -1954,3 +1970,4 @@
>        return true;
>      }
>    }
>   +
>   
>   
>   
>   1.7       +1 -0      ws-axis/java/test/types/PackageTests.java
>   
>   Index: PackageTests.java
>   ===================================================================
>   RCS file: /home/cvs/ws-axis/java/test/types/PackageTests.java,v
>   retrieving revision 1.6
>   retrieving revision 1.7
>   diff -u -r1.6 -r1.7
>   --- PackageTests.java	25 Feb 2004 14:02:59 -0000	1.6
>   +++ PackageTests.java	3 Apr 2004 09:43:19 -0000	1.7
>   @@ -54,6 +54,7 @@
>            suite.addTestSuite(TestNCName.class);
>            suite.addTestSuite(TestNMToken.class);
>            suite.addTestSuite(TestDuration.class);
>   +        suite.addTestSuite(TestURI.class);
>            return suite;
>        }
>    }
>   
>   
>   
>   1.1                  ws-axis/java/test/types/TestURI.java
>   
>   Index: TestURI.java
>   ===================================================================
>   /*
>    * Copyright 2002-2004 The 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 test.types;
>   
>   import junit.framework.TestCase;
>   import org.apache.axis.types.URI;
>   
>   /**
>    * Test validation of types.Day
>    */
>   public class TestURI extends TestCase {
>   
>       public TestURI(String name) {
>           super(name);
>       }
>   
>       /**
>        * Bug AXIS-814
>        */
>       public void testAxis814() throws Exception {
>           URI uri1 = new URI("urn:foobar");
>           URI uri2 = new URI("urn:foobar");
>           assertEquals(uri1,uri2);
>           assertEquals(uri1.hashCode(),uri2.hashCode());
>       }
>   }
>   
>   
>   


=====
Davanum Srinivas - http://webservices.apache.org/~dims/

Mime
View raw message