Author: marius.bogoevici
Date: 2009-10-07 17:43:49 -0400 (Wed, 07 Oct 2009)
New Revision: 3872
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/ManagedBean.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/util/Reflections.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/ejb3model/Ball.java
Log:
Make @Interceptors and @ExcludeClassInterceptors completely optional. Look for them only
if they're on the classpath.
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/ManagedBean.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/ManagedBean.java 2009-10-07
19:55:47 UTC (rev 3871)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/ManagedBean.java 2009-10-07
21:43:49 UTC (rev 3872)
@@ -19,6 +19,7 @@
import java.util.Set;
import java.util.List;
import java.util.ArrayList;
+import java.lang.annotation.Annotation;
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.event.Observes;
@@ -26,8 +27,6 @@
import javax.enterprise.inject.spi.Decorator;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.enterprise.inject.spi.AnnotatedMethod;
-import javax.interceptor.Interceptors;
-import javax.interceptor.ExcludeClassInterceptors;
import org.jboss.interceptor.proxy.InterceptorProxyCreatorImpl;
import org.jboss.interceptor.proxy.InterceptionHandlerFactory;
@@ -429,16 +428,16 @@
protected void initDeclaredInterceptors()
{
- if (manager.getDeclaredInterceptorsRegistry().getInterceptionModel(getType()) ==
null)
+ if (manager.getDeclaredInterceptorsRegistry().getInterceptionModel(getType()) ==
null && InterceptionUtils.supportsEjb3InterceptorDeclaration())
{
InterceptionModelBuilder<Class<?>, Class<?>> builder =
InterceptionModelBuilder.newBuilderFor(getType(), (Class) Class.class);
Class<?>[] classDeclaredInterceptors = null;
- if (getAnnotatedItem().isAnnotationPresent(Interceptors.class))
+ if
(getAnnotatedItem().isAnnotationPresent(InterceptionUtils.getInterceptorsAnnotationClass()))
{
- classDeclaredInterceptors =
getType().getAnnotation(Interceptors.class).value();
+ Annotation interceptorsAnnotation =
getType().getAnnotation(InterceptionUtils.getInterceptorsAnnotationClass());
+ classDeclaredInterceptors =
Reflections.extractValues(interceptorsAnnotation);
}
-
if (classDeclaredInterceptors != null)
{
builder.interceptPostConstruct().with(classDeclaredInterceptors);
@@ -448,11 +447,11 @@
List<WBMethod<?, ?>> businessMethods =
Beans.getInterceptableBusinessMethods(getAnnotatedItem());
for (WBMethod<?, ?> method : businessMethods)
{
- boolean excludeClassInterceptors =
method.isAnnotationPresent(ExcludeClassInterceptors.class);
+ boolean excludeClassInterceptors =
method.isAnnotationPresent(InterceptionUtils.getExcludeClassInterceptorsAnnotationClass());
Class<?>[] methodDeclaredInterceptors = null;
- if (method.isAnnotationPresent(Interceptors.class))
+ if
(method.isAnnotationPresent(InterceptionUtils.getInterceptorsAnnotationClass()))
{
- methodDeclaredInterceptors =
method.getAnnotation(Interceptors.class).value();
+ methodDeclaredInterceptors =
Reflections.extractValues(method.getAnnotation(InterceptionUtils.getInterceptorsAnnotationClass()));
}
if (!excludeClassInterceptors && classDeclaredInterceptors != null)
{
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/util/Reflections.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/util/Reflections.java 2009-10-07
19:55:47 UTC (rev 3871)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/util/Reflections.java 2009-10-07
21:43:49 UTC (rev 3872)
@@ -41,6 +41,7 @@
import org.jboss.webbeans.log.Log;
import org.jboss.webbeans.log.Logging;
import org.jboss.webbeans.util.reflection.ParameterizedTypeImpl;
+import org.jboss.webbeans.DeploymentException;
/**
* Utility class for static reflection-type operations
@@ -55,8 +56,8 @@
public static final Type[] EMPTY_TYPES = {};
- public static final Annotation[] EMPTY_ANNOTATIONS = {};
-
+ public static final Annotation[] EMPTY_ANNOTATIONS = {};
+
public static class HierarchyDiscovery
{
@@ -899,4 +900,18 @@
}
}
+ public static Class<?>[] extractValues(Annotation annotation)
+ {
+ try
+ {
+ Class<?>[] valueClasses = (Class<?>[])
annotation.annotationType().getMethod("value").invoke(annotation);
+ return valueClasses;
+ }
+ catch (Exception e)
+ {
+ throw new DeploymentException("Cannot access values() on annotation",
e);
+ }
+ }
+
+
}
Modified:
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/ejb3model/Ball.java
===================================================================
---
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/ejb3model/Ball.java 2009-10-07
19:55:47 UTC (rev 3871)
+++
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/ejb3model/Ball.java 2009-10-07
21:43:49 UTC (rev 3872)
@@ -39,10 +39,10 @@
public void pass()
{
played = true;
- };
+ }
public void lob()
{
played = true;
- };
+ }
}
Show replies by date