[webbeans-commits] Webbeans SVN: r289 - in ri/trunk/webbeans-ri/src: main/java/org/jboss/webbeans/util and 1 other directories.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Tue Nov 11 02:20:01 EST 2008
Author: nickarls
Date: 2008-11-11 02:20:01 -0500 (Tue, 11 Nov 2008)
New Revision: 289
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ProxyMethodHandler.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/lifecycle/EnterpriseBeanLifecycleTest.java
Log:
Minor typos, refactoring, remove method check loosening
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java 2008-11-09 14:57:41 UTC (rev 288)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java 2008-11-11 07:20:01 UTC (rev 289)
@@ -69,11 +69,11 @@
{
if (getType().isAnnotationPresent(Interceptor.class))
{
- throw new DefinitionException("Enterprise beans can't be interceptors");
+ throw new DefinitionException("Enterprise beans cannot be interceptors");
}
if (getType().isAnnotationPresent(Decorator.class))
{
- throw new DefinitionException("Enterprise beans can't be decorators");
+ throw new DefinitionException("Enterprise beans cannot be decorators");
}
}
@@ -151,10 +151,20 @@
{
super.removeMethod = checkRemoveMethod(possibleRemoveMethods.get(0));
}
- else if (possibleRemoveMethods.size() > 1)
+ else if (possibleRemoveMethods.size() == 2)
{
- throw new DefinitionException("Multiple remove methods are annotated @Destructor for " + getType());
+ Method firstMethod = possibleRemoveMethods.get(0);
+ Method secondMethod = possibleRemoveMethods.get(1);
+ // If the method has both the @Remove and @Destructor annotation, it gets added twice in
+ // the EjbMetaData constructor.
+ if (!firstMethod.equals(secondMethod)) {
+ throw new DefinitionException("Multiple remove methods are annotated @Remove/@Destructor for " + getType());
+ }
}
+ else if (possibleRemoveMethods.size() > 2)
+ {
+ throw new DefinitionException("Multiple remove methods are annotated @Remove/@Destructor for " + getType());
+ }
else if (possibleRemoveMethods.size() == 0)
{
throw new RuntimeException("Multiple remove methods are declared, and none are annotated @Destructor for " + getType());
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ProxyMethodHandler.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ProxyMethodHandler.java 2008-11-09 14:57:41 UTC (rev 288)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ProxyMethodHandler.java 2008-11-11 07:20:01 UTC (rev 289)
@@ -25,7 +25,8 @@
ProxyMethodHandler.manager = manager;
}
- public Object invoke(Object self, Method method, Method proceed, Object[] args) throws Throwable
+ public Object invoke(Object self, Method method, Method proceed,
+ Object[] args) throws Throwable
{
if (bean == null)
{
@@ -33,23 +34,10 @@
}
Context context = manager.getContext(bean.getScopeType());
Object proxiedInstance = context.get(bean, true);
- Method proxiedMethod = getMethod(method, proxiedInstance);
+ Method proxiedMethod = Reflections.lookupMethod(method, proxiedInstance);
return proxiedMethod.invoke(proxiedInstance, args);
}
- private static Method getMethod(Method method, Object instance)
- {
- for (Class<? extends Object> c = instance.getClass(); c!=Object.class; c=c.getSuperclass())
- {
- try
- {
- Method m = c.getDeclaredMethod(method.getName(), method.getParameterTypes());
- if (!m.isAccessible()) m.setAccessible(true);
- return m;
- }
- catch (NoSuchMethodException nsme) {}
- }
- throw new IllegalArgumentException("method not implemented by instance");
- }
+
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java 2008-11-09 14:57:41 UTC (rev 288)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java 2008-11-11 07:20:01 UTC (rev 289)
@@ -284,4 +284,25 @@
}
}
+ public static Method lookupMethod(Method method, Object instance)
+ {
+ for (Class<? extends Object> clazz = instance.getClass(); clazz != Object.class; clazz = clazz.getSuperclass())
+ {
+ try
+ {
+ Method targetMethod = clazz.getDeclaredMethod(method.getName(),
+ method.getParameterTypes());
+ if (!targetMethod.isAccessible())
+ {
+ targetMethod.setAccessible(true);
+ }
+ return targetMethod;
+ } catch (NoSuchMethodException nsme)
+ {
+ // Expected, nothing to see here.
+ }
+ }
+ throw new IllegalArgumentException("Method " + method.getName() + " not implemented by instance");
+ }
+
}
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/lifecycle/EnterpriseBeanLifecycleTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/lifecycle/EnterpriseBeanLifecycleTest.java 2008-11-09 14:57:41 UTC (rev 288)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/lifecycle/EnterpriseBeanLifecycleTest.java 2008-11-11 07:20:01 UTC (rev 289)
@@ -2,10 +2,11 @@
import javax.webbeans.UnremovedException;
+import org.jboss.webbeans.test.AbstractTest;
import org.jboss.webbeans.test.SpecAssertion;
import org.testng.annotations.Test;
-public class EnterpriseBeanLifecycleTest
+public class EnterpriseBeanLifecycleTest extends AbstractTest
{
@Test(groups="removeMethod") @SpecAssertion(section="3.2.3")
More information about the weld-commits
mailing list