hivemind-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jcar...@apache.org
Subject svn commit: r400320 - in /jakarta/hivemind/trunk: .settings/ framework/src/java/org/apache/hivemind/impl/ framework/src/java/org/apache/hivemind/service/ framework/src/java/org/apache/hivemind/service/impl/ framework/src/test/org/apache/hivemind/servic...
Date Sat, 06 May 2006 15:06:26 GMT
Author: jcarman
Date: Sat May  6 08:06:25 2006
New Revision: 400320

URL: http://svn.apache.org/viewcvs?rev=400320&view=rev
Log:
HiveMind LoggingInterceptor incompatible with proxies generated by outside means (CGLIB or
Javassist)
PR: HIVEMIND-176

Added:
    jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/CglibBeanInterfaceFactory.java
  (with props)
    jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/JavassistBeanInterfaceFactory.java
  (with props)
    jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/JdkBeanInterfaceFactory.java
  (with props)
    jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/generated.xml
  (with props)
Modified:
    jakarta/hivemind/trunk/.settings/org.eclipse.jdt.core.prefs
    jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/impl/ProxyUtils.java
    jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/service/ClassFab.java
    jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/service/ClassFabUtils.java
    jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/AbstractFab.java
    jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/ClassFabImpl.java
    jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/CtClassSource.java
    jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/LoggingInterceptorFactory.java
    jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/TestClassFab.java
    jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/TestClassFabUtils.java
    jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/TestLoggingInterceptorFactory.java
    jakarta/hivemind/trunk/library/src/java/org/apache/hivemind/lib/impl/ServicePropertyFactory.java

Modified: jakarta/hivemind/trunk/.settings/org.eclipse.jdt.core.prefs
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/trunk/.settings/org.eclipse.jdt.core.prefs?rev=400320&r1=400319&r2=400320&view=diff
==============================================================================
--- jakarta/hivemind/trunk/.settings/org.eclipse.jdt.core.prefs (original)
+++ jakarta/hivemind/trunk/.settings/org.eclipse.jdt.core.prefs Sat May  6 08:06:25 2006
@@ -1,4 +1,4 @@
-#Thu Jun 09 11:03:45 EDT 2005
+#Sat May 06 10:53:35 EDT 2006
 eclipse.preferences.version=1
 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled
 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.1

Modified: jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/impl/ProxyUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/impl/ProxyUtils.java?rev=400320&r1=400319&r2=400320&view=diff
==============================================================================
--- jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/impl/ProxyUtils.java (original)
+++ jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/impl/ProxyUtils.java Sat
May  6 08:06:25 2006
@@ -127,7 +127,7 @@
     {
         classFab.addField("_shutdown", boolean.class);
 
-        Class delegateClass = ClassFabUtils.getInstanceClass(delegate, servicePoint
+        Class delegateClass = ClassFabUtils.getInstanceClass(classFab, delegate, servicePoint
                 .getServiceInterface());
 
         classFab.addField("_delegate", delegateClass);

Modified: jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/service/ClassFab.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/service/ClassFab.java?rev=400320&r1=400319&r2=400320&view=diff
==============================================================================
--- jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/service/ClassFab.java (original)
+++ jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/service/ClassFab.java Sat
May  6 08:06:25 2006
@@ -57,6 +57,8 @@
 
     public void addField(String name, Class type);
 
+    public boolean canConvert(Class inputClass);
+    
     /**
      * Convenience method for checking whether the fabricated class already contains
      * a method.

Modified: jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/service/ClassFabUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/service/ClassFabUtils.java?rev=400320&r1=400319&r2=400320&view=diff
==============================================================================
--- jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/service/ClassFabUtils.java
(original)
+++ jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/service/ClassFabUtils.java
Sat May  6 08:06:25 2006
@@ -16,7 +16,6 @@
 
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
-import java.lang.reflect.Proxy;
 
 /**
  * Static class containing utility methods.
@@ -115,11 +114,11 @@
      * @param interfaceClass
      *            the interface class to return if the instance is a JDK proxy.
      */
-    public static Class getInstanceClass(Object instance, Class interfaceClass)
+    public static Class getInstanceClass(ClassFab classFab, Object instance, Class interfaceClass)
     {
         Class instanceClass = instance.getClass();
 
-        if (Proxy.isProxyClass(instanceClass))
+        if (!classFab.canConvert(instanceClass))
             return interfaceClass;
 
         return instanceClass;

Modified: jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/AbstractFab.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/AbstractFab.java?rev=400320&r1=400319&r2=400320&view=diff
==============================================================================
--- jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/AbstractFab.java
(original)
+++ jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/AbstractFab.java
Sat May  6 08:06:25 2006
@@ -71,6 +71,11 @@
         return result;
     }
 
+    public boolean canConvert(Class inputClass)
+    {
+    	return _source.canConvert(inputClass);
+    }
+    
     /**
      * @since 1.1
      */

Modified: jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/ClassFabImpl.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/ClassFabImpl.java?rev=400320&r1=400319&r2=400320&view=diff
==============================================================================
--- jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/ClassFabImpl.java
(original)
+++ jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/ClassFabImpl.java
Sat May  6 08:06:25 2006
@@ -244,7 +244,7 @@
     {
         return getCtClass().getName();
     }
-
+    
     public void addField(String name, Class type)
     {
         CtClass ctType = convertClass(type);

Modified: jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/CtClassSource.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/CtClassSource.java?rev=400320&r1=400319&r2=400320&view=diff
==============================================================================
--- jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/CtClassSource.java
(original)
+++ jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/CtClassSource.java
Sat May  6 08:06:25 2006
@@ -50,14 +50,24 @@
         _pool = pool;
     }
 
+    public boolean canConvert(Class searchClass) 
+    {
+    	ensureClassLoaderAvailable(searchClass);
+        String name = ClassFabUtils.getJavaClassName(searchClass);
+        try
+        {
+        	_pool.get(name);
+        	return true;
+        }
+        catch (NotFoundException ex)
+        {
+            return false;
+        }
+    }
+    
     public CtClass getCtClass(Class searchClass)
     {
-        ClassLoader loader = searchClass.getClassLoader();
-
-        // Add the class loader for the searchClass to the class pool and
-        // delegating class loader if needed.
-
-        _pool.appendClassLoader(loader);
+        ensureClassLoaderAvailable(searchClass);
 
         String name = ClassFabUtils.getJavaClassName(searchClass);
 
@@ -70,6 +80,18 @@
             throw new ApplicationRuntimeException(ServiceMessages.unableToLookupClass(name,
ex), ex);
         }
     }
+
+	/**
+	 * @param searchClass
+	 */
+	private void ensureClassLoaderAvailable(Class searchClass) {
+		ClassLoader loader = searchClass.getClassLoader();
+
+        // Add the class loader for the searchClass to the class pool and
+        // delegating class loader if needed.
+
+        _pool.appendClassLoader(loader);
+	}
 
     public CtClass newClass(String name, Class superClass)
     {

Modified: jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/LoggingInterceptorFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/LoggingInterceptorFactory.java?rev=400320&r1=400319&r2=400320&view=diff
==============================================================================
--- jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/LoggingInterceptorFactory.java
(original)
+++ jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/LoggingInterceptorFactory.java
Sat May  6 08:06:25 2006
@@ -218,8 +218,8 @@
 
     private void createInfrastructure(InterceptorStack stack, ClassFab classFab)
     {
-        Class topClass = ClassFabUtils.getInstanceClass(stack.peek(), stack.getServiceInterface());
-
+        Class topClass = ClassFabUtils.getInstanceClass(classFab, stack.peek(), stack.getServiceInterface());
+        
         classFab.addField("_log", Log.class);
 
         // This is very important: since we know the instance of the top object (the next

Added: jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/CglibBeanInterfaceFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/CglibBeanInterfaceFactory.java?rev=400320&view=auto
==============================================================================
--- jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/CglibBeanInterfaceFactory.java
(added)
+++ jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/CglibBeanInterfaceFactory.java
Sat May  6 08:06:25 2006
@@ -0,0 +1,75 @@
+// Copyright 2006 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 org.apache.hivemind.service.impl;
+
+import java.lang.reflect.Method;
+
+import net.sf.cglib.proxy.Callback;
+import net.sf.cglib.proxy.CallbackFilter;
+import net.sf.cglib.proxy.Enhancer;
+import net.sf.cglib.proxy.FixedValue;
+import net.sf.cglib.proxy.NoOp;
+
+import org.apache.hivemind.ServiceImplementationFactory;
+import org.apache.hivemind.ServiceImplementationFactoryParameters;
+
+/**
+ * 
+ * @author James Carman
+ */
+public class CglibBeanInterfaceFactory implements ServiceImplementationFactory
+{
+
+	public Object createCoreServiceImplementation(ServiceImplementationFactoryParameters factoryParameters)
{
+		return createCglibBean();
+	}
+
+
+	/**
+	 * @return
+	 */
+	public static BeanInterface createCglibBean() {
+		Enhancer enhancer = new Enhancer();
+		enhancer.setClassLoader( BeanInterface.class.getClassLoader() );
+		enhancer.setInterfaces( new Class[] { BeanInterface.class } );
+		enhancer.setCallbackFilter( new InterfaceMethodFilter() );
+		enhancer.setCallbacks( new Callback[] { new FixedValue()
+				{
+					public Object loadObject() throws Exception {
+
+						return "Hello, World!";
+					}
+			
+				}, NoOp.INSTANCE } );
+		
+		return (BeanInterface)enhancer.create();
+	}
+	
+	
+	private static class InterfaceMethodFilter implements CallbackFilter
+	{
+
+		public int accept(Method method) 
+		{
+			if( method.getName().equals( "interfaceMethod" ) )
+			{
+				return 0;
+			}
+			return 1;
+		}
+		
+	}
+
+}

Propchange: jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/CglibBeanInterfaceFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/CglibBeanInterfaceFactory.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/JavassistBeanInterfaceFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/JavassistBeanInterfaceFactory.java?rev=400320&view=auto
==============================================================================
--- jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/JavassistBeanInterfaceFactory.java
(added)
+++ jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/JavassistBeanInterfaceFactory.java
Sat May  6 08:06:25 2006
@@ -0,0 +1,63 @@
+// Copyright 2006 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 org.apache.hivemind.service.impl;
+
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.CtMethod;
+import javassist.LoaderClassPath;
+
+import org.apache.hivemind.ApplicationRuntimeException;
+import org.apache.hivemind.ServiceImplementationFactory;
+import org.apache.hivemind.ServiceImplementationFactoryParameters;
+import org.apache.hivemind.service.ClassFabUtils;
+
+/**
+ * @author James Carman
+ */
+public class JavassistBeanInterfaceFactory implements
+		ServiceImplementationFactory {
+
+	public Object createCoreServiceImplementation(
+			ServiceImplementationFactoryParameters factoryParameters) {
+		return createJavassistBean();
+	}
+
+	/**
+	 * @return
+	 */
+	public static BeanInterface createJavassistBean() {
+		try {
+			ClassPool classPool = new ClassPool();
+			classPool.appendClassPath(new LoaderClassPath(BeanInterface.class
+					.getClassLoader()));
+			CtClass theClass = classPool
+					.makeClass(ClassFabUtils.generateClassName( BeanInterface.class ) );
+
+			theClass.addInterface(classPool.get(BeanInterface.class.getName()));
+			CtMethod theMethod = new CtMethod(
+					classPool.get("java.lang.String"), "interfaceMethod",
+					new CtClass[0], theClass);
+			theMethod.setBody("return \"Hello, World!\";");
+			theClass.addMethod(theMethod);
+			Class clazz = theClass.toClass();
+			return ( BeanInterface )clazz.newInstance();
+		} catch (Exception e) {
+			throw new ApplicationRuntimeException("Cannot construct instance.",
+					e);
+		}
+	}
+
+}

Propchange: jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/JavassistBeanInterfaceFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/JavassistBeanInterfaceFactory.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/JdkBeanInterfaceFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/JdkBeanInterfaceFactory.java?rev=400320&view=auto
==============================================================================
--- jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/JdkBeanInterfaceFactory.java
(added)
+++ jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/JdkBeanInterfaceFactory.java
Sat May  6 08:06:25 2006
@@ -0,0 +1,48 @@
+// Copyright 2006 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 org.apache.hivemind.service.impl;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+import org.apache.hivemind.ServiceImplementationFactory;
+import org.apache.hivemind.ServiceImplementationFactoryParameters;
+
+/**
+ * 
+ * @author James Carman
+ *
+ */
+public class JdkBeanInterfaceFactory implements ServiceImplementationFactory {
+
+	public Object createCoreServiceImplementation(ServiceImplementationFactoryParameters factoryParameters)
{
+		return createJdkBean();
+	}
+
+	/**
+	 * @return
+	 */
+	public static BeanInterface createJdkBean() {
+		return ( BeanInterface )Proxy.newProxyInstance( BeanInterface.class.getClassLoader(), new
Class[] { BeanInterface.class }, new InvocationHandler()
+				{
+					public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+						return "Hello, World!";
+					}	
+				} );
+	}
+	
+
+}

Propchange: jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/JdkBeanInterfaceFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/JdkBeanInterfaceFactory.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/TestClassFab.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/TestClassFab.java?rev=400320&r1=400319&r2=400320&view=diff
==============================================================================
--- jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/TestClassFab.java
(original)
+++ jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/TestClassFab.java
Sat May  6 08:06:25 2006
@@ -441,10 +441,21 @@
 
     }
 
+    public void testCanConvert()
+    {
+    	final ClassFab cf = newClassFab("BamBam", Object.class);
+    	assertTrue( cf.canConvert( String.class ) );
+    	assertFalse(cf.canConvert(CglibBeanInterfaceFactory.createCglibBean().getClass()));
+    	assertFalse(cf.canConvert(JavassistBeanInterfaceFactory.createJavassistBean().getClass()));
+    	assertFalse(cf.canConvert(JdkBeanInterfaceFactory.createJdkBean().getClass()));
+    }
+    
     /** @since 1.1 */
     private void contains(String actual, String expected)
     {
         if (actual.indexOf(expected) < 0)
             throw new AssertionFailedError("Missing substring: " + expected);
     }
+    
+    
 }

Modified: jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/TestClassFabUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/TestClassFabUtils.java?rev=400320&r1=400319&r2=400320&view=diff
==============================================================================
--- jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/TestClassFabUtils.java
(original)
+++ jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/TestClassFabUtils.java
Sat May  6 08:06:25 2006
@@ -27,63 +27,69 @@
  * Tests for {@link org.apache.hivemind.service.ClassFabUtils}
  * 
  * @author Howard Lewis Ship
+ * @author James Carman
  */
-public class TestClassFabUtils extends HiveMindTestCase
-{
-    public void testGetInstanceClassName()
-    {
-        Runnable subject = new Runnable()
-        {
-            public void run()
-            {
-            }
-        };
-
-        assertSame(subject.getClass(), ClassFabUtils.getInstanceClass(subject, Runnable.class));
-
-        Runnable mock = (Runnable) newMock(Runnable.class);
-
-        assertSame(Runnable.class, ClassFabUtils.getInstanceClass(mock, Runnable.class));
-    }
-
-    /** @since 1.1 */
-    public void testAddNoOpMethod()
-    {
-        tryAddNoOpMethod(void.class, "{  }");
-        tryAddNoOpMethod(String.class, "{ return null; }");
-        tryAddNoOpMethod(boolean.class, "{ return false; }");
-        tryAddNoOpMethod(char.class, "{ return 0; }");
-        tryAddNoOpMethod(short.class, "{ return 0; }");
-        tryAddNoOpMethod(int.class, "{ return 0; }");
-        tryAddNoOpMethod(long.class, "{ return 0L; }");
-        tryAddNoOpMethod(double.class, "{ return 0.0d; }");
-        tryAddNoOpMethod(float.class, "{ return 0.0f; }");
-    }
-
-    /** @since 1.1 */
-    private void tryAddNoOpMethod(Class returnClass, String expectedBody)
-    {
-        MethodSignature sig = new MethodSignature(returnClass, "run", null, null);
-
-        MockControl control = newControl(ClassFab.class);
-        ClassFab cf = (ClassFab) control.getMock();
-        MethodFab mf = (MethodFab) newMock(MethodFab.class);
-
-        cf.addMethod(Modifier.PUBLIC, sig, expectedBody);
-        control.setReturnValue(mf);
-
-        replayControls();
-
-        ClassFabUtils.addNoOpMethod(cf, sig);
-
-        verifyControls();
-    }
-
-    /** @since 1.1 */
-    public void testGenerateClassName() throws Exception
-    {
-        String name = ClassFabUtils.generateClassName(Runnable.class);
+public class TestClassFabUtils extends HiveMindTestCase {
+	
 
-        assertRegexp("\\$Runnable_([0-9|a-f])+", name);
-    }
+	public void testGetInstanceClass() {
+		final HiveMindClassPool pool = new HiveMindClassPool();
+		final CtClassSource classSource = new CtClassSource(pool);
+		final ClassFab classFab = new ClassFabImpl(classSource, pool
+				.makeClass("Dummy"));
+		assertSame(ClassFabUtils.getInstanceClass(classFab,
+				new BeanInterfaceImpl(), BeanInterface.class),
+				BeanInterfaceImpl.class);
+		assertSame( ClassFabUtils.getInstanceClass(classFab,CglibBeanInterfaceFactory.createCglibBean(),
BeanInterface.class ), BeanInterface.class );
+		assertSame( ClassFabUtils.getInstanceClass(classFab,JavassistBeanInterfaceFactory.createJavassistBean(),
BeanInterface.class ), BeanInterface.class );
+		assertSame( ClassFabUtils.getInstanceClass(classFab,JdkBeanInterfaceFactory.createJdkBean(),
BeanInterface.class ), BeanInterface.class );
+		
+	}
+
+	public static class BeanInterfaceImpl implements BeanInterface {
+
+		public String interfaceMethod() {
+			return "Hello, World!";
+		}
+
+	}
+
+	/** @since 1.1 */
+	public void testAddNoOpMethod() {
+		tryAddNoOpMethod(void.class, "{  }");
+		tryAddNoOpMethod(String.class, "{ return null; }");
+		tryAddNoOpMethod(boolean.class, "{ return false; }");
+		tryAddNoOpMethod(char.class, "{ return 0; }");
+		tryAddNoOpMethod(short.class, "{ return 0; }");
+		tryAddNoOpMethod(int.class, "{ return 0; }");
+		tryAddNoOpMethod(long.class, "{ return 0L; }");
+		tryAddNoOpMethod(double.class, "{ return 0.0d; }");
+		tryAddNoOpMethod(float.class, "{ return 0.0f; }");
+	}
+
+	/** @since 1.1 */
+	private void tryAddNoOpMethod(Class returnClass, String expectedBody) {
+		MethodSignature sig = new MethodSignature(returnClass, "run", null,
+				null);
+
+		MockControl control = newControl(ClassFab.class);
+		ClassFab cf = (ClassFab) control.getMock();
+		MethodFab mf = (MethodFab) newMock(MethodFab.class);
+
+		cf.addMethod(Modifier.PUBLIC, sig, expectedBody);
+		control.setReturnValue(mf);
+
+		replayControls();
+
+		ClassFabUtils.addNoOpMethod(cf, sig);
+
+		verifyControls();
+	}
+
+	/** @since 1.1 */
+	public void testGenerateClassName() throws Exception {
+		String name = ClassFabUtils.generateClassName(Runnable.class);
+
+		assertRegexp("\\$Runnable_([0-9|a-f])+", name);
+	}
 }

Modified: jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/TestLoggingInterceptorFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/TestLoggingInterceptorFactory.java?rev=400320&r1=400319&r2=400320&view=diff
==============================================================================
--- jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/TestLoggingInterceptorFactory.java
(original)
+++ jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/TestLoggingInterceptorFactory.java
Sat May  6 08:06:25 2006
@@ -17,6 +17,7 @@
 import java.util.Collections;
 
 import org.apache.commons.logging.Log;
+import org.apache.hivemind.Registry;
 import org.apache.hivemind.impl.InterceptorStackImpl;
 import org.apache.hivemind.internal.Module;
 import org.apache.hivemind.internal.ServicePoint;
@@ -28,6 +29,7 @@
  * Tests for {@link org.apache.hivemind.service.impl.LoggingInterceptorFactory}.
  * 
  * @author Howard Lewis Ship
+ * @author James Carman
  */
 public class TestLoggingInterceptorFactory extends HiveMindTestCase
 {
@@ -85,4 +87,23 @@
 
         verifyControls();
     }
+    
+    public void testJavassistProxies() throws Exception {
+		final Registry reg = buildFrameworkRegistry("generated.xml" );
+		final BeanInterface bean = ( BeanInterface )reg.getService( "generated.JavassistBeanInterface",
BeanInterface.class );
+		bean.interfaceMethod();
+	}
+	
+	public void testCglibProxies() throws Exception {
+		final Registry reg = buildFrameworkRegistry("generated.xml" );
+		final BeanInterface bean = ( BeanInterface )reg.getService( "generated.CglibBeanInterface",
BeanInterface.class );
+		bean.interfaceMethod();
+	}
+	
+	public void testJdkProxies() throws Exception {
+		final Registry reg = buildFrameworkRegistry("generated.xml" );
+		final BeanInterface bean = ( BeanInterface )reg.getService( "generated.JdkBeanInterface",
BeanInterface.class );
+		bean.interfaceMethod();
+	}
+	
 }

Added: jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/generated.xml
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/generated.xml?rev=400320&view=auto
==============================================================================
--- jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/generated.xml
(added)
+++ jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/generated.xml
Sat May  6 08:06:25 2006
@@ -0,0 +1,53 @@
+<?xml version="1.0"?>
+<!-- 
+   Copyright 2006 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.
+-->
+
+<module id="generated" version="1.0.0">
+
+  <service-point id="JavassistFactory" interface="org.apache.hivemind.ServiceImplementationFactory"
parameters-occurs="none">
+    <invoke-factory>
+      <construct class="org.apache.hivemind.service.impl.JavassistBeanInterfaceFactory"
/>
+    </invoke-factory>
+  </service-point>
+
+  <service-point id="CglibFactory" interface="org.apache.hivemind.ServiceImplementationFactory"
parameters-occurs="none">
+    <invoke-factory>
+      <construct class="org.apache.hivemind.service.impl.CglibBeanInterfaceFactory" />
+    </invoke-factory>
+  </service-point>
+  
+  <service-point id="JdkFactory" interface="org.apache.hivemind.ServiceImplementationFactory"
parameters-occurs="none">
+    <invoke-factory>
+      <construct class="org.apache.hivemind.service.impl.JdkBeanInterfaceFactory" />
+    </invoke-factory>
+  </service-point>
+  
+  
+  <service-point id="JavassistBeanInterface" interface="org.apache.hivemind.service.impl.BeanInterface">
+    <invoke-factory service-id="JavassistFactory" />
+    <interceptor service-id="hivemind.LoggingInterceptor" />
+  </service-point>
+  
+  <service-point id="CglibBeanInterface" interface="org.apache.hivemind.service.impl.BeanInterface">
+    <invoke-factory service-id="CglibFactory" />
+    <interceptor service-id="hivemind.LoggingInterceptor" />
+  </service-point>
+  
+  <service-point id="JdkBeanInterface" interface="org.apache.hivemind.service.impl.BeanInterface">
+    <invoke-factory service-id="JdkFactory" />
+    <interceptor service-id="hivemind.LoggingInterceptor" />
+  </service-point>
+</module>

Propchange: jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/generated.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/generated.xml
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: jakarta/hivemind/trunk/library/src/java/org/apache/hivemind/lib/impl/ServicePropertyFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/trunk/library/src/java/org/apache/hivemind/lib/impl/ServicePropertyFactory.java?rev=400320&r1=400319&r2=400320&view=diff
==============================================================================
--- jakarta/hivemind/trunk/library/src/java/org/apache/hivemind/lib/impl/ServicePropertyFactory.java
(original)
+++ jakarta/hivemind/trunk/library/src/java/org/apache/hivemind/lib/impl/ServicePropertyFactory.java
Sat May  6 08:06:25 2006
@@ -99,7 +99,7 @@
     {
         cf.addInterface(serviceInterface);
 
-        Class targetServiceClass = ClassFabUtils.getInstanceClass(targetService, serviceInterface);
+        Class targetServiceClass = ClassFabUtils.getInstanceClass(cf, targetService, serviceInterface);
 
         cf.addField("_targetService", targetServiceClass);
 



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


Mime
View raw message