commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jcar...@apache.org
Subject svn commit: r321332 - in /jakarta/commons/sandbox/proxy/trunk/src: java/org/apache/commons/proxy/ java/org/apache/commons/proxy/factory/javassist/ java/org/apache/commons/proxy/interceptor/ test/org/apache/commons/proxy/
Date Sat, 15 Oct 2005 13:22:05 GMT
Author: jcarman
Date: Sat Oct 15 06:22:00 2005
New Revision: 321332

URL: http://svn.apache.org/viewcvs?rev=321332&view=rev
Log:
Moved getJavaClassName() method.

Modified:
    jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/ProxyUtils.java
    jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/javassist/JavassistMethodInvocation.java
    jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/javassist/JavassistUtils.java
    jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/interceptor/LoggingMethodInterceptor.java
    jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/TestProxyUtils.java

Modified: jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/ProxyUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/ProxyUtils.java?rev=321332&r1=321331&r2=321332&view=diff
==============================================================================
--- jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/ProxyUtils.java
(original)
+++ jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/ProxyUtils.java
Sat Oct 15 06:22:00 2005
@@ -28,9 +28,17 @@
  */
 public class ProxyUtils
 {
+//----------------------------------------------------------------------------------------------------------------------
+// Fields
+//----------------------------------------------------------------------------------------------------------------------
+
     public static final Object[] EMPTY_ARGUMENTS = new Object[0];
     public static final Class[] EMPTY_ARGUMENT_TYPES = new Class[0];
-    
+
+//----------------------------------------------------------------------------------------------------------------------
+// Static Methods
+//----------------------------------------------------------------------------------------------------------------------
+
     /**
      * Creates a "null object" which implements the <code>proxyClasses</code>.
      * @param proxyFactory the proxy factory to be used to create the proxy object
@@ -54,7 +62,6 @@
         return proxyFactory.createInvocationHandlerProxy( classLoader, new NullInvocationHandler(),
proxyClasses );
     }
 
-
     /**
      * <p>Gets an array of {@link Class} objects representing all interfaces implemented
by the given
      * class and its superclasses.</p>
@@ -107,4 +114,26 @@
         }
         return list;
     }
+
+    /**
+     * Returns the class name as you would expect to see it in Java code.
+     * <p>
+     * <b>Examples:</b>
+     * <ul>
+     *   <li>getJavaClassName( Object[].class ) == "Object[]"</li>
+     *   <li>getJavaClassName( Object[][].class ) == "Object[][]"</li>
+     *   <li>getJavaClassName( Integer.TYPE ) == "int"</li>
+     * </p>
+     * @param clazz the class
+     * @return the class' name as you would expect to see it in Java code
+     */
+    public static String getJavaClassName( Class clazz )
+    {
+        if( clazz.isArray() )
+        {
+            return getJavaClassName( clazz.getComponentType() ) + "[]";
+        }
+        return clazz.getName();
+    }
 }
+

Modified: jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/javassist/JavassistMethodInvocation.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/javassist/JavassistMethodInvocation.java?rev=321332&r1=321331&r2=321332&view=diff
==============================================================================
--- jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/javassist/JavassistMethodInvocation.java
(original)
+++ jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/javassist/JavassistMethodInvocation.java
Sat Oct 15 06:22:00 2005
@@ -124,14 +124,14 @@
             proceedBody.append( "\t" );
         }
         proceedBody.append( "( (" );
-        proceedBody.append( JavassistUtils.getJavaClassName( interfaceMethod.getDeclaringClass()
) );
+        proceedBody.append( ProxyUtils.getJavaClassName( interfaceMethod.getDeclaringClass()
) );
         proceedBody.append( " )target )." );
         proceedBody.append( interfaceMethod.getName() );
         proceedBody.append( "(" );
         for( int i = 0; i < argumentTypes.length; ++i )
         {
             proceedBody.append( "(" );
-            proceedBody.append( JavassistUtils.getJavaClassName( argumentTypes[i] ) );
+            proceedBody.append( ProxyUtils.getJavaClassName( argumentTypes[i] ) );
             proceedBody.append( ")arguments[" );
             proceedBody.append( i );
             proceedBody.append( "]" );

Modified: jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/javassist/JavassistUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/javassist/JavassistUtils.java?rev=321332&r1=321331&r2=321332&view=diff
==============================================================================
--- jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/javassist/JavassistUtils.java
(original)
+++ jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/javassist/JavassistUtils.java
Sat Oct 15 06:22:00 2005
@@ -22,6 +22,7 @@
 import javassist.CtField;
 import javassist.NotFoundException;
 import org.apache.commons.proxy.exception.ObjectProviderException;
+import org.apache.commons.proxy.ProxyUtils;
 
 /**
  * @author James Carman
@@ -51,22 +52,13 @@
     {
         try
         {
-            return classPool.get( getJavaClassName( clazz ) );
+            return classPool.get( ProxyUtils.getJavaClassName( clazz ) );
         }
         catch( NotFoundException e )
         {
             throw new ObjectProviderException(
                     "Unable to find class " + clazz.getName() + " in default Javassist class
pool.", e );
         }
-    }
-
-    public static String getJavaClassName( Class inputClass )
-    {
-        if( inputClass.isArray() )
-        {
-            return getJavaClassName( inputClass.getComponentType() ) + "[]";
-        }
-        return inputClass.getName();
     }
 
     public static void addInterfaces( CtClass ctClass, Class[] proxyClasses )

Modified: jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/interceptor/LoggingMethodInterceptor.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/interceptor/LoggingMethodInterceptor.java?rev=321332&r1=321331&r2=321332&view=diff
==============================================================================
--- jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/interceptor/LoggingMethodInterceptor.java
(original)
+++ jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/interceptor/LoggingMethodInterceptor.java
Sat Oct 15 06:22:00 2005
@@ -19,7 +19,7 @@
 import org.aopalliance.intercept.MethodInterceptor;
 import org.aopalliance.intercept.MethodInvocation;
 import org.apache.commons.logging.Log;
-import org.apache.commons.proxy.factory.javassist.JavassistUtils;
+import org.apache.commons.proxy.ProxyUtils;
 
 /**
  * An interceptor which logs each method invocation.
@@ -123,7 +123,7 @@
             return;
         }
         buffer.append( "(" );
-        buffer.append( JavassistUtils.getJavaClassName( input.getClass() ) );
+        buffer.append( ProxyUtils.getJavaClassName( input.getClass() ) );
         buffer.append( "){" );
         Object[] array = ( Object[] ) input;
         int count = array.length;

Modified: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/TestProxyUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/TestProxyUtils.java?rev=321332&r1=321331&r2=321332&view=diff
==============================================================================
--- jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/TestProxyUtils.java
(original)
+++ jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/TestProxyUtils.java
Sat Oct 15 06:22:00 2005
@@ -36,4 +36,19 @@
         assertNull( nullEcho.echoBack( "hello", "world" ) );
         assertEquals( ( int ) 0, nullEcho.echoBack( 12345 ) );
     }
+
+    public void testGetJavaClassName() throws Exception
+    {
+        assertEquals( "java.lang.Object[]", ProxyUtils.getJavaClassName( Object[].class )
);
+        assertEquals( "java.lang.Object[][]", ProxyUtils.getJavaClassName( Object[][].class
) );
+        assertEquals( "java.lang.String[][][]", ProxyUtils.getJavaClassName( String[][][].class
) );
+        assertEquals( "int", ProxyUtils.getJavaClassName( Integer.TYPE ) );
+        assertEquals( "float", ProxyUtils.getJavaClassName( Float.TYPE ) );
+        assertEquals( "long", ProxyUtils.getJavaClassName( Long.TYPE ) );
+        assertEquals( "double", ProxyUtils.getJavaClassName( Double.TYPE ) );
+        assertEquals( "short", ProxyUtils.getJavaClassName( Short.TYPE ) );
+        assertEquals( "byte", ProxyUtils.getJavaClassName( Byte.TYPE ) );
+        assertEquals( "char", ProxyUtils.getJavaClassName( Character.TYPE ) );
+        assertEquals( "boolean", ProxyUtils.getJavaClassName( Boolean.TYPE ) );
+    }
 }



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


Mime
View raw message