You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by hl...@apache.org on 2003/08/06 00:06:58 UTC

cvs commit: jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/service/impl AbstractServiceInterceptorFactory.java ClassFactoryImpl.java LoggingInterceptorFactory.java

hlship      2003/08/05 15:06:58

  Modified:    hivemind/src/java/org/apache/commons/hivemind/service/impl
                        AbstractServiceInterceptorFactory.java
                        ClassFactoryImpl.java
                        LoggingInterceptorFactory.java
  Log:
  Fix some problems with code generation concerning object arrays.
  
  Revision  Changes    Path
  1.5       +18 -2     jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/service/impl/AbstractServiceInterceptorFactory.java
  
  Index: AbstractServiceInterceptorFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/service/impl/AbstractServiceInterceptorFactory.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AbstractServiceInterceptorFactory.java	5 Aug 2003 14:07:17 -0000	1.4
  +++ AbstractServiceInterceptorFactory.java	5 Aug 2003 22:06:58 -0000	1.5
  @@ -90,7 +90,7 @@
           Class serviceInterfaceClass = stack.getServiceInterface();
           Module module = stack.getServiceExtensionPoint().getModule();
   
  -        String name ="$Interceptor_" + Long.toHexString(System.currentTimeMillis()) + "$" + _uid++;
  +        String name = "$Interceptor_" + Long.toHexString(System.currentTimeMillis()) + "$" + _uid++;
   
           ClassFab classFab = _factory.newClass(name, getInterceptorSuperclass(), module);
   
  @@ -218,5 +218,21 @@
                   m.getParameterTypes(),
                   m.getExceptionTypes());
           }
  +    }
  +
  +    /**
  +     * Convienience for converting a class into a proper name, compatibile
  +     * with {@link org.apache.commons.hivemind.service.MethodFab}.  It is important
  +     * that array types be converted properly, for array types,
  +     * getName() returns the incorrect value, but this method
  +     * returns the correct value.
  +     *
  +     */
  +    protected String getClassName(Class inputClass)
  +    {
  +        if (inputClass.isArray())
  +            return getClassName(inputClass.getComponentType()) + "[]";
  +
  +        return inputClass.getName();
       }
   }
  
  
  
  1.3       +21 -4     jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/service/impl/ClassFactoryImpl.java
  
  Index: ClassFactoryImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/service/impl/ClassFactoryImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ClassFactoryImpl.java	5 Aug 2003 14:07:18 -0000	1.2
  +++ ClassFactoryImpl.java	5 Aug 2003 22:06:58 -0000	1.3
  @@ -112,14 +112,16 @@
   
       public CtClass getClass(ClassPool pool, Class inputClass)
       {
  +        String name = getName(inputClass);
  +        
           try
           {
  -            return pool.get(inputClass.getName());
  +            return pool.get(name);
           }
           catch (NotFoundException ex)
           {
               throw new ApplicationRuntimeException(
  -                HiveMind.format("ClassFactoryImpl.unable-to-lookup", inputClass, ex.getMessage()),
  +                HiveMind.format("ClassFactoryImpl.unable-to-lookup", name, ex.getMessage()),
                   ex);
           }
       }
  @@ -147,7 +149,7 @@
       {
           String id = module.getModuleId();
   
  -        ClassPool result = (ClassPool) _poolMap.get(id);
  +        ClassPool result = (ClassPool)_poolMap.get(id);
   
           if (result == null)
           {
  @@ -163,5 +165,20 @@
           }
   
           return result;
  +    }
  +
  +    /**
  +     * Javassist needs the class name to be as it appears in code, even for arrays.
  +     * Invoking getName() on Class instance representing an array returns the itnernal
  +     * format (i.e, "[...;" or something).  This returns it as it would appear in
  +     * Java code.
  +     *
  +     */
  +    private String getName(Class inputClass)
  +    {
  +        if (inputClass.isArray())
  +            return getName(inputClass.getComponentType()) + "[]";
  +
  +        return inputClass.getName();
       }
   }
  
  
  
  1.4       +9 -9      jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/service/impl/LoggingInterceptorFactory.java
  
  Index: LoggingInterceptorFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/service/impl/LoggingInterceptorFactory.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- LoggingInterceptorFactory.java	9 Jul 2003 11:27:24 -0000	1.3
  +++ LoggingInterceptorFactory.java	5 Aug 2003 22:06:58 -0000	1.4
  @@ -107,20 +107,20 @@
           StringBuffer buffer = new StringBuffer(100);
   
           buffer.append("{\n\n");
  -        
  +
           buffer.append("boolean debug = _isDebugEnabled();\n\n");
   
           buffer.append("if (debug) _logEntry(" + QUOTE);
           buffer.append(methodName);
           buffer.append(QUOTE + ", $args);\n\n");
   
  -		if (!isVoid)
  -		{
  -			// May need work, for arrays and such.
  -			buffer.append(returnType);
  -			buffer.append(" result = ");
  -		}
  -		
  +        if (!isVoid)
  +        {
  +            // May need work, for arrays and such.
  +            buffer.append(getClassName(returnType));
  +            buffer.append(" result = ");
  +        }
  +
           buffer.append("_inner.");
           buffer.append(methodName);
           buffer.append("($$);\n\n");