[jboss-cvs] JBossAS SVN: r67984 - in trunk/ejb3/src/main/org/jboss/ejb3: lang and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Dec 6 05:10:32 EST 2007


Author: wolfc
Date: 2007-12-06 05:10:32 -0500 (Thu, 06 Dec 2007)
New Revision: 67984

Added:
   trunk/ejb3/src/main/org/jboss/ejb3/lang/
   trunk/ejb3/src/main/org/jboss/ejb3/lang/ClassHelper.java
Modified:
   trunk/ejb3/src/main/org/jboss/ejb3/Ejb3DescriptorHandler.java
Log:
EJBTHREE-1149: allowing declared methods of super classes as well

Modified: trunk/ejb3/src/main/org/jboss/ejb3/Ejb3DescriptorHandler.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/Ejb3DescriptorHandler.java	2007-12-06 10:09:55 UTC (rev 67983)
+++ trunk/ejb3/src/main/org/jboss/ejb3/Ejb3DescriptorHandler.java	2007-12-06 10:10:32 UTC (rev 67984)
@@ -136,6 +136,7 @@
 import org.jboss.ejb3.annotation.impl.ServiceImpl;
 import org.jboss.ejb3.annotation.impl.TransactionTimeoutImpl;
 import org.jboss.ejb3.interceptor.InterceptorInfoRepository;
+import org.jboss.ejb3.lang.ClassHelper;
 import org.jboss.ejb3.mdb.ConsumerContainer;
 import org.jboss.ejb3.mdb.MDB;
 import org.jboss.ejb3.service.ServiceContainer;
@@ -2141,8 +2142,7 @@
                }
                if(log.isTraceEnabled())
                   log.trace("Looking for method " + methodName + Arrays.toString(methodSignature) + " on class " + ejbClass);
-               java.lang.reflect.Member member = ejbClass.getDeclaredMethod(methodName,
-                     methodSignature);
+               Member member = ClassHelper.getPrivateMethod(ejbClass, methodName, methodSignature);
                log.debug("adding " + annotationClass.getName()
                      + " method annotation to " + member);
                annotations.addAnnotation(member, annotationClass, annotation);

Added: trunk/ejb3/src/main/org/jboss/ejb3/lang/ClassHelper.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/lang/ClassHelper.java	                        (rev 0)
+++ trunk/ejb3/src/main/org/jboss/ejb3/lang/ClassHelper.java	2007-12-06 10:10:32 UTC (rev 67984)
@@ -0,0 +1,103 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.lang;
+
+import java.lang.reflect.Method;
+import java.util.Arrays;
+
+/**
+ * Usefull methods for classes.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class ClassHelper
+{
+   /**
+    * @see Class#argumentTypesToString
+    */
+   private static String argumentTypesToString(Class<?>[] argTypes)
+   {
+      StringBuilder buf = new StringBuilder();
+      buf.append("(");
+      if (argTypes != null)
+      {
+         for (int i = 0; i < argTypes.length; i++)
+         {
+            if (i > 0)
+            {
+               buf.append(", ");
+            }
+            Class<?> c = argTypes[i];
+            buf.append((c == null) ? "null" : c.getName());
+         }
+      }
+      buf.append(")");
+      return buf.toString();
+   }
+
+   private static Method findPrivateMethod(Class<?> target, String methodName, Class<?>... paramTypes)
+   {
+      // Top of the world
+      if(target == null)
+         return null;
+      
+      // TODO: what is faster? scan or catch exception?
+      for(Method method : target.getDeclaredMethods())
+      {
+         if(method.getName().equals(methodName))
+         {
+            if(paramTypes == null)
+               return method;
+            
+            if(Arrays.equals(method.getParameterTypes(), paramTypes))
+               return method;
+         }
+      }
+      
+      return findPrivateMethod(target.getSuperclass(), methodName, paramTypes);
+   }
+   
+   /**
+    * Returns the <code>Method</code> with the given attributes of either this class
+    * or one of it's super classes.
+    * 
+    * TODO: return type specifics are not considered
+    * 
+    * @param cls            class to scan
+    * @param methodName     the name of the method
+    * @param paramTypes     the parameter types
+    * @return               the <code>Method</code> matching the method name and parameters
+    * @throws NoSuchMethodException if no method can be found
+    */
+   public static Method getPrivateMethod(Class<?> cls, String methodName, Class<?>... paramTypes) throws NoSuchMethodException
+   {
+      assert cls != null : "cls is null";
+      assert methodName != null : "methodName is null";
+      
+      Method result = findPrivateMethod(cls, methodName, paramTypes);
+      if(result == null)
+         throw new NoSuchMethodException(cls.getName() + "." + methodName + argumentTypesToString(paramTypes));
+      
+      return result;
+   }
+}


Property changes on: trunk/ejb3/src/main/org/jboss/ejb3/lang/ClassHelper.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native




More information about the jboss-cvs-commits mailing list