Author: marius.bogoevici
Date: 2009-10-07 06:01:23 -0400 (Wed, 07 Oct 2009)
New Revision: 3865
Added:
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/interceptor/
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/interceptor/ClassInterceptionHandlerFactory.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/interceptor/InterceptorBindingsAdapter.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/interceptor/InterceptorInterceptionHandlerFactory.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/ejb3model/
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/Defender.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/ejb3model/Ejb3InterceptionModelTests.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/ejb3model/Goalkeeper.java
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/ManagedBean.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SessionBean.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/AbstractBeanDeployer.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/ejb/EnterpriseBeanInterceptionTests.java
Log:
Support @Interceptors-bound interceptors on managed beans and EJBs with
@InterceptionBinding.
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java 2009-10-06
16:11:44 UTC (rev 3864)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java 2009-10-07
10:01:23 UTC (rev 3865)
@@ -264,7 +264,8 @@
/**
* Interception model
*/
- private transient final InterceptorRegistry<Class<?>, Interceptor>
boundInterceptorsRegistry = new InterceptorRegistry<Class<?>, Interceptor>();
+ private transient final InterceptorRegistry<Class<?>,
Interceptor<?>> boundInterceptorsRegistry = new
InterceptorRegistry<Class<?>, Interceptor<?>>();
+ private transient final InterceptorRegistry<Class<?>, Class<?>>
declaredInterceptorsRegistry = new InterceptorRegistry<Class<?>,
Class<?>>();
/**
* Create a new, root, manager
@@ -1413,8 +1414,13 @@
this.currentInjectionPoint.remove();
}
- public InterceptorRegistry<Class<?>, Interceptor>
getBoundInterceptorsRegistry()
+ public InterceptorRegistry<Class<?>, Interceptor<?>>
getBoundInterceptorsRegistry()
{
return boundInterceptorsRegistry;
}
+
+ public InterceptorRegistry<Class<?>, Class<?>>
getDeclaredInterceptorsRegistry()
+ {
+ return declaredInterceptorsRegistry;
+ }
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java 2009-10-06
16:11:44 UTC (rev 3864)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java 2009-10-07
10:01:23 UTC (rev 3865)
@@ -444,7 +444,7 @@
{
if (manager.getBoundInterceptorsRegistry().getInterceptionModel(getType()) ==
null)
{
- InterceptionModelBuilder<Class<?>, Interceptor> builder =
InterceptionModelBuilder.newBuilderFor(getType(), (Class) Interceptor.class);
+ InterceptionModelBuilder<Class<?>, Interceptor<?>> builder =
InterceptionModelBuilder.newBuilderFor(getType(), (Class) Interceptor.class);
Set<Annotation> classBindingAnnotations =
flattenInterceptorBindings(manager, getAnnotatedItem().getAnnotations());
for (Class<? extends Annotation> annotation : getStereotypes())
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-06
16:11:44 UTC (rev 3864)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/ManagedBean.java 2009-10-07
10:01:23 UTC (rev 3865)
@@ -17,22 +17,28 @@
package org.jboss.webbeans.bean;
import java.util.Set;
+import java.util.List;
+import java.util.ArrayList;
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.event.Observes;
import javax.enterprise.inject.Disposes;
import javax.enterprise.inject.spi.Decorator;
import javax.enterprise.inject.spi.InjectionPoint;
-import javax.enterprise.inject.spi.Interceptor;
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.interceptor.Interceptors;
+import javax.interceptor.ExcludeClassInterceptors;
-import org.jboss.interceptor.proxy.DirectClassInterceptionHandler;
-import org.jboss.interceptor.proxy.InterceptionHandler;
+import org.jboss.interceptor.proxy.InterceptorProxyCreatorImpl;
import org.jboss.interceptor.proxy.InterceptionHandlerFactory;
-import org.jboss.interceptor.proxy.InterceptorProxyCreatorImpl;
import org.jboss.interceptor.util.InterceptionUtils;
+import org.jboss.interceptor.model.InterceptionModelBuilder;
+import org.jboss.interceptor.registry.InterceptorRegistry;
import org.jboss.webbeans.BeanManagerImpl;
import org.jboss.webbeans.DefinitionException;
import org.jboss.webbeans.DeploymentException;
+import org.jboss.webbeans.bean.interceptor.InterceptorInterceptionHandlerFactory;
+import org.jboss.webbeans.bean.interceptor.ClassInterceptionHandlerFactory;
import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
import org.jboss.webbeans.injection.ConstructorInjectionPoint;
import org.jboss.webbeans.injection.InjectionContextImpl;
@@ -69,7 +75,6 @@
private ManagedBean<?> specializedBean;
-
/**
* Creates a simple, annotation defined Web Bean
*
@@ -115,7 +120,7 @@
{
instance = applyDecorators(instance, creationalContext,
originalInjectionPoint);
}
- if (isInterceptionCandidate() && hasInterceptors())
+ if (isInterceptionCandidate() && (hasBoundInterceptors() ||
hasDeclaredInterceptors()))
{
instance = applyInterceptors(instance, creationalContext);
InterceptionUtils.executePostConstruct(instance);
@@ -176,7 +181,7 @@
{
try
{
- if (!isInterceptionCandidate() || !hasInterceptors())
+ if (!isInterceptionCandidate() || !hasBoundInterceptors())
preDestroy(instance);
else
{
@@ -204,6 +209,8 @@
initPostConstruct();
initPreDestroy();
initEEInjectionPoints();
+ if (isInterceptionCandidate())
+ initDeclaredInterceptors();
}
}
@@ -378,24 +385,40 @@
return !Beans.isInterceptor(getAnnotatedItem()) &&
!Beans.isDecorator(getAnnotatedItem());
}
- private boolean hasInterceptors()
+ private boolean hasBoundInterceptors()
{
- return
manager.getBoundInterceptorsRegistry().getInterceptionModel(getType()).getAllInterceptors().size()
> 0;
+ if (manager.getBoundInterceptorsRegistry().getInterceptionModel(getType()) !=
null)
+ return
manager.getBoundInterceptorsRegistry().getInterceptionModel(getType()).getAllInterceptors().size()
> 0;
+ else
+ return false;
}
+ private boolean hasDeclaredInterceptors()
+ {
+ if (manager.getDeclaredInterceptorsRegistry().getInterceptionModel(getType()) !=
null)
+ return
manager.getDeclaredInterceptorsRegistry().getInterceptionModel(getType()).getAllInterceptors().size()
> 0;
+ else
+ return false;
+ }
+
protected T applyInterceptors(T instance, final CreationalContext<T>
creationalContext)
{
try
{
- InterceptionHandlerFactory<Interceptor> factory = new
InterceptionHandlerFactory<Interceptor>()
+ List<InterceptorRegistry<Class<?>, ?>> interceptionRegistries
= new ArrayList<InterceptorRegistry<Class<?>,?>>();
+ List<InterceptionHandlerFactory<?>> interceptionHandlerFactories =
new ArrayList<InterceptionHandlerFactory<?>>();
+ if (hasDeclaredInterceptors())
{
- public InterceptionHandler createFor(final Interceptor interceptor)
- {
- final Object instance = getManager().getReference(interceptor,
creationalContext);
- return new DirectClassInterceptionHandler<Interceptor>(instance,
interceptor.getBeanClass());
- }
- };
- instance = new
InterceptorProxyCreatorImpl<Interceptor>(manager.getBoundInterceptorsRegistry(),
factory).createProxyFromInstance(instance, getType());
+ interceptionRegistries.add(manager.getDeclaredInterceptorsRegistry());
+ interceptionHandlerFactories.add(new
ClassInterceptionHandlerFactory(creationalContext, getManager()));
+ }
+ if (hasBoundInterceptors())
+ {
+ interceptionRegistries.add(manager.getBoundInterceptorsRegistry());
+ interceptionHandlerFactories.add(new
InterceptorInterceptionHandlerFactory(creationalContext, manager));
+ }
+ if (interceptionRegistries.size() > 0)
+ instance = new InterceptorProxyCreatorImpl(interceptionRegistries,
interceptionHandlerFactories).createProxyFromInstance(instance, getType());
} catch (Exception e)
{
@@ -404,4 +427,44 @@
return instance;
}
+ protected void initDeclaredInterceptors()
+ {
+ if (manager.getDeclaredInterceptorsRegistry().getInterceptionModel(getType()) ==
null)
+ {
+ InterceptionModelBuilder<Class<?>, Class<?>> builder =
InterceptionModelBuilder.newBuilderFor(getType(), (Class) Class.class);
+
+ Class<?>[] classDeclaredInterceptors = null;
+ if (getAnnotatedItem().isAnnotationPresent(Interceptors.class))
+ {
+ classDeclaredInterceptors =
getType().getAnnotation(Interceptors.class).value();
+ }
+
+ if (classDeclaredInterceptors != null)
+ {
+ builder.interceptPostConstruct().with(classDeclaredInterceptors);
+ builder.interceptPreDestroy().with(classDeclaredInterceptors);
+ }
+
+ List<WBMethod<?, ?>> businessMethods =
Beans.getInterceptableBusinessMethods(getAnnotatedItem());
+ for (WBMethod<?, ?> method : businessMethods)
+ {
+ boolean excludeClassInterceptors =
method.isAnnotationPresent(ExcludeClassInterceptors.class);
+ Class<?>[] methodDeclaredInterceptors = null;
+ if (method.isAnnotationPresent(Interceptors.class))
+ {
+ methodDeclaredInterceptors =
method.getAnnotation(Interceptors.class).value();
+ }
+ if (!excludeClassInterceptors && classDeclaredInterceptors != null)
+ {
+ builder.interceptAroundInvoke(((AnnotatedMethod)
method).getJavaMember()).with(classDeclaredInterceptors);
+ }
+ if (methodDeclaredInterceptors != null)
+ {
+ builder.interceptAroundInvoke(((AnnotatedMethod)
method).getJavaMember()).with(methodDeclaredInterceptors);
+ }
+ }
+ manager.getDeclaredInterceptorsRegistry().registerInterceptionModel(getType(),
builder.build());
+ }
+ }
+
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SessionBean.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SessionBean.java 2009-10-06
16:11:44 UTC (rev 3864)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SessionBean.java 2009-10-07
10:01:23 UTC (rev 3865)
@@ -40,6 +40,7 @@
import org.jboss.webbeans.bean.proxy.EnterpriseBeanInstance;
import org.jboss.webbeans.bean.proxy.EnterpriseBeanProxyMethodHandler;
import org.jboss.webbeans.bean.proxy.Marker;
+import org.jboss.webbeans.bean.interceptor.InterceptorBindingsAdapter;
import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
import org.jboss.webbeans.ejb.InternalEjbDescriptor;
import org.jboss.webbeans.ejb.api.SessionObjectReference;
@@ -53,6 +54,7 @@
import org.jboss.webbeans.resources.ClassTransformer;
import org.jboss.webbeans.util.Beans;
import org.jboss.webbeans.util.Proxies;
+import org.jboss.interceptor.model.InterceptionModel;
/**
* An enterprise bean representation
@@ -115,6 +117,7 @@
checkConflictingRoles();
checkObserverMethods();
checkScopeAllowed();
+ registerInterceptors();
}
}
@@ -394,6 +397,12 @@
{
return true;
}
-
+
+ private void registerInterceptors()
+ {
+
InterceptionModel<Class<?>,javax.enterprise.inject.spi.Interceptor<?>>
model =
manager.getBoundInterceptorsRegistry().getInterceptionModel(ejbDescriptor.getBeanClass());
+ if (model != null)
+
getManager().getServices().get(EjbServices.class).registerInterceptors(getEjbDescriptor(),
new InterceptorBindingsAdapter(model));
+ }
}
Added:
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/interceptor/ClassInterceptionHandlerFactory.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/interceptor/ClassInterceptionHandlerFactory.java
(rev 0)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/interceptor/ClassInterceptionHandlerFactory.java 2009-10-07
10:01:23 UTC (rev 3865)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jboss.webbeans.bean.interceptor;
+
+import javax.enterprise.context.spi.CreationalContext;
+
+import org.jboss.interceptor.proxy.InterceptionHandlerFactory;
+import org.jboss.interceptor.proxy.InterceptionHandler;
+import org.jboss.interceptor.proxy.DirectClassInterceptionHandler;
+import org.jboss.webbeans.DeploymentException;
+import org.jboss.webbeans.BeanManagerImpl;
+
+/**
+ * @author Marius Bogoevici
+*/
+public class ClassInterceptionHandlerFactory implements
InterceptionHandlerFactory<Class>
+{
+ private final CreationalContext<?> creationalContext;
+ private BeanManagerImpl manager;
+
+ public ClassInterceptionHandlerFactory(CreationalContext<?> creationalContext,
BeanManagerImpl manager)
+ {
+ this.creationalContext = creationalContext;
+ this.manager = manager;
+ }
+
+ public InterceptionHandler createFor(Class clazz)
+ {
+ try
+ {
+ // this is not a managed instance - assume no-argument constructor exists
+ Object interceptorInstance = clazz.newInstance();
+ // inject
+
manager.createInjectionTarget(manager.createAnnotatedType(clazz)).inject(interceptorInstance,
creationalContext);
+ return new DirectClassInterceptionHandler(interceptorInstance, clazz);
+ }
+ catch (Exception e)
+ {
+ throw new DeploymentException(e);
+ }
+ }
+}
Added:
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/interceptor/InterceptorBindingsAdapter.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/interceptor/InterceptorBindingsAdapter.java
(rev 0)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/interceptor/InterceptorBindingsAdapter.java 2009-10-07
10:01:23 UTC (rev 3865)
@@ -0,0 +1,95 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jboss.webbeans.bean.interceptor;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Collections;
+import java.util.Arrays;
+import java.lang.reflect.Method;
+
+import javax.enterprise.inject.spi.Interceptor;
+import javax.enterprise.inject.spi.InterceptionType;
+
+import org.jboss.webbeans.ejb.spi.InterceptorBindings;
+import org.jboss.interceptor.model.InterceptionModel;
+
+/**
+ * @author Marius Bogoevici
+ */
+public class InterceptorBindingsAdapter implements InterceptorBindings
+{
+
+ private InterceptionModel<Class<?>, Interceptor<?>>
interceptionModel;
+
+ public InterceptorBindingsAdapter(InterceptionModel<Class<?>,
Interceptor<?>> interceptionModel)
+ {
+ if (interceptionModel == null)
+ {
+ throw new IllegalArgumentException("Interception model must not be
null");
+ }
+ this.interceptionModel = interceptionModel;
+ }
+
+ public Collection<Interceptor<?>> getAllInterceptors()
+ {
+ return interceptionModel.getAllInterceptors();
+ }
+
+ public List<Interceptor<?>> getMethodInterceptors(InterceptionType
interceptionType, Method method)
+ {
+ if (interceptionType == null)
+ {
+ throw new IllegalArgumentException("InterceptionType must not be
null");
+ }
+
+ if (method == null)
+ {
+ throw new IllegalArgumentException("Method must not be null");
+ }
+
+ org.jboss.interceptor.model.InterceptionType internalInterceptionType =
org.jboss.interceptor.model.InterceptionType.valueOf(interceptionType.name());
+
+ if (internalInterceptionType.isLifecycleCallback())
+ {
+ throw new IllegalArgumentException("Interception type must not be
lifecycle, but it is " + interceptionType.name());
+ }
+
+ return interceptionModel.getInterceptors(internalInterceptionType, method);
+
+ }
+
+ public List<Interceptor<?>> getLifecycleInterceptors(InterceptionType
interceptionType)
+ {
+ if (interceptionType == null)
+ {
+ throw new IllegalArgumentException("InterceptionType must not be
null");
+ }
+
+ org.jboss.interceptor.model.InterceptionType internalInterceptionType =
org.jboss.interceptor.model.InterceptionType.valueOf(interceptionType.name());
+
+ if (!internalInterceptionType.isLifecycleCallback())
+ {
+ throw new IllegalArgumentException("Interception type must be lifecycle,
but it is " + interceptionType.name());
+ }
+
+ return interceptionModel.getInterceptors(internalInterceptionType, null);
+ }
+}
Added:
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/interceptor/InterceptorInterceptionHandlerFactory.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/interceptor/InterceptorInterceptionHandlerFactory.java
(rev 0)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/interceptor/InterceptorInterceptionHandlerFactory.java 2009-10-07
10:01:23 UTC (rev 3865)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jboss.webbeans.bean.interceptor;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Interceptor;
+
+import org.jboss.interceptor.proxy.DirectClassInterceptionHandler;
+import org.jboss.interceptor.proxy.InterceptionHandler;
+import org.jboss.interceptor.proxy.InterceptionHandlerFactory;
+import org.jboss.webbeans.BeanManagerImpl;
+
+/**
+ * @author Marius Bogoevici
+*/
+public class InterceptorInterceptionHandlerFactory implements
InterceptionHandlerFactory<Interceptor<?>>
+{
+ private final CreationalContext creationalContext;
+ private BeanManagerImpl manager;
+
+ public InterceptorInterceptionHandlerFactory(CreationalContext creationalContext,
BeanManagerImpl manager)
+ {
+ this.creationalContext = creationalContext;
+ this.manager = manager;
+ }
+
+ public BeanManagerImpl getManager()
+ {
+ return manager;
+ }
+
+ public InterceptionHandler createFor(final Interceptor interceptor)
+ {
+ Object instance = getManager().getReference(interceptor, creationalContext);
+ return new DirectClassInterceptionHandler(instance, interceptor.getBeanClass());
+ }
+
+}
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/AbstractBeanDeployer.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/AbstractBeanDeployer.java 2009-10-06
16:11:44 UTC (rev 3864)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/AbstractBeanDeployer.java 2009-10-07
10:01:23 UTC (rev 3865)
@@ -25,6 +25,7 @@
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.ProcessObserverMethod;
import javax.enterprise.inject.spi.ProcessProducer;
+import javax.enterprise.inject.spi.Interceptor;
import javax.inject.Inject;
import org.jboss.webbeans.BeanManagerImpl;
@@ -47,6 +48,7 @@
import org.jboss.webbeans.bootstrap.events.ProcessProducerImpl;
import org.jboss.webbeans.ejb.EJBApiAbstraction;
import org.jboss.webbeans.ejb.InternalEjbDescriptor;
+import org.jboss.webbeans.ejb.spi.EjbServices;
import org.jboss.webbeans.event.ObserverFactory;
import org.jboss.webbeans.event.ObserverMethodImpl;
import org.jboss.webbeans.introspector.WBClass;
@@ -60,6 +62,7 @@
import org.jboss.webbeans.util.Reflections;
import org.jboss.webbeans.util.reflection.ParameterizedTypeImpl;
import org.jboss.webbeans.ws.WSApiAbstraction;
+import org.jboss.interceptor.model.InterceptionModel;
public class AbstractBeanDeployer<E extends BeanDeployerEnvironment>
{
Modified:
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/ejb/EnterpriseBeanInterceptionTests.java
===================================================================
---
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/ejb/EnterpriseBeanInterceptionTests.java 2009-10-06
16:11:44 UTC (rev 3864)
+++
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/ejb/EnterpriseBeanInterceptionTests.java 2009-10-07
10:01:23 UTC (rev 3865)
@@ -26,7 +26,7 @@
public void testEnterpriseBeanInterceptionMetadataAdded() throws Exception
{
SessionBean<Ball> ballSessionBean =
(SessionBean<Ball>)getCurrentManager().getBeans(Ball.class).iterator().next();
- InterceptionModel<Class<?>, Interceptor> interceptionModel =
getCurrentManager().getBoundInterceptorsRegistry().getInterceptionModel(ballSessionBean.getType());
+ InterceptionModel<Class<?>, Interceptor<?>> interceptionModel =
getCurrentManager().getBoundInterceptorsRegistry().getInterceptionModel(ballSessionBean.getType());
List<javax.enterprise.inject.spi.Interceptor> interceptors =
new
ArrayList<javax.enterprise.inject.spi.Interceptor>(interceptionModel.getAllInterceptors());
Added:
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
(rev 0)
+++
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/ejb3model/Ball.java 2009-10-07
10:01:23 UTC (rev 3865)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jboss.webbeans.test.unit.interceptor.ejb3model;
+
+import javax.interceptor.Interceptors;
+import javax.interceptor.ExcludeClassInterceptors;
+
+/**
+ * @author Marius Bogoevici
+ */
+(a)Interceptors(Goalkeeper.class)
+public class Ball
+{
+ public static boolean played = false;
+
+ @ExcludeClassInterceptors
+ @Interceptors(Defender.class)
+ public void shoot()
+ {
+ played = true;
+ }
+
+ @Interceptors(Defender.class)
+ public void pass()
+ {
+ played = true;
+ };
+
+ public void lob()
+ {
+ played = true;
+ };
+}
Copied:
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/ejb3model/Defender.java
(from rev 3861,
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/ejb/Defender.java)
===================================================================
---
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/ejb3model/Defender.java
(rev 0)
+++
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/ejb3model/Defender.java 2009-10-07
10:01:23 UTC (rev 3865)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jboss.webbeans.test.unit.interceptor.ejb3model;
+
+import javax.interceptor.Interceptor;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+
+import org.jboss.webbeans.test.unit.interceptor.ejb.Pass;
+
+/**
+ * @author <a href="mailto:mariusb@redhat.com">Marius
Bogoevici</a>
+ */
+public class Defender
+{
+ public static boolean defended = false;
+
+ @AroundInvoke
+ public Object defend(InvocationContext context) throws Exception
+ {
+ defended = true;
+ return context.proceed();
+ }
+}
\ No newline at end of file
Added:
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/ejb3model/Ejb3InterceptionModelTests.java
===================================================================
---
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/ejb3model/Ejb3InterceptionModelTests.java
(rev 0)
+++
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/ejb3model/Ejb3InterceptionModelTests.java 2009-10-07
10:01:23 UTC (rev 3865)
@@ -0,0 +1,82 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jboss.webbeans.test.unit.interceptor.ejb3model;
+
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.context.spi.CreationalContext;
+
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.webbeans.test.AbstractWebBeansTest;
+
+import org.testng.annotations.Test;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.BeforeMethod;
+
+
+/**
+ * @author Marius Bogoevici
+ */
+@Artifact
+public class Ejb3InterceptionModelTests extends AbstractWebBeansTest
+{
+ @BeforeMethod
+ public void reset()
+ {
+ Ball.played = false;
+ Goalkeeper.caught = false;
+ Defender.defended = false;
+ }
+
+ @Test
+ public void testSimpleInterceptor()
+ {
+ Bean bean = getCurrentManager().getBeans(Ball.class).iterator().next();
+ CreationalContext creationalContext =
getCurrentManager().createCreationalContext(bean);
+ Ball ball = (Ball) bean.create(creationalContext);
+ ball.shoot();
+ assert Defender.defended;
+ assert Ball.played;
+ assert !Goalkeeper.caught;
+ }
+
+
+ @Test
+ public void testSimpleInterceptor2()
+ {
+ Bean bean = getCurrentManager().getBeans(Ball.class).iterator().next();
+ CreationalContext creationalContext =
getCurrentManager().createCreationalContext(bean);
+ Ball ball = (Ball) bean.create(creationalContext);
+ ball.pass();
+ assert Defender.defended;
+ assert Ball.played;
+ assert Goalkeeper.caught;
+ }
+
+ @Test
+ public void testSimpleInterceptor3()
+ {
+ Bean bean = getCurrentManager().getBeans(Ball.class).iterator().next();
+ CreationalContext creationalContext =
getCurrentManager().createCreationalContext(bean);
+ Ball ball = (Ball) bean.create(creationalContext);
+ ball.lob();
+ assert !Defender.defended;
+ assert Ball.played;
+ assert Goalkeeper.caught;
+ }
+
+}
Copied:
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/ejb3model/Goalkeeper.java
(from rev 3861,
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/ejb/Goalkeeper.java)
===================================================================
---
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/ejb3model/Goalkeeper.java
(rev 0)
+++
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/ejb3model/Goalkeeper.java 2009-10-07
10:01:23 UTC (rev 3865)
@@ -0,0 +1,37 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jboss.webbeans.test.unit.interceptor.ejb3model;
+
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+
+/**
+ * @author <a href="mailto:mariusb@redhat.com">Marius
Bogoevici</a>
+ */
+public class Goalkeeper
+{
+
+ public static boolean caught = false;
+
+ @AroundInvoke
+ public Object catchBall(InvocationContext invocationContext) throws Exception
+ {
+ caught = true;
+ return invocationContext.proceed();
+ }
+}
\ No newline at end of file