Hi,

after updating to the newest cvs checkout i saw this old bug:

if you use beans derived from other (abstract) beans and both 
implement the same method (overloading), the Class.getMethods()
will report them twice (at least on Linux Jdk1.2.2RC4) and so 
it is genreated twice in GenICHome, GenICRemote which results
in a compiler error: duplicate method.

<pseudo code snippet>

  public abstract class BaseBean extends javax.ejb.EntityBean {

    public String getSomeData()
      { return "Default"; }

  }

  public abstract class DerivedBean extends BaseBean {

    public String getSomeData()
      { return "MyOwnValue"; }

  }

</pseudo code snippet>

I attach a litte patch for this. It uses a new utility class
dealing with method fingerprints (=mangeling) to ensure unique
methods.

HTH,
         Markus

-- 
Dipl.-Ing. (FH) Markus Fritz             [EMAIL PROTECTED]
Just Innovative Software GmbH * Kranstrasse 8 * 70499 Stuttgart
diff -NuwbBrd --exclude=CVS* --exclude=.* --exclude=output --exclude=#*# 
objectweb.orig/jonas/src/org/objectweb/jonas/lib/Makefile 
objectweb/jonas/src/org/objectweb/jonas/lib/Makefile
--- objectweb.orig/jonas/src/org/objectweb/jonas/lib/Makefile   Thu Oct 28 16:07:10 
1999
+++ objectweb/jonas/src/org/objectweb/jonas/lib/Makefile        Wed Dec 22 12:39:47 
+1999
@@ -34,5 +34,6 @@
        InvalidBeanException \
        JavaType \
-       MarshallTool
+       MarshallTool \
+       MethodUniqueizer
 
 include $(ROOT)/stdrules.mk
diff -NuwbBrd --exclude=CVS* --exclude=.* --exclude=output --exclude=#*# 
objectweb.orig/jonas/src/org/objectweb/jonas/lib/MethodUniqueizer.java 
objectweb/jonas/src/org/objectweb/jonas/lib/MethodUniqueizer.java
--- objectweb.orig/jonas/src/org/objectweb/jonas/lib/MethodUniqueizer.java      Thu 
Jan  1 01:00:00 1970
+++ objectweb/jonas/src/org/objectweb/jonas/lib/MethodUniqueizer.java   Wed Dec 22 
+12:38:53 1999
@@ -0,0 +1,49 @@
+/**
+ * MethodUniqueizer.java
+ * @author: Markus Fritz 9/99
+ */
+
+package org.objectweb.jonas.lib ;
+
+/**
+ * Helper-Class to make methods unique
+ */
+public class MethodUniqueizer
+{
+
+    java.util.HashSet hMethods = new java.util.HashSet();
+
+    /**
+     * return true if method is already known
+     */
+    public boolean check( java.lang.reflect.Method m )
+    {
+       String fp = fingerprint( m );
+       if ( hMethods.contains( fp ) )
+           return false;
+       hMethods.add( fp );
+       return true;
+    }
+
+    /**
+     * Generate fingerprint (=mangeling)
+     */
+    String fingerprint( java.lang.reflect.Method method )
+    {
+       StringBuffer fingerprint = new StringBuffer();
+       fingerprint.append( method.getReturnType().getName() );
+       fingerprint.append( " " );
+       fingerprint.append( method.getName() );
+       fingerprint.append( "(" );
+       Class[] aCls = method.getParameterTypes();
+       if ( aCls.length > 0 )
+           fingerprint.append( aCls[0].getName() );
+       for ( int i=0; i<aCls.length; i++ ) {
+           fingerprint.append( "," );
+           fingerprint.append( aCls[i].getName() );
+       }
+       fingerprint.append( ")" );
+       return fingerprint.toString();
+    }
+
+}
diff -NuwbBrd --exclude=CVS* --exclude=.* --exclude=output --exclude=#*# 
objectweb.orig/jonas/src/org/objectweb/jonas/tools/GenICHome.java 
objectweb/jonas/src/org/objectweb/jonas/tools/GenICHome.java
--- objectweb.orig/jonas/src/org/objectweb/jonas/tools/GenICHome.java   Thu Oct 28 
16:07:10 1999
+++ objectweb/jonas/src/org/objectweb/jonas/tools/GenICHome.java        Wed Dec 22 
+12:38:53 1999
@@ -35,6 +35,7 @@
 import org.objectweb.jonas.lib.BeanNaming;
 import org.objectweb.jonas.lib.DD;
 import org.objectweb.jonas.lib.JavaType;
+import org.objectweb.jonas.lib.MethodUniqueizer;
 
 
 /**
@@ -163,10 +164,15 @@
 
        // create() and find...() Methodes defined in the home interface
        methods = ejbHomeClass.getMethods();
+       MethodUniqueizer oMU = new MethodUniqueizer();
        for (int m=0; m < methods.length; m++) {
            // Skip the methods defined in the 'javax.ejb.EJBHome' interface
            Method method = methods[m];
-           if (!method.getDeclaringClass().getName().equals("javax.ejb.EJBHome")) {
+           if ( method.getDeclaringClass().getName().
+                equals("javax.ejb.EJBHome") )
+               continue;
+           if ( ! oMU.check( method ) )
+               continue;
 
                boolean isCreate    = method.getName().equals("create");
                boolean isFindByPK  = method.getName().equals("findByPrimaryKey");
@@ -184,7 +190,6 @@
                }
 
                src.println();
-           }
        }
 
        // Class End
diff -NuwbBrd --exclude=CVS* --exclude=.* --exclude=output --exclude=#*# 
objectweb.orig/jonas/src/org/objectweb/jonas/tools/GenICRemote.java 
objectweb/jonas/src/org/objectweb/jonas/tools/GenICRemote.java
--- objectweb.orig/jonas/src/org/objectweb/jonas/tools/GenICRemote.java Thu Nov 18 
13:57:17 1999
+++ objectweb/jonas/src/org/objectweb/jonas/tools/GenICRemote.java      Wed Dec 22 
+12:38:53 1999
@@ -35,6 +35,7 @@
 import org.objectweb.jonas.lib.BeanNaming;
 import org.objectweb.jonas.lib.DD;
 import org.objectweb.jonas.lib.JavaType;
+import org.objectweb.jonas.lib.MethodUniqueizer;
 
 
 /**
@@ -156,13 +157,18 @@
 
        // Bussiness Methodes defined in the remote interface
        methods = ejbRemoteClass.getMethods();
+       MethodUniqueizer oMU = new MethodUniqueizer();
        for (int m=0; m < methods.length; m++) {
            // Skip the methods defined in the 'javax.ejb.EJBObject' interface
            Method method = methods[m];
-           if (!method.getDeclaringClass().getName().equals("javax.ejb.EJBObject")) {
+           if ( method.getDeclaringClass().getName().
+                equals("javax.ejb.EJBObject")) 
+               continue;
+           if ( ! oMU.check( method ) )
+               continue;
+           
                genBussinessMethod(method);
                src.println();
-           }
        }
 
        // createData(), removeData(), loadData(), storeData()

Reply via email to