You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by ha...@apache.org on 2003/01/20 08:45:36 UTC
cvs commit: jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test/socket CallbackEnabledCustomStreamTestCase.java
hammant 2003/01/19 23:45:36
Modified: altrmi/src/java/org/apache/excalibur/altrmi/generator
ProxyGeneratorImpl.java
altrmi/src/java/org/apache/excalibur/altrmi/generator/ant
ProxyGenerationTask.java
altrmi/src/java/org/apache/excalibur/altrmi/server
PublicationDescriptionItem.java
altrmi/src/java/org/apache/excalibur/altrmi/server/impl/adapters
PublicationAdapter.java
altrmi/src/test/org/apache/excalibur/altrmi/test
AbstractHelloTestCase.java TestInterfaceImpl.java
altrmi/src/test/org/apache/excalibur/altrmi/test/socket
CallbackEnabledCustomStreamTestCase.java
Log:
toString() and hashCode() supported automatically.
Revision Changes Path
1.20 +18 -2 jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/generator/ProxyGeneratorImpl.java
Index: ProxyGeneratorImpl.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/generator/ProxyGeneratorImpl.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- ProxyGeneratorImpl.java 6 Jan 2003 23:42:11 -0000 1.19
+++ ProxyGeneratorImpl.java 20 Jan 2003 07:45:36 -0000 1.20
@@ -19,6 +19,7 @@
import org.apache.excalibur.altrmi.javacompiler.JavaCompiler;
import org.apache.excalibur.altrmi.server.PublicationDescriptionItem;
+
/**
* Class ProxyGeneratorImpl
*
@@ -195,7 +196,22 @@
System.out.println( "ProxyGen: Processing interface: " + clazz.getName() );
}
- Method[] methods = clazz.getMethods();
+ Method[] methods = null;
+
+ try
+ {
+ Method ts = Object.class.getMethod("toString", new Class[0]);
+ Method hc = Object.class.getMethod("hashCode", new Class[0]);
+ Method[] interfaceMethods = clazz.getMethods();
+ methods = new Method[interfaceMethods.length +2];
+ System.arraycopy(interfaceMethods,0,methods, 0,interfaceMethods.length);
+ methods[interfaceMethods.length] = ts;
+ methods[interfaceMethods.length+1] = hc;
+ }
+ catch (NoSuchMethodException e)
+ {
+ // never!
+ }
for( int y = 0; y < methods.length; y++ )
{
1.2 +1 -2 jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/generator/ant/ProxyGenerationTask.java
Index: ProxyGenerationTask.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/generator/ant/ProxyGenerationTask.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ProxyGenerationTask.java 9 Jan 2003 22:55:29 -0000 1.1
+++ ProxyGenerationTask.java 20 Jan 2003 07:45:36 -0000 1.2
@@ -260,7 +260,6 @@
for( int i = 0; i < m_interfacesToExpose.length; i++ )
{
String cn = m_interfacesToExpose[ i ];
-
interfacesToExpose[ i ] = new PublicationDescriptionItem(classLoader.loadClass( cn ));
}
1.10 +8 -1 jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/server/PublicationDescriptionItem.java
Index: PublicationDescriptionItem.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/server/PublicationDescriptionItem.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- PublicationDescriptionItem.java 4 Jan 2003 21:31:46 -0000 1.9
+++ PublicationDescriptionItem.java 20 Jan 2003 07:45:36 -0000 1.10
@@ -59,6 +59,13 @@
// attribute jars are missing.
// This allowed for when there is no Async functionality.
}
+ catch (RuntimeException re)
+ {
+ if (!re.getClass().getName().equals("org.apache.commons.attributes.AttributesException"))
+ {
+ throw re;
+ }
+ }
}
public PublicationDescriptionItem(Class facadeClass,
1.10 +65 -49 jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/server/impl/adapters/PublicationAdapter.java
Index: PublicationAdapter.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/server/impl/adapters/PublicationAdapter.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- PublicationAdapter.java 5 Jan 2003 23:24:45 -0000 1.9
+++ PublicationAdapter.java 20 Jan 2003 07:45:36 -0000 1.10
@@ -60,11 +60,11 @@
* @throws PublicationException if a problem during publication.
*
*/
- public void publish( Object impl, String asName, Class interfaceToExpose )
- throws PublicationException
+ public void publish(Object impl, String asName, Class interfaceToExpose)
+ throws PublicationException
{
- publish( impl, asName,
- new PublicationDescription( interfaceToExpose ) );
+ publish(impl, asName,
+ new PublicationDescription(interfaceToExpose));
}
/**
@@ -77,74 +77,90 @@
* @throws PublicationException if a problem during publication.
*
*/
- public void publish( Object impl, String asName,
- PublicationDescription publicationDescription ) throws PublicationException
+ public void publish(Object impl, String asName,
+ PublicationDescription publicationDescription) throws PublicationException
{
PublicationDescriptionItem[] interfacesToExpose = publicationDescription.getInterfacesToExpose();
PublicationDescriptionItem[] additionalFacades = publicationDescription.getAdditionalFacades();
- if( m_publishedObjects.containsKey( asName + "_Main" ) )
+ if (m_publishedObjects.containsKey(asName + "_Main"))
{
- throw new PublicationException( "Service '" + asName + "' already published" );
+ throw new PublicationException("Service '" + asName + "' already published");
}
- String[] interfaceNames = new String[ interfacesToExpose.length ];
+ String[] interfaceNames = new String[interfacesToExpose.length];
- for( int i = 0; i < interfacesToExpose.length; i++ )
+ for (int i = 0; i < interfacesToExpose.length; i++)
{
- interfaceNames[ i ] = interfacesToExpose[ i ].getFacadeClass().getName();
+ interfaceNames[i] = interfacesToExpose[i].getFacadeClass().getName();
}
// add method maps for main lookup-able service.
HashMap mainMethodMap = new HashMap();
DefaultMethodInvocationHandler mainMethodInvocationHandler =
- new DefaultMethodInvocationHandler( this, asName + "_Main",
- mainMethodMap, publicationDescription );
+ new DefaultMethodInvocationHandler(this, asName + "_Main",
+ mainMethodMap, publicationDescription);
- mainMethodInvocationHandler.addImplementationBean( new Long( 0 ), impl );
+ mainMethodInvocationHandler.addImplementationBean(new Long(0), impl);
- for( int x = 0; x < interfacesToExpose.length; x++ )
+ for (int x = 0; x < interfacesToExpose.length; x++)
{
- Method methods[] = interfacesToExpose[ x ].getFacadeClass().getMethods();
+ Class clazz = interfacesToExpose[x].getFacadeClass();
- for( int y = 0; y < methods.length; y++ )
+ Method methods[] = null;
+ try
{
- Method method = methods[ y ];
- String methodSignature = MethodNameHelper.getMethodSignature( method );
+ Method ts = Object.class.getMethod("toString", new Class[0]);
+ Method hc = Object.class.getMethod("hashCode", new Class[0]);
+ Method[] interfaceMethods = clazz.getMethods();
+ methods = new Method[interfaceMethods.length + 2];
+ System.arraycopy(interfaceMethods, 0, methods, 0, interfaceMethods.length);
+ methods[interfaceMethods.length] = ts;
+ methods[interfaceMethods.length + 1] = hc;
+ }
+ catch (NoSuchMethodException e)
+ {
+ // never!
+ }
+
+ for (int y = 0; y < methods.length; y++)
+ {
+ Method method = methods[y];
+ String methodSignature = MethodNameHelper.getMethodSignature(method);
- if( !mainMethodMap.containsKey( methodSignature.toString() ) )
+ if (!mainMethodMap.containsKey(methodSignature.toString()))
{
- mainMethodMap.put( methodSignature.toString(), methods[ y ] );
+ mainMethodMap.put(methodSignature.toString(), methods[y]);
}
}
}
// as the main service is lookup-able, it has a prexisting impl.
- m_publishedObjects.put( asName + "_Main", mainMethodInvocationHandler );
+ m_publishedObjects.put(asName + "_Main", mainMethodInvocationHandler);
// add method maps for all the additional facades.
- for( int x = 0; x < additionalFacades.length; x++ )
+ for (int x = 0; x < additionalFacades.length; x++)
{
- Method methods[] = additionalFacades[ x ].getFacadeClass().getMethods();
- String encodedClassName = MethodNameHelper.encodeClassName( additionalFacades[ x ].getFacadeClass().getName() );
+ Method methods[] = additionalFacades[x].getFacadeClass().getMethods();
+ String encodedClassName = MethodNameHelper.encodeClassName(additionalFacades[x].getFacadeClass().getName());
HashMap methodMap = new HashMap();
MethodInvocationHandler methodInvocationHandler =
- new DefaultMethodInvocationHandler( this, asName + "_" + encodedClassName,
- methodMap, publicationDescription );
+ new DefaultMethodInvocationHandler(this, asName + "_" + encodedClassName,
+ methodMap, publicationDescription);
- for( int y = 0; y < methods.length; y++ )
+ for (int y = 0; y < methods.length; y++)
{
- Method method = methods[ y ];
- String methodSignature = MethodNameHelper.getMethodSignature( method );
+ Method method = methods[y];
+ String methodSignature = MethodNameHelper.getMethodSignature(method);
- if( !methodMap.containsKey( methodSignature.toString() ) )
+ if (!methodMap.containsKey(methodSignature.toString()))
{
- methodMap.put( methodSignature.toString(), methods[ y ] );
+ methodMap.put(methodSignature.toString(), methods[y]);
}
}
- m_publishedObjects.put( asName + "_" + encodedClassName, methodInvocationHandler );
+ m_publishedObjects.put(asName + "_" + encodedClassName, methodInvocationHandler);
}
}
@@ -157,15 +173,15 @@
* @throws PublicationException if a problem during publication.
*
*/
- public void unPublish( Object impl, String publishedName ) throws PublicationException
+ public void unPublish(Object impl, String publishedName) throws PublicationException
{
- if( !m_publishedObjects.containsKey( publishedName + "_Main" ) )
+ if (!m_publishedObjects.containsKey(publishedName + "_Main"))
{
- throw new PublicationException( "Service '" + publishedName + "' not published" );
+ throw new PublicationException("Service '" + publishedName + "' not published");
}
- m_publishedObjects.remove( publishedName + "_Main" );
+ m_publishedObjects.remove(publishedName + "_Main");
}
/**
@@ -178,19 +194,19 @@
* @throws PublicationException if a problem during publication.
*
*/
- public void replacePublished( Object oldImpl, String publishedName, Object withImpl )
- throws PublicationException
+ public void replacePublished(Object oldImpl, String publishedName, Object withImpl)
+ throws PublicationException
{
- if( !m_publishedObjects.containsKey( publishedName + "_Main" ) )
+ if (!m_publishedObjects.containsKey(publishedName + "_Main"))
{
- throw new PublicationException( "Service '" + publishedName + "' not published" );
+ throw new PublicationException("Service '" + publishedName + "' not published");
}
MethodInvocationHandler asih =
- (MethodInvocationHandler)m_publishedObjects.get( publishedName + "_Main" );
+ (MethodInvocationHandler) m_publishedObjects.get(publishedName + "_Main");
- asih.replaceImplementationBean( oldImpl, withImpl );
+ asih.replaceImplementationBean(oldImpl, withImpl);
}
/**
@@ -203,11 +219,11 @@
* @return the method invoation handler
*
*/
- public MethodInvocationHandler getMethodInvocationHandler( MethodRequest methodRequest,
- String objectName )
+ public MethodInvocationHandler getMethodInvocationHandler(MethodRequest methodRequest,
+ String objectName)
{
return (MethodInvocationHandler) m_publishedObjects.get(
- methodRequest.getPublishedServiceName() + "_" + objectName );
+ methodRequest.getPublishedServiceName() + "_" + objectName);
}
/**
@@ -219,8 +235,8 @@
* @return the method invoation handler
*
*/
- public MethodInvocationHandler getMethodInvocationHandler( String publishedName )
+ public MethodInvocationHandler getMethodInvocationHandler(String publishedName)
{
- return (MethodInvocationHandler) m_publishedObjects.get( publishedName );
+ return (MethodInvocationHandler) m_publishedObjects.get(publishedName);
}
}
1.9 +13 -0 jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test/AbstractHelloTestCase.java
Index: AbstractHelloTestCase.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test/AbstractHelloTestCase.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- AbstractHelloTestCase.java 21 Dec 2002 23:18:14 -0000 1.8
+++ AbstractHelloTestCase.java 20 Jan 2003 07:45:36 -0000 1.9
@@ -200,4 +200,17 @@
}
+ public void testToString() {
+
+ // lookup worked ?
+ assertNotNull(testClient);
+
+ // Invoke a method over AltRMI.
+ String retVal = testClient.toString();
+
+ // test our returned result
+ assertEquals("YeeeeHaaaa", retVal);
+
+ }
+
}
1.8 +7 -1 jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test/TestInterfaceImpl.java
Index: TestInterfaceImpl.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test/TestInterfaceImpl.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- TestInterfaceImpl.java 26 Aug 2002 21:53:48 -0000 1.7
+++ TestInterfaceImpl.java 20 Jan 2003 07:45:36 -0000 1.8
@@ -237,4 +237,10 @@
testCallBackListener.serverCallingClient2(this);
}
}
+
+ public String toString()
+ {
+ return "YeeeeHaaaa";
+ }
+
}
1.7 +23 -0 jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test/socket/CallbackEnabledCustomStreamTestCase.java
Index: CallbackEnabledCustomStreamTestCase.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test/socket/CallbackEnabledCustomStreamTestCase.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- CallbackEnabledCustomStreamTestCase.java 9 Jan 2003 22:55:28 -0000 1.6
+++ CallbackEnabledCustomStreamTestCase.java 20 Jan 2003 07:45:36 -0000 1.7
@@ -15,9 +15,12 @@
import org.apache.excalibur.altrmi.test.TestInterface3;
import org.apache.excalibur.altrmi.test.TestInterface2;
import org.apache.excalibur.altrmi.test.AbstractHelloCallBackTestCase;
+import org.apache.excalibur.altrmi.test.TestCallBackListener;
import org.apache.excalibur.altrmi.server.impl.callback.socket.CallbackEnabledSocketCustomStreamServer;
import org.apache.excalibur.altrmi.server.PublicationDescription;
+import java.util.HashMap;
+
/**
* Test Custom Stream over sockets.
@@ -55,6 +58,26 @@
// threads, AltRMI being a client/server thing
Thread.yield();
}
+
+ public void dont_testCallBack() {
+
+ final HashMap results = new HashMap();
+
+ testClient.addCallBackListener(new TestCallBackListener() {
+ public void serverCallingClient(String message)
+ {
+ results.put("1", message);
+ }
+
+ public void serverCallingClient2(TestInterface testInterface)
+ {
+ results.put("2", testInterface.toString());
+ }
+
+ });
+
+ }
+
protected void tearDown() throws Exception
{
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>