You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-dev@jakarta.apache.org by cm...@apache.org on 2002/12/25 13:19:59 UTC

cvs commit: jakarta-cactus/framework/src/java/share/org/apache/cactus/server AbstractWebTestController.java

cmlenz      2002/12/25 04:19:59

  Modified:    framework/src/java/share/org/apache/cactus
                        ServiceEnumeration.java
               framework/src/java/share/org/apache/cactus/server
                        AbstractWebTestController.java
  Log:
  - Introduced a new factory method ServiceEnumeration.valueOf(String)
    that returns the enumeration instance corresponding to the service
    name. This can be used to retrieve the instance for identity comparison.
  - Deprecated ServiceEnumeration.equals(String), and added final
    implementations of equals(Object) and hashCode() that delegate to the
    java.lang.Object implementation, so that they always operate on object
    identity.
  - Updated AbstractWebTestCaller to use ServiceEnumeration.valueOf() 
    and identity comparison instead of ServiceEnumeration.equals(String)
  
  Revision  Changes    Path
  1.6       +47 -10    jakarta-cactus/framework/src/java/share/org/apache/cactus/ServiceEnumeration.java
  
  Index: ServiceEnumeration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/ServiceEnumeration.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ServiceEnumeration.java	22 Dec 2002 17:54:17 -0000	1.5
  +++ ServiceEnumeration.java	25 Dec 2002 12:19:58 -0000	1.6
  @@ -113,7 +113,8 @@
        *
        * @param theString the string to compare with this Service name
        * @return true if the string corresponds to the current Service
  -     * @see java.lang.Object#equals
  +     * @deprecated Use {@link ServiceEnumeration#valueOf} and identity
  +     *              comparison instead of this method
        */
       public boolean equals(String theString)
       {
  @@ -121,16 +122,23 @@
       }
   
       /**
  -     * Calculates a hash code for the service.
  -     *
  -     * @return the hash code
  -     * @see java.lang.Object#hashCode
  +     * Always compares object identity.
  +     * 
  +     * @see java.lang.Object#equals(Object)
  +     */
  +    public final boolean equals(Object theObject)
  +    {
  +        return super.equals(theObject);
  +    }
  +
  +    /**
  +     * Delegates to the <code>java.lang.Object</code> implementation.
  +     * 
  +     * @see java.lang.Object#equals(Object)
        */
  -    public int hashCode()
  +    public final int hashCode()
       {
  -        int result = 17;
  -        result = 37 * result + this.name.hashCode();
  -        return result;
  +        return super.hashCode();
       }
   
       /**
  @@ -142,6 +150,35 @@
       public String toString()
       {
           return this.name;
  +    }
  +    
  +    /**
  +     * Returns the enumeration instance corresponding to the provided service 
  +     * name.
  +     * 
  +     * @param theName The name of the service
  +     * @return The corresponding service instance
  +     * @since Cactus 1.5
  +     */
  +    public static ServiceEnumeration valueOf(String theName)
  +    {
  +        if (CALL_TEST_SERVICE.name.equals(theName))
  +        {
  +            return CALL_TEST_SERVICE;
  +        }
  +        else if (GET_RESULTS_SERVICE.name.equals(theName))
  +        {
  +            return GET_RESULTS_SERVICE;
  +        }
  +        else if (RUN_TEST_SERVICE.name.equals(theName))
  +        {
  +            return RUN_TEST_SERVICE;
  +        }
  +        else if (CREATE_SESSION_SERVICE.name.equals(theName))
  +        {
  +            return CREATE_SESSION_SERVICE;
  +        }
  +        return null;
       }
       
   }
  
  
  
  1.8       +10 -11    jakarta-cactus/framework/src/java/share/org/apache/cactus/server/AbstractWebTestController.java
  
  Index: AbstractWebTestController.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/server/AbstractWebTestController.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- AbstractWebTestController.java	26 Sep 2002 21:27:49 -0000	1.7
  +++ AbstractWebTestController.java	25 Dec 2002 12:19:59 -0000	1.8
  @@ -121,29 +121,28 @@
   
               // FIXME: will need a factory here real soon...
               
  +            ServiceEnumeration service =
  +                ServiceEnumeration.valueOf(serviceName);
  +            
               // Is it the call test method service ?
  -            if (ServiceEnumeration.CALL_TEST_SERVICE.equals(serviceName))
  +            if (service == ServiceEnumeration.CALL_TEST_SERVICE)
               {
                   caller.doTest();
  -
  -            // Is it the get test results service ?
               }
  -            else if (ServiceEnumeration.GET_RESULTS_SERVICE.equals(serviceName))
  +            // Is it the get test results service ?
  +            else if (service == ServiceEnumeration.GET_RESULTS_SERVICE)
               {
                   caller.doGetResults();
  -
  +            }
               // Is it the test connection service ?
               // This service is only used to verify that connection between
               // client and server is working fine
  -            }
  -            else if (ServiceEnumeration.RUN_TEST_SERVICE.equals(serviceName))
  +            else if (service == ServiceEnumeration.RUN_TEST_SERVICE)
               {
                   caller.doRunTest();
               }
  -
               // Is it the service to create an HTTP session?
  -            else if (ServiceEnumeration.CREATE_SESSION_SERVICE.equals(
  -                serviceName))
  +            else if (service == ServiceEnumeration.CREATE_SESSION_SERVICE)
               {
                   caller.doCreateSession();                
               }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>