bloritsch 2002/10/03 08:05:54
Modified: util/src/java/org/apache/excalibur/util Delegate.java
util/src/test/org/apache/excalibur/util/test
DelegateTestCase.java
Log:
make delegate work a bit more nicely with static methods--i.e. no instance needed
Revision Changes Path
1.5 +4 -19
jakarta-avalon-excalibur/util/src/java/org/apache/excalibur/util/Delegate.java
Index: Delegate.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/util/src/java/org/apache/excalibur/util/Delegate.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Delegate.java 3 Oct 2002 14:54:32 -0000 1.4
+++ Delegate.java 3 Oct 2002 15:05:54 -0000 1.5
@@ -87,7 +87,7 @@
}
Class[] signature = interfaceMethods[0].getParameterTypes();
- InvocationHandler handler = new DelegateHandler( instance, methodName,
signature );
+ InvocationHandler handler = new DelegateHandler( instance,
instance.getClass(), methodName, signature );
return Proxy.newProxyInstance( loader, publicInterface, handler );
}
@@ -116,7 +116,7 @@
}
Class[] signature = interfaceMethods[0].getParameterTypes();
- InvocationHandler handler = new DelegateHandler( klass, methodName,
signature );
+ InvocationHandler handler = new DelegateHandler( null, klass, methodName,
signature );
return Proxy.newProxyInstance( loader, publicInterface, handler );
}
@@ -136,30 +136,15 @@
* we have a method call on the delegate.
*
* @param instance The object instance that has the method
+ * @param klass The class of the object containing the method
* @param methodName The method name that we forward messages to.
* @param signature The method signature used to ensure we have
* a good delegate.
*/
- public DelegateHandler ( Object instance, String methodName, Class[]
signature )
+ public DelegateHandler ( Object instance, Class klass, String methodName,
Class[] signature )
{
m_instance = instance;
- this( m_instance.getClass() );
- }
-
- /**
- * Create a new InvocationHandler for the delegate we manufactured.
- * We examine the instance class passed in for the method with the
- * requested name. When we find it, we save and use it every time
- * we have a method call on the delegate.
- *
- * @param klass The class of the object containing the method
- * @param methodName The method name that we forward messages to.
- * @param signature The method signature used to ensure we have
- * a good delegate.
- */
- public DelegateHandler ( Class klass, String methodName, Class[] signature
)
- {
Method[] methods = klass.getDeclaredMethods();
Method delegate = null;
1.5 +2 -2
jakarta-avalon-excalibur/util/src/test/org/apache/excalibur/util/test/DelegateTestCase.java
Index: DelegateTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/util/src/test/org/apache/excalibur/util/test/DelegateTestCase.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DelegateTestCase.java 3 Oct 2002 14:50:08 -0000 1.4
+++ DelegateTestCase.java 3 Oct 2002 15:05:54 -0000 1.5
@@ -100,7 +100,7 @@
public void testStaticDelegate()
{
- EchoDelegate delegate = (EchoDelegate) Delegate.newDelegate( this,
"staticEcho", EchoDelegate.class );
+ EchoDelegate delegate = (EchoDelegate) Delegate.newStaticDelegate(
getClass(), "staticEcho", EchoDelegate.class );
assertTrue( delegate.echo( MESSAGE ).startsWith( "static: " ) );
}
@@ -116,6 +116,6 @@
{
checkDelegate( (EchoDelegate) Delegate.newDelegate( this, "echo",
EchoDelegate.class ) );
checkDelegate( (EchoDelegate) Delegate.newDelegate( this, "otherEcho",
EchoDelegate.class ) );
- checkDelegate( (EchoDelegate) Delegate.newDelegate( this, "staticEcho",
EchoDelegate.class ) );
+ checkDelegate( (EchoDelegate) Delegate.newStaticDelegate( getClass(),
"staticEcho", EchoDelegate.class ) );
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>