You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by st...@apache.org on 2010/01/22 22:17:33 UTC
svn commit: r902270 - in /openwebbeans/trunk/webbeans-impl/src:
main/java/org/apache/webbeans/event/ main/java/org/apache/webbeans/intercept/
test/java/org/apache/webbeans/test/
test/java/org/apache/webbeans/test/component/event/normal/ test/java/org/a...
Author: struberg
Date: Fri Jan 22 21:17:31 2010
New Revision: 902270
URL: http://svn.apache.org/viewvc?rev=902270&view=rev
Log:
OWB-249 use a bean reference instead of the internal instance to enable interceptors and decorators for eventing methods
Added:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/Transactional.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/TransactionalInterceptor.java
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/ComponentWithObserves2.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/event/component/ObserversComponentTest.java
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java?rev=902270&r1=902269&r2=902270&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java Fri Jan 22 21:17:31 2010
@@ -160,7 +160,7 @@
AbstractBean<Object> specializedComponent = null;
Object object = null;
- CreationalContext<?> creationalContext = null;
+ CreationalContext<Object> creationalContext = null;
try
{
@@ -189,15 +189,15 @@
creationalContext = manager.createCreationalContext(specializedComponent);
- // lookup the contextual instance if one already exists
- object = context.get(specializedComponent);
-
- if(object == null && !this.ifExist)
+ // on Reception.IF_EXISTS: ignore this bean if a the contextual instance doesn't already exist
+ if (ifExist && context.get(specializedComponent) == null)
{
- // on Reception.ALWAYS we must get a contextual reference if we didn't find the contextual instance
- object = manager.getReference(specializedComponent, specializedComponent.getBeanClass(), creationalContext);
+ return;
}
+ // on Reception.ALWAYS we must get a contextual reference if we didn't find the contextual instance
+ object = manager.getReference(specializedComponent, specializedComponent.getBeanClass(), creationalContext);
+
if (object != null)
{
//Invoke Method
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java?rev=902270&r1=902269&r2=902270&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java Fri Jan 22 21:17:31 2010
@@ -165,7 +165,7 @@
private static void addMethodInterceptors(Class<?> clazz, List<InterceptorData> stack, Set<Interceptor<?>> componentInterceptors)
{
Method[] methods = clazz.getDeclaredMethods();
- Set<Annotation> set = new HashSet<Annotation>();
+ Set<Annotation> interceptorAnns = new HashSet<Annotation>();
for (Method method : methods)
{
@@ -176,12 +176,12 @@
for (Annotation ann : anns)
{
- set.add(ann);
+ interceptorAnns.add(ann);
}
for (Annotation ann : annsClazz)
{
- set.add(ann);
+ interceptorAnns.add(ann);
}
}
@@ -194,30 +194,33 @@
for (Annotation ann : steroInterceptorBindings)
{
- set.add(ann);
+ interceptorAnns.add(ann);
}
}
}
- Annotation[] result = new Annotation[set.size()];
- result = set.toArray(result);
-
- Set<Interceptor<?>> setInterceptors = findDeployedWebBeansInterceptor(result);
-
- if(componentInterceptors != null)
- {
- setInterceptors.removeAll(componentInterceptors);
- }
-
- Iterator<Interceptor<?>> it = setInterceptors.iterator();
-
- while (it.hasNext())
+ if (!interceptorAnns.isEmpty())
{
- WebBeansInterceptor<?> interceptor = (WebBeansInterceptor<?>) it.next();
-
- WebBeansUtil.configureInterceptorMethods(interceptor, interceptor.getClazz(), AroundInvoke.class, true, true, stack, method, true);
- WebBeansUtil.configureInterceptorMethods(interceptor, interceptor.getClazz(), PostConstruct.class, true, true, stack, method, true);
- WebBeansUtil.configureInterceptorMethods(interceptor, interceptor.getClazz(), PreDestroy.class, true, true, stack, method, true);
+ Annotation[] result = new Annotation[interceptorAnns.size()];
+ result = interceptorAnns.toArray(result);
+
+ Set<Interceptor<?>> setInterceptors = findDeployedWebBeansInterceptor(result);
+
+ if(componentInterceptors != null)
+ {
+ setInterceptors.removeAll(componentInterceptors);
+ }
+
+ Iterator<Interceptor<?>> it = setInterceptors.iterator();
+
+ while (it.hasNext())
+ {
+ WebBeansInterceptor<?> interceptor = (WebBeansInterceptor<?>) it.next();
+
+ WebBeansUtil.configureInterceptorMethods(interceptor, interceptor.getClazz(), AroundInvoke.class, true, true, stack, method, true);
+ WebBeansUtil.configureInterceptorMethods(interceptor, interceptor.getClazz(), PostConstruct.class, true, true, stack, method, true);
+ WebBeansUtil.configureInterceptorMethods(interceptor, interceptor.getClazz(), PreDestroy.class, true, true, stack, method, true);
+ }
}
}
Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java?rev=902270&r1=902269&r2=902270&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java Fri Jan 22 21:17:31 2010
@@ -419,17 +419,13 @@
ManagedBean<T> component = null;
ManagedBeanConfigurator.checkManagedBeanCondition(clazz);
- {
- // This is the interceptor class
- if (InterceptorsManager.getInstance().isInterceptorEnabled(clazz))
- {
- InterceptorUtil.checkInterceptorConditions(clazz);
- component = ManagedBeanConfigurator.define(clazz, WebBeansType.INTERCEPTOR);
- WebBeansInterceptorConfig.configureInterceptorClass((ManagedBean<Object>) component,
- AnnotationUtil.getInterceptorBindingMetaAnnotations(clazz.getDeclaredAnnotations()));
- }
+
+ InterceptorsManager.getInstance().addNewInterceptor(clazz);
+ InterceptorUtil.checkInterceptorConditions(clazz);
+ component = ManagedBeanConfigurator.define(clazz, WebBeansType.INTERCEPTOR);
+ WebBeansInterceptorConfig.configureInterceptorClass((ManagedBean<Object>) component,
+ AnnotationUtil.getInterceptorBindingMetaAnnotations(clazz.getDeclaredAnnotations()));
- }
return component;
}
Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/ComponentWithObserves2.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/ComponentWithObserves2.java?rev=902270&r1=902269&r2=902270&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/ComponentWithObserves2.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/ComponentWithObserves2.java Fri Jan 22 21:17:31 2010
@@ -1,15 +1,18 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to You 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.
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.webbeans.test.component.event.normal;
@@ -28,12 +31,20 @@
private String user;
+ /** This gets set via the TransactionalInterceptor */
+ public static boolean hasBeenIntercepted;
+
public void afterLogin(@Observes @Role(value = "USER") LoggedInEvent event, PaymentProcessorComponent payment)
{
+ hasBeenIntercepted = false;
this.payment = payment.getPaymentCheck();
this.user = event.getUserName();
}
+ /**
+ * Test if observer functions can be intercepted
+ */
+ @Transactional
public void afterAdminLogin(@Observes @Role(value = "ADMIN") LoggedInEvent event, PaymentProcessorComponent payment)
{
this.payment = payment.getPaymentCheck();
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/Transactional.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/Transactional.java?rev=902270&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/Transactional.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/Transactional.java Fri Jan 22 21:17:31 2010
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.webbeans.test.component.event.normal;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import javax.interceptor.InterceptorBinding;
+
+@InterceptorBinding
+@Retention(RetentionPolicy.RUNTIME)
+@Target( { ElementType.TYPE, ElementType.METHOD })
+public @interface Transactional
+{
+
+}
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/TransactionalInterceptor.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/TransactionalInterceptor.java?rev=902270&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/TransactionalInterceptor.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/TransactionalInterceptor.java Fri Jan 22 21:17:31 2010
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.webbeans.test.component.event.normal;
+
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.Interceptor;
+import javax.interceptor.InvocationContext;
+
+@Interceptor
+@Transactional
+public class TransactionalInterceptor
+{
+
+ @AroundInvoke
+ public Object caller(InvocationContext context) throws Exception
+ {
+ try
+ {
+ ComponentWithObserves2.hasBeenIntercepted = true;
+ return context.proceed();
+
+ }catch(Exception e)
+ {
+ ComponentWithObserves2.hasBeenIntercepted = false;
+ }
+
+ return null;
+ }
+}
Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/event/component/ObserversComponentTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/event/component/ObserversComponentTest.java?rev=902270&r1=902269&r2=902270&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/event/component/ObserversComponentTest.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/event/component/ObserversComponentTest.java Fri Jan 22 21:17:31 2010
@@ -1,15 +1,18 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to You 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.
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.webbeans.test.unittests.event.component;
@@ -31,6 +34,7 @@
import org.apache.webbeans.test.component.event.normal.ComponentWithObservable1;
import org.apache.webbeans.test.component.event.normal.ComponentWithObserves1;
import org.apache.webbeans.test.component.event.normal.ComponentWithObserves2;
+import org.apache.webbeans.test.component.event.normal.TransactionalInterceptor;
import org.apache.webbeans.test.event.LoggedInEvent;
import org.apache.webbeans.util.WebBeansUtil;
import org.junit.Before;
@@ -152,6 +156,7 @@
{
clear();
+ defineInterceptor(TransactionalInterceptor.class);
defineManagedBean(CheckWithCheckPayment.class);
defineManagedBean(CheckWithMoneyPayment.class);
defineManagedBean(PaymentProcessorComponent.class);
@@ -180,21 +185,35 @@
}
+ ComponentWithObserves2.hasBeenIntercepted = false;
+
Annotation[] anns = new Annotation[1];
anns[0] = new RoleUser();
getManager().fireEvent(event, anns);
ComponentWithObserves2 instance = getManager().getInstance(component);
+ Assert.assertFalse(ComponentWithObserves2.hasBeenIntercepted);
+
Assert.assertNotNull(instance.getPayment());
Assert.assertEquals("USER", instance.getUser());
anns[0] = new RoleAdmin();
event = new LoggedInEvent("ADMIN");
+
+ getManager().fireEvent(event, anns);
+ instance = getManager().getInstance(component);
+
+ Assert.assertTrue(ComponentWithObserves2.hasBeenIntercepted);
+ Assert.assertNotNull(instance.getPayment());
+ Assert.assertEquals("ADMIN", instance.getUser());
+ // lessons learned: do it again sam! ;)
+ ComponentWithObserves2.hasBeenIntercepted = false;
getManager().fireEvent(event, anns);
instance = getManager().getInstance(component);
+ Assert.assertTrue(ComponentWithObserves2.hasBeenIntercepted);
Assert.assertNotNull(instance.getPayment());
Assert.assertEquals("ADMIN", instance.getUser());
Re: svn commit: r902270 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/event/ main/java/org/apache/webbeans/intercept/ test/java/org/apache/webbeans/test/ test/java/org/apache/webbeans/test/component/event/normal/ test/java/org/a...
Posted by Mark Struberg <st...@yahoo.de>.
Gurkan, I recapitulated our previous conversation and came to the conclusion that we really need to use references also in the NotificationManager, because otherwise something like
@Transactional
public void onUserLogin(@Observes UserLoggedInEvent uli) {
... do something in the database ...
}
would not work.
I will now look at the problem why my injection points are null if I only use field access (it works if I invoke methods).
LieGrue,
strub
--- On Fri, 1/22/10, struberg@apache.org <st...@apache.org> wrote:
> From: struberg@apache.org <st...@apache.org>
> Subject: svn commit: r902270 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/event/ main/java/org/apache/webbeans/intercept/ test/java/org/apache/webbeans/test/ test/java/org/apache/webbeans/test/component/event/normal/ test/java/org/a...
> To: commits@openwebbeans.apache.org
> Date: Friday, January 22, 2010, 10:17 PM
> Author: struberg
> Date: Fri Jan 22 21:17:31 2010
> New Revision: 902270
>
> URL: http://svn.apache.org/viewvc?rev=902270&view=rev
> Log:
> OWB-249 use a bean reference instead of the internal
> instance to enable interceptors and decorators for eventing
> methods
>
> Added:
>
> openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/Transactional.java
>
> openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/TransactionalInterceptor.java
> Modified:
>
> openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
>
> openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java
>
> openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java
>
> openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/ComponentWithObserves2.java
>
> openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/event/component/ObserversComponentTest.java
>
> Modified:
> openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
> URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java?rev=902270&r1=902269&r2=902270&view=diff
> ==============================================================================
> ---
> openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
> (original)
> +++
> openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
> Fri Jan 22 21:17:31 2010
> @@ -160,7 +160,7 @@
>
> AbstractBean<Object>
> specializedComponent = null;
> Object object =
> null;
>
> - CreationalContext<?>
> creationalContext = null;
> +
> CreationalContext<Object> creationalContext = null;
>
> try
> {
> @@ -189,15 +189,15 @@
>
>
>
> creationalContext =
> manager.createCreationalContext(specializedComponent);
>
>
> - //
> lookup the contextual instance if one already exists
> -
> object = context.get(specializedComponent);
> -
> -
> if(object == null && !this.ifExist)
> + //
> on Reception.IF_EXISTS: ignore this bean if a the contextual
> instance doesn't already exist
> + if
> (ifExist && context.get(specializedComponent) ==
> null)
>
> {
> -
> // on Reception.ALWAYS we must get a
> contextual reference if we didn't find the contextual
> instance
> -
> object =
> manager.getReference(specializedComponent,
> specializedComponent.getBeanClass(), creationalContext);
> +
> return;
>
> }
>
>
> + //
> on Reception.ALWAYS we must get a contextual reference if we
> didn't find the contextual instance
> +
> object = manager.getReference(specializedComponent,
> specializedComponent.getBeanClass(), creationalContext);
> +
>
> if (object != null)
>
> {
>
> //Invoke Method
>
> Modified:
> openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java
> URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java?rev=902270&r1=902269&r2=902270&view=diff
> ==============================================================================
> ---
> openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java
> (original)
> +++
> openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java
> Fri Jan 22 21:17:31 2010
> @@ -165,7 +165,7 @@
> private static void
> addMethodInterceptors(Class<?> clazz,
> List<InterceptorData> stack,
> Set<Interceptor<?>> componentInterceptors)
> {
> Method[] methods =
> clazz.getDeclaredMethods();
> - Set<Annotation> set =
> new HashSet<Annotation>();
> + Set<Annotation>
> interceptorAnns = new HashSet<Annotation>();
>
> for (Method method :
> methods)
> {
> @@ -176,12 +176,12 @@
>
>
> for (Annotation ann : anns)
>
> {
> -
> set.add(ann);
> +
> interceptorAnns.add(ann);
>
> }
>
>
> for (Annotation ann : annsClazz)
>
> {
> -
> set.add(ann);
> +
> interceptorAnns.add(ann);
>
> }
> }
>
> @@ -194,30 +194,33 @@
>
>
> for (Annotation ann :
> steroInterceptorBindings)
>
> {
> -
> set.add(ann);
> +
> interceptorAnns.add(ann);
>
> }
>
> }
> }
>
> - Annotation[]
> result = new Annotation[set.size()];
> - result =
> set.toArray(result);
> -
> -
> Set<Interceptor<?>> setInterceptors =
> findDeployedWebBeansInterceptor(result);
> -
> -
> if(componentInterceptors != null)
> - {
> -
> setInterceptors.removeAll(componentInterceptors);
> - }
> -
> -
> Iterator<Interceptor<?>> it =
> setInterceptors.iterator();
> -
> - while
> (it.hasNext())
> + if
> (!interceptorAnns.isEmpty())
> {
> -
> WebBeansInterceptor<?> interceptor =
> (WebBeansInterceptor<?>) it.next();
> -
> -
> WebBeansUtil.configureInterceptorMethods(interceptor,
> interceptor.getClazz(), AroundInvoke.class, true, true,
> stack, method, true);
> -
> WebBeansUtil.configureInterceptorMethods(interceptor,
> interceptor.getClazz(), PostConstruct.class, true, true,
> stack, method, true);
> -
> WebBeansUtil.configureInterceptorMethods(interceptor,
> interceptor.getClazz(), PreDestroy.class, true, true, stack,
> method, true);
> +
> Annotation[] result = new
> Annotation[interceptorAnns.size()];
> +
> result = interceptorAnns.toArray(result);
> +
> +
> Set<Interceptor<?>> setInterceptors =
> findDeployedWebBeansInterceptor(result);
> +
> +
> if(componentInterceptors != null)
> + {
> +
>
> setInterceptors.removeAll(componentInterceptors);
> + }
> +
> +
> Iterator<Interceptor<?>> it =
> setInterceptors.iterator();
> +
> +
> while (it.hasNext())
> + {
> +
> WebBeansInterceptor<?> interceptor =
> (WebBeansInterceptor<?>) it.next();
> +
> +
>
> WebBeansUtil.configureInterceptorMethods(interceptor,
> interceptor.getClazz(), AroundInvoke.class, true, true,
> stack, method, true);
> +
>
> WebBeansUtil.configureInterceptorMethods(interceptor,
> interceptor.getClazz(), PostConstruct.class, true, true,
> stack, method, true);
> +
>
> WebBeansUtil.configureInterceptorMethods(interceptor,
> interceptor.getClazz(), PreDestroy.class, true, true, stack,
> method, true);
> + }
> }
> }
>
>
> Modified:
> openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java
> URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java?rev=902270&r1=902269&r2=902270&view=diff
> ==============================================================================
> ---
> openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java
> (original)
> +++
> openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java
> Fri Jan 22 21:17:31 2010
> @@ -419,17 +419,13 @@
> ManagedBean<T>
> component = null;
>
>
> ManagedBeanConfigurator.checkManagedBeanCondition(clazz);
> - {
> - // This is the
> interceptor class
> - if
> (InterceptorsManager.getInstance().isInterceptorEnabled(clazz))
> - {
> -
> InterceptorUtil.checkInterceptorConditions(clazz);
> -
> component = ManagedBeanConfigurator.define(clazz,
> WebBeansType.INTERCEPTOR);
> -
> WebBeansInterceptorConfig.configureInterceptorClass((ManagedBean<Object>)
> component,
> -
>
> AnnotationUtil.getInterceptorBindingMetaAnnotations(clazz.getDeclaredAnnotations()));
> - }
> +
> +
> InterceptorsManager.getInstance().addNewInterceptor(clazz);
> +
> InterceptorUtil.checkInterceptorConditions(clazz);
> + component =
> ManagedBeanConfigurator.define(clazz,
> WebBeansType.INTERCEPTOR);
> +
> WebBeansInterceptorConfig.configureInterceptorClass((ManagedBean<Object>)
> component,
> +
> AnnotationUtil.getInterceptorBindingMetaAnnotations(clazz.getDeclaredAnnotations()));
>
> - }
>
> return component;
> }
>
> Modified:
> openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/ComponentWithObserves2.java
> URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/ComponentWithObserves2.java?rev=902270&r1=902269&r2=902270&view=diff
> ==============================================================================
> ---
> openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/ComponentWithObserves2.java
> (original)
> +++
> openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/ComponentWithObserves2.java
> Fri Jan 22 21:17:31 2010
> @@ -1,15 +1,18 @@
> /*
> - * Licensed to the Apache Software Foundation (ASF) under
> one or more
> - * contributor license agreements. See the NOTICE file
> distributed with this
> - * work for additional information regarding copyright
> ownership. The ASF
> - * licenses this file to You 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.
> + * Licensed to the Apache Software Foundation (ASF)
> under one or more
> + * contributor license agreements. See the
> NOTICE file distributed with
> + * this work for additional information regarding
> copyright ownership.
> + * The ASF licenses this file to You 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.apache.webbeans.test.component.event.normal;
>
> @@ -28,12 +31,20 @@
>
> private String user;
>
> + /** This gets set via the
> TransactionalInterceptor */
> + public static boolean hasBeenIntercepted;
> +
> public void afterLogin(@Observes
> @Role(value = "USER") LoggedInEvent event,
> PaymentProcessorComponent payment)
> {
> + hasBeenIntercepted = false;
> this.payment =
> payment.getPaymentCheck();
> this.user =
> event.getUserName();
> }
>
> + /**
> + * Test if observer functions can
> be intercepted
> + */
> + @Transactional
> public void
> afterAdminLogin(@Observes @Role(value = "ADMIN")
> LoggedInEvent event, PaymentProcessorComponent payment)
> {
> this.payment =
> payment.getPaymentCheck();
>
> Added:
> openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/Transactional.java
> URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/Transactional.java?rev=902270&view=auto
> ==============================================================================
> ---
> openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/Transactional.java
> (added)
> +++
> openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/Transactional.java
> Fri Jan 22 21:17:31 2010
> @@ -0,0 +1,32 @@
> +/*
> + * Licensed to the Apache Software Foundation (ASF)
> under one or more
> + * contributor license agreements. See the
> NOTICE file distributed with
> + * this work for additional information regarding
> copyright ownership.
> + * The ASF licenses this file to You 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.apache.webbeans.test.component.event.normal;
> +
> +import java.lang.annotation.ElementType;
> +import java.lang.annotation.Retention;
> +import java.lang.annotation.RetentionPolicy;
> +import java.lang.annotation.Target;
> +
> +import javax.interceptor.InterceptorBinding;
> +
> +@InterceptorBinding
> +@Retention(RetentionPolicy.RUNTIME)
> +@Target( { ElementType.TYPE, ElementType.METHOD })
> +public @interface Transactional
> +{
> +
> +}
>
> Added:
> openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/TransactionalInterceptor.java
> URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/TransactionalInterceptor.java?rev=902270&view=auto
> ==============================================================================
> ---
> openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/TransactionalInterceptor.java
> (added)
> +++
> openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/TransactionalInterceptor.java
> Fri Jan 22 21:17:31 2010
> @@ -0,0 +1,43 @@
> +/*
> + * Licensed to the Apache Software Foundation (ASF)
> under one or more
> + * contributor license agreements. See the
> NOTICE file distributed with
> + * this work for additional information regarding
> copyright ownership.
> + * The ASF licenses this file to You 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.apache.webbeans.test.component.event.normal;
> +
> +import javax.interceptor.AroundInvoke;
> +import javax.interceptor.Interceptor;
> +import javax.interceptor.InvocationContext;
> +
> +@Interceptor
> +@Transactional
> +public class TransactionalInterceptor
> +{
> +
> + @AroundInvoke
> + public Object caller(InvocationContext
> context) throws Exception
> + {
> + try
> + {
> +
> ComponentWithObserves2.hasBeenIntercepted = true;
> + return
> context.proceed();
> +
> + }catch(Exception e)
> + {
> +
> ComponentWithObserves2.hasBeenIntercepted = false;
> + }
> +
> + return null;
> + }
> +}
>
> Modified:
> openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/event/component/ObserversComponentTest.java
> URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/event/component/ObserversComponentTest.java?rev=902270&r1=902269&r2=902270&view=diff
> ==============================================================================
> ---
> openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/event/component/ObserversComponentTest.java
> (original)
> +++
> openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/event/component/ObserversComponentTest.java
> Fri Jan 22 21:17:31 2010
> @@ -1,15 +1,18 @@
> /*
> - * Licensed to the Apache Software Foundation (ASF) under
> one or more
> - * contributor license agreements. See the NOTICE file
> distributed with this
> - * work for additional information regarding copyright
> ownership. The ASF
> - * licenses this file to You 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.
> + * Licensed to the Apache Software Foundation (ASF)
> under one or more
> + * contributor license agreements. See the
> NOTICE file distributed with
> + * this work for additional information regarding
> copyright ownership.
> + * The ASF licenses this file to You 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.apache.webbeans.test.unittests.event.component;
>
> @@ -31,6 +34,7 @@
> import
> org.apache.webbeans.test.component.event.normal.ComponentWithObservable1;
> import
> org.apache.webbeans.test.component.event.normal.ComponentWithObserves1;
> import
> org.apache.webbeans.test.component.event.normal.ComponentWithObserves2;
> +import
> org.apache.webbeans.test.component.event.normal.TransactionalInterceptor;
> import org.apache.webbeans.test.event.LoggedInEvent;
> import org.apache.webbeans.util.WebBeansUtil;
> import org.junit.Before;
> @@ -152,6 +156,7 @@
> {
> clear();
>
> +
> defineInterceptor(TransactionalInterceptor.class);
>
> defineManagedBean(CheckWithCheckPayment.class);
>
> defineManagedBean(CheckWithMoneyPayment.class);
>
> defineManagedBean(PaymentProcessorComponent.class);
> @@ -180,21 +185,35 @@
>
> }
>
> +
> ComponentWithObserves2.hasBeenIntercepted = false;
> +
> Annotation[] anns =
> new Annotation[1];
> anns[0] = new
> RoleUser();
>
>
> getManager().fireEvent(event, anns);
>
> ComponentWithObserves2 instance =
> getManager().getInstance(component);
>
> +
> Assert.assertFalse(ComponentWithObserves2.hasBeenIntercepted);
> +
>
> Assert.assertNotNull(instance.getPayment());
>
> Assert.assertEquals("USER",
> instance.getUser());
>
> anns[0] = new
> RoleAdmin();
> event = new
> LoggedInEvent("ADMIN");
> +
> + getManager().fireEvent(event,
> anns);
> + instance =
> getManager().getInstance(component);
> +
> +
> Assert.assertTrue(ComponentWithObserves2.hasBeenIntercepted);
> +
> Assert.assertNotNull(instance.getPayment());
> + Assert.assertEquals("ADMIN",
> instance.getUser());
>
> + // lessons learned: do it
> again sam! ;)
> +
> ComponentWithObserves2.hasBeenIntercepted = false;
>
> getManager().fireEvent(event, anns);
> instance =
> getManager().getInstance(component);
>
> +
> Assert.assertTrue(ComponentWithObserves2.hasBeenIntercepted);
>
> Assert.assertNotNull(instance.getPayment());
>
> Assert.assertEquals("ADMIN",
> instance.getUser());
>
>
>
>