hammant 2003/02/01 07:29:57 Modified: altrmi/src/java/org/apache/excalibur/altrmi/client ProxyHelper.java altrmi/src/java/org/apache/excalibur/altrmi/client/impl AbstractFactory.java DefaultProxyHelper.java altrmi/src/java/org/apache/excalibur/altrmi/generator ProxyGeneratorImpl.java altrmi/src/java/org/apache/excalibur/altrmi/server/impl DefaultMethodInvocationHandler.java altrmi/src/java/org/apache/excalibur/altrmi/server/impl/adapters PublicationAdapter.java altrmi/src/test/org/apache/excalibur/altrmi/test AbstractHelloTestCase.java TestInterface2Impl.java Log: .equals() supported on facades. Revision Changes Path 1.8 +5 -2 jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/ProxyHelper.java Index: ProxyHelper.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/ProxyHelper.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- ProxyHelper.java 26 Nov 2002 06:09:55 -0000 1.7 +++ ProxyHelper.java 1 Feb 2003 15:29:56 -0000 1.8 @@ -13,7 +13,7 @@ * Interface ProxyHelper * * - * @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> + * @author Paul Hammant * @author Vinay Chandrasekharan <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> * @version $Revision$ */ @@ -97,4 +97,7 @@ * */ Long getReferenceID( Object factory ); + + boolean isEquals(Object o1, Object o2); + } 1.4 +5 -2 jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/AbstractFactory.java Index: AbstractFactory.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/AbstractFactory.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- AbstractFactory.java 1 Feb 2003 11:33:47 -0000 1.3 +++ AbstractFactory.java 1 Feb 2003 15:29:56 -0000 1.4 @@ -35,7 +35,7 @@ * Class AbstractFactory * * - * @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> + * @author Paul Hammant * @author Peter Royal <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> * @version $Revision$ */ @@ -48,6 +48,9 @@ protected final HashMap m_refObjs = new HashMap(); private transient String m_textToSign; protected Long m_session; + + + /** * Set the HostContext (defauts to optimize = true) 1.23 +23 -1 jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/DefaultProxyHelper.java Index: DefaultProxyHelper.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/DefaultProxyHelper.java,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- DefaultProxyHelper.java 1 Feb 2003 11:33:47 -0000 1.22 +++ DefaultProxyHelper.java 1 Feb 2003 15:29:56 -0000 1.23 @@ -415,6 +415,28 @@ } } + public boolean isEquals(Object o1, Object o2) + { + if (o2 == null) return false; + if (o1 == o2) return true; + if (o1.getClass() != o2.getClass()) return false; + try { + Object retVal = processObjectRequest("equals(java.lang.Object)", new Object[] {o2}, new Class[] {Object.class}); + return ((Boolean) retVal).booleanValue(); + } catch (Throwable t) { + if (t instanceof RuntimeException) { + throw (RuntimeException) t; + } else if (t instanceof Error) { + throw (Error) t; + } else { + t.printStackTrace(); + throw new org.apache.excalibur.altrmi.common.InvocationException("Should never get here: " +t.getMessage()); + } + } + + + } + protected void finalize() throws Throwable { 1.23 +15 -3 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.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- ProxyGeneratorImpl.java 1 Feb 2003 12:29:21 -0000 1.22 +++ ProxyGeneratorImpl.java 1 Feb 2003 15:29:56 -0000 1.23 @@ -24,7 +24,7 @@ * Class ProxyGeneratorImpl * * - * @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> + * @author Paul Hammant * @author Mike Miller of www.gac.com * @author <a href="mailto:[EMAIL PROTECTED]">Peter Royal</a> * @version $Revision$ @@ -182,6 +182,11 @@ Vector methodsDone) throws ProxyGenerationException { // TODO DefaultProxyHelper altrmiGetProxyHelper(); + + + generateEqualsMethod(classSource); + methodsDone.add("equals(java.lang.Object)"); + for( int x = 0; x < interfacesToExpose.length; x++ ) { PublicationDescriptionItem interfaceToExpose = interfacesToExpose[ x ]; @@ -219,7 +224,7 @@ System.out.println( "ProxyGen: Processing method: " + methodSignature ); } - if( !methodsDone.contains( methodSignature ) ) + if( !methodsDone.contains( methodSignature )) { makeSourceInterfacesMethodsNotDone( classSource, @@ -235,6 +240,13 @@ } } } + } + + private void generateEqualsMethod(PrintWriter classSource) + { + classSource.println( " public boolean equals(Object o) {" ); + classSource.println( " return m_proxyHelper.isEquals(this,o);" ); + classSource.println( " }" ); } private void makeSourceInterfacesMethodsNotDone(PrintWriter classSource, Vector methodsDone, 1.14 +6 -7 jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/server/impl/DefaultMethodInvocationHandler.java Index: DefaultMethodInvocationHandler.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/server/impl/DefaultMethodInvocationHandler.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- DefaultMethodInvocationHandler.java 1 Feb 2003 11:33:49 -0000 1.13 +++ DefaultMethodInvocationHandler.java 1 Feb 2003 15:29:56 -0000 1.14 @@ -13,6 +13,8 @@ import java.lang.reflect.Method; import java.util.HashMap; import java.util.WeakHashMap; +import java.util.Iterator; + import org.apache.excalibur.altrmi.common.InvocationException; import org.apache.excalibur.altrmi.common.Reply; import org.apache.excalibur.altrmi.common.ExceptionReply; @@ -28,7 +30,7 @@ * Class DefaultMethodInvocationHandler * * - * @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> + * @author Paul Hammant * @author Vinay Chandrasekharan <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> * @version $Revision$ */ @@ -189,8 +191,9 @@ if( !m_methodMap.containsKey( methodSignature ) ) { + return new ExceptionReply( - new InvocationException( "Method not present in impl" ) ); + new InvocationException( "Method '"+ methodSignature +"' not present in impl" ) ); } Method method = (Method) m_methodMap.get( methodSignature ); @@ -263,10 +266,6 @@ DefaultMethodInvocationHandler methodInvocationHandler = (DefaultMethodInvocationHandler)m_altrmiPublisher .getMethodInvocationHandler( frh.getObjectName() ); - if (methodInvocationHandler == null) - { - System.out.println("--> not found " + frh.getObjectName()); - } WeakReference wr = (WeakReference)methodInvocationHandler.m_refBeans.get( frh.getReferenceID() ); 1.11 +25 -4 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.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- PublicationAdapter.java 20 Jan 2003 07:45:36 -0000 1.10 +++ PublicationAdapter.java 1 Feb 2003 15:29:56 -0000 1.11 @@ -20,7 +20,7 @@ * Class PublicationAdapter * * - * @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> + * @author Paul Hammant * @version $Revision$ */ public class PublicationAdapter implements Publisher @@ -113,11 +113,13 @@ { Method ts = Object.class.getMethod("toString", new Class[0]); Method hc = Object.class.getMethod("hashCode", new Class[0]); + Method eq = Object.class.getMethod("equals", new Class[]{Object.class}); Method[] interfaceMethods = clazz.getMethods(); - methods = new Method[interfaceMethods.length + 2]; + methods = new Method[interfaceMethods.length + 3]; System.arraycopy(interfaceMethods, 0, methods, 0, interfaceMethods.length); methods[interfaceMethods.length] = ts; methods[interfaceMethods.length + 1] = hc; + methods[interfaceMethods.length + 2] = eq; } catch (NoSuchMethodException e) { @@ -142,12 +144,31 @@ // add method maps for all the additional facades. for (int x = 0; x < additionalFacades.length; x++) { - Method methods[] = additionalFacades[x].getFacadeClass().getMethods(); + Class facadeClass = additionalFacades[x].getFacadeClass(); String encodedClassName = MethodNameHelper.encodeClassName(additionalFacades[x].getFacadeClass().getName()); HashMap methodMap = new HashMap(); MethodInvocationHandler methodInvocationHandler = new DefaultMethodInvocationHandler(this, asName + "_" + encodedClassName, methodMap, publicationDescription); + + Method methods[] = null; + try + { + Method ts = Object.class.getMethod("toString", new Class[0]); + Method hc = Object.class.getMethod("hashCode", new Class[0]); + Method eq = Object.class.getMethod("equals", new Class[]{Object.class}); + Method[] interfaceMethods = facadeClass.getMethods(); + methods = new Method[interfaceMethods.length + 3]; + System.arraycopy(interfaceMethods, 0, methods, 0, interfaceMethods.length); + methods[interfaceMethods.length] = ts; + methods[interfaceMethods.length + 1] = hc; + methods[interfaceMethods.length + 2] = eq; + } + catch (NoSuchMethodException e) + { + // never! + } + for (int y = 0; y < methods.length; y++) { 1.10 +16 -1 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.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- AbstractHelloTestCase.java 20 Jan 2003 07:45:36 -0000 1.9 +++ AbstractHelloTestCase.java 1 Feb 2003 15:29:56 -0000 1.10 @@ -145,7 +145,7 @@ TestInterface2 def2 = testClient.findTestInterface2ByName( "def" ); assertNotNull(def2); - assertEquals(def, def2); + assertTrue(def == def2); TestInterface2[] ti2s = testClient.getTestInterface2s(); @@ -212,5 +212,20 @@ assertEquals("YeeeeHaaaa", retVal); } + + public void testEquals() { + assertTrue(!testClient.equals(null)); + assertTrue(!testClient.equals("ha!")); + + TestInterface2 one = testClient.makeTestInterface2("equals-test-one"); + TestInterface2 two = testClient.makeTestInterface2("equals-test-two"); + + // These seem to contradict at first glance, but it is what we want. + assertFalse(one == two); + assertTrue(one.equals(two)); + + + } + } 1.4 +18 -2 jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test/TestInterface2Impl.java Index: TestInterface2Impl.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test/TestInterface2Impl.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- TestInterface2Impl.java 26 Aug 2002 10:44:08 -0000 1.3 +++ TestInterface2Impl.java 1 Feb 2003 15:29:57 -0000 1.4 @@ -11,7 +11,7 @@ * Class TestInterface2Impl * * - * @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> + * @author Paul Hammant * @version * $Revision$ */ public class TestInterface2Impl implements TestInterface2 @@ -55,4 +55,20 @@ { return mName; } + + public boolean equals(Object obj) + { + + // This is a bit unusual, but it is for the AbstractHelloTestCase testEquals method + + TestInterface2 other = (TestInterface2) obj; + + if (mName.equals("equals-test-one") && other.getName().equals("equals-test-two")) { + return true; + } + + return false; + + } + }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]