hlship      2004/09/14 10:56:51

  Modified:    .        status.xml
               library/src/java/org/apache/hivemind/lib/impl
                        ServicePropertyFactory.java
               framework/src/java/org/apache/hivemind/service/impl
                        LoggingInterceptorFactory.java
               framework/src/java/org/apache/hivemind/service
                        ClassFabUtils.java
  Added:       framework/src/test/org/apache/hivemind/service/impl
                        TestLoggingInterceptorFactory.java
                        TestClassFabUtils.java
  Log:
  HIVEMIND-55: Make fabricated classes work with JDK proxies.
  
  Revision  Changes    Path
  1.2       +97 -0     
jakarta-hivemind/framework/src/test/org/apache/hivemind/service/impl/TestLoggingInterceptorFactory.java
  
  
  
  
  1.2       +42 -0     
jakarta-hivemind/framework/src/test/org/apache/hivemind/service/impl/TestClassFabUtils.java
  
  
  
  
  1.60      +6 -0      jakarta-hivemind/status.xml
  
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/status.xml,v
  retrieving revision 1.59
  retrieving revision 1.60
  diff -u -r1.59 -r1.60
  --- status.xml        13 Sep 2004 14:48:16 -0000      1.59
  +++ status.xml        14 Sep 2004 17:56:51 -0000      1.60
  @@ -37,6 +37,12 @@
         </action>
       </release>
   
  +   <release version="1.0" date="unreleased">
  +    <action type="fix" dev="HLS" fixes-bug="HIVEMIND-55">
  +      Ensure that the logging interceptor will work properly when wrapping 
around JDK dynamic proxies.
  +    </action>
  +   </release>
  +
      <release version="1.0-rc-2" date="Sep 11 2004">
         <action type="add" dev="HLS">
           Add method <code>getSymbolValue()</code> to RegistryInfrastructure 
and Module
  
  
  
  1.6       +1 -1      
jakarta-hivemind/library/src/java/org/apache/hivemind/lib/impl/ServicePropertyFactory.java
  
  Index: ServicePropertyFactory.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-hivemind/library/src/java/org/apache/hivemind/lib/impl/ServicePropertyFactory.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ServicePropertyFactory.java       13 Sep 2004 14:48:16 -0000      1.5
  +++ ServicePropertyFactory.java       14 Sep 2004 17:56:51 -0000      1.6
  @@ -111,7 +111,7 @@
       {
           cf.addInterface(serviceInterface);
   
  -        Class targetServiceClass = targetService.getClass();
  +        Class targetServiceClass = 
ClassFabUtils.getInstanceClass(targetService, serviceInterface);
   
           cf.addField("_targetService", targetServiceClass);
   
  
  
  
  1.10      +1 -1      
jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/LoggingInterceptorFactory.java
  
  Index: LoggingInterceptorFactory.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/LoggingInterceptorFactory.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- LoggingInterceptorFactory.java    13 Sep 2004 14:48:15 -0000      1.9
  +++ LoggingInterceptorFactory.java    14 Sep 2004 17:56:51 -0000      1.10
  @@ -219,7 +219,7 @@
   
       private void createInfrastructure(InterceptorStack stack, ClassFab 
classFab)
       {
  -        Class topClass = stack.peek().getClass();
  +        Class topClass = ClassFabUtils.getInstanceClass(stack.peek(), 
stack.getServiceInterface());
   
           classFab.addField("_log", Log.class);
   
  
  
  
  1.4       +36 -18    
jakarta-hivemind/framework/src/java/org/apache/hivemind/service/ClassFabUtils.java
  
  Index: ClassFabUtils.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/service/ClassFabUtils.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ClassFabUtils.java        12 Jun 2004 18:43:41 -0000      1.3
  +++ ClassFabUtils.java        14 Sep 2004 17:56:51 -0000      1.4
  @@ -16,10 +16,11 @@
   
   import java.lang.reflect.Method;
   import java.lang.reflect.Modifier;
  +import java.lang.reflect.Proxy;
   
   /**
    * Static class containing utility methods.
  - *
  + * 
    * @author Howard Lewis Ship
    */
   public class ClassFabUtils
  @@ -33,8 +34,7 @@
       }
   
       /**
  -     * Generates a unique class name, which will be in the
  -     * default package.
  +     * Generates a unique class name, which will be in the default package.
        */
   
       public static synchronized String generateClassName(String baseName)
  @@ -43,11 +43,10 @@
       }
   
       /**
  -     * Javassist needs the class name to be as it appears in source code, 
even for arrays.
  -     * Invoking getName() on a Class instance representing an array returns 
the internal
  -     * format (i.e, "[...;" or something).  This returns it as it would 
appear in
  -     * Java code.
  -     *
  +     * Javassist needs the class name to be as it appears in source code, 
even
  +     * for arrays. Invoking getName() on a Class instance representing an 
array
  +     * returns the internal format (i.e, "[...;" or something). This returns 
it
  +     * as it would appear in Java code.
        */
       public static String getJavaClassName(Class inputClass)
       {
  @@ -58,9 +57,9 @@
       }
   
       /**
  -     * Returns true if the method is the standard toString() method.
  -     * Very few interfaces will ever include this method as part of
  -     * the interface, but we have to be sure.
  +     * Returns true if the method is the standard toString() method. Very few
  +     * interfaces will ever include this method as part of the interface, 
but we
  +     * have to be sure.
        */
       public static boolean isToString(Method method)
       {
  @@ -77,8 +76,10 @@
        * Adds a <code>toString()</code> method to a class that returns a fixed,
        * pre-computed value.
        * 
  -     * @param classFab ClassFab used to construct the new class.
  -     * @param toStringResult fixed result to be returned by the method.
  +     * @param classFab
  +     *            ClassFab used to construct the new class.
  +     * @param toStringResult
  +     *            fixed result to be returned by the method.
        */
       public static void addToStringMethod(ClassFab classFab, String 
toStringResult)
       {
  @@ -88,10 +89,27 @@
           buffer.append(QUOTE);
           buffer.append(";");
   
  -        classFab.addMethod(
  -            Modifier.PUBLIC,
  -            new MethodSignature(String.class, "toString", null, null),
  -            buffer.toString());
  +        classFab.addMethod(Modifier.PUBLIC, new 
MethodSignature(String.class, "toString", null, null), buffer
  +                .toString());
       }
   
  -}
  +    /**
  +     * Returns the class of an instance. However, if the instance is, in 
fact, a
  +     * JDK proxy, returns the interfaceClass (because JDK proxies do not work
  +     * with Javassist).
  +     * 
  +     * @param instance
  +     *            the object instance to obtain a class from
  +     * @param interfaceClass
  +     *            the interface class to return if the instance is a JDK 
proxy.
  +     */
  +    public static Class getInstanceClass(Object instance, Class 
interfaceClass)
  +    {
  +        Class instanceClass = instance.getClass();
  +
  +        if (Proxy.isProxyClass(instanceClass))
  +            return interfaceClass;
  +
  +        return instanceClass;
  +    }
  +}
  \ No newline at end of file
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to