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/04/07 19:24:24 UTC
svn commit: r931623 - in
/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans:
component/ intercept/ util/
Author: struberg
Date: Wed Apr 7 17:24:23 2010
New Revision: 931623
URL: http://svn.apache.org/viewvc?rev=931623&view=rev
Log:
OWB-344 move interceptor related utils into intercept package
Added:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorRuntimeSupport.java
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractInjectionTargetBean.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorData.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorUtil.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractInjectionTargetBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractInjectionTargetBean.java?rev=931623&r1=931622&r2=931623&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractInjectionTargetBean.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractInjectionTargetBean.java Wed Apr 7 17:24:23 2010
@@ -42,6 +42,7 @@ import org.apache.webbeans.inject.Inject
import org.apache.webbeans.inject.OWBInjector;
import org.apache.webbeans.intercept.InterceptorData;
import org.apache.webbeans.intercept.InterceptorType;
+import org.apache.webbeans.intercept.InterceptorUtil;
import org.apache.webbeans.intercept.InvocationContextImpl;
import org.apache.webbeans.intercept.webbeans.WebBeansInterceptor;
import org.apache.webbeans.logger.WebBeansLogger;
@@ -245,7 +246,7 @@ public abstract class AbstractInjectionT
// Call Post Construct
if (WebBeansUtil.isContainsInterceptorMethod(getInterceptorStack(), InterceptorType.POST_CONSTRUCT))
{
- InvocationContextImpl impl = new InvocationContextImpl(null, instance, null, null, WebBeansUtil.getInterceptorMethods(getInterceptorStack(), InterceptorType.POST_CONSTRUCT), InterceptorType.POST_CONSTRUCT);
+ InvocationContextImpl impl = new InvocationContextImpl(null, instance, null, null, InterceptorUtil.getInterceptorMethods(getInterceptorStack(), InterceptorType.POST_CONSTRUCT), InterceptorType.POST_CONSTRUCT);
impl.setCreationalContext(ownerCreationalContext);
try
{
@@ -281,7 +282,7 @@ public abstract class AbstractInjectionT
{
if (WebBeansUtil.isContainsInterceptorMethod(getInterceptorStack(), InterceptorType.PRE_DESTROY))
{
- InvocationContextImpl impl = new InvocationContextImpl(null, instance, null, null, WebBeansUtil.getInterceptorMethods(getInterceptorStack(), InterceptorType.PRE_DESTROY), InterceptorType.PRE_DESTROY);
+ InvocationContextImpl impl = new InvocationContextImpl(null, instance, null, null, InterceptorUtil.getInterceptorMethods(getInterceptorStack(), InterceptorType.PRE_DESTROY), InterceptorType.PRE_DESTROY);
impl.setCreationalContext(creationalContext);
try
{
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorData.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorData.java?rev=931623&r1=931622&r2=931623&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorData.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorData.java Wed Apr 7 17:24:23 2010
@@ -54,7 +54,7 @@ public interface InterceptorData
public Method getPostConstruct();
/**
- * Gets the list of {@link PreDestroy} annotated method
+ * Gets the {@link PreDestroy} annotated method
* if exist, returns null otherwise.
* @return pre-destroy method
*/
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java?rev=931623&r1=931622&r2=931623&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java Wed Apr 7 17:24:23 2010
@@ -245,7 +245,7 @@ public abstract class InterceptorHandler
// Call Around Invokes
if (WebBeansUtil.isContainsInterceptorMethod(this.interceptedMethodMap.get(method), InterceptorType.AROUND_INVOKE))
{
- return callAroundInvokes(method, arguments, WebBeansUtil.getInterceptorMethods(this.interceptedMethodMap.get(method), InterceptorType.AROUND_INVOKE));
+ return callAroundInvokes(method, arguments, InterceptorUtil.getInterceptorMethods(this.interceptedMethodMap.get(method), InterceptorType.AROUND_INVOKE));
}
}
Added: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorRuntimeSupport.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorRuntimeSupport.java?rev=931623&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorRuntimeSupport.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorRuntimeSupport.java Wed Apr 7 17:24:23 2010
@@ -0,0 +1,77 @@
+/*
+ * 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.intercept;
+
+import java.util.List;
+
+import org.apache.webbeans.component.AbstractInjectionTargetBean;
+import org.apache.webbeans.component.OwbBean;
+
+/**
+ * <p>This class contains a set of static helper functions
+ * for creating interceptor subclasses of beans and
+ * evaluating and performing interceptor handling for those
+ * contextual instances at runtime</p>
+ *
+ * <p>For each {@link OwbBean<T>} which is either decorated with a
+ * {@link javax.enterprise.inject.spi.Decorator} or intercepted
+ * by a {@link javax.enterprise.inject.spi.Interceptor} we
+ * dynamically create a subclass and use bytecode creation to
+ * override intercepted functions to first delegate to all
+ * registered {@link InterceptorHandler}s.</p>
+ */
+public class InterceptorRuntimeSupport {
+
+ /**
+ * <p>Create a interceptor/decorator subclass for the given bean.</p>
+ *
+ * <p>This will first check if we really need to apply subclassing and
+ * if not will return <code>null</code> instead. We need subclassing
+ * if the bean contains any {@link InterceptorType.AROUND_INVOKE}
+ * or if there are any Decoraors</p>
+ *
+ *
+ * @param <T>
+ * @param bean
+ * @return the interceptor subclass or <code>null</code> if there is no need to.
+ */
+ public static final <T> Class<? extends T> getInterceptorSubClass(OwbBean<T> bean)
+ {
+ if (!(bean instanceof AbstractInjectionTargetBean<?>))
+ {
+ // we can only apply interceptors and decorators to AbstractInjectionTargetBeans
+ return null;
+ }
+
+ AbstractInjectionTargetBean<T> interceptableBean = (AbstractInjectionTargetBean<T>) bean;
+
+ List<InterceptorData> interceptorStack = interceptableBean.getInterceptorStack();
+
+ // we only subclass
+ List<InterceptorData> aroundInvokes = InterceptorUtil.getInterceptorMethods(interceptorStack, InterceptorType.AROUND_INVOKE);
+
+ if (aroundInvokes == null || aroundInvokes.size() == 0)
+ {
+ return null;
+ }
+
+ //X TODO continue
+ return null;
+ }
+}
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorUtil.java?rev=931623&r1=931622&r2=931623&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorUtil.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorUtil.java Wed Apr 7 17:24:23 2010
@@ -18,6 +18,8 @@ import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
import java.lang.reflect.Method;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
import java.util.List;
import java.util.Set;
@@ -395,4 +397,71 @@ public final class InterceptorUtil
}
+ /**
+ * Gets list of interceptors with the given type.
+ *
+ * @param stack interceptor stack
+ * @param type interceptor type
+ * @return list of interceptor
+ */
+
+ public static List<InterceptorData> getInterceptorMethods(List<InterceptorData> stack, InterceptorType type)
+ {
+ List<InterceptorData> ai = new ArrayList<InterceptorData>();
+ List<InterceptorData> pc = new ArrayList<InterceptorData>();
+ List<InterceptorData> pd = new ArrayList<InterceptorData>();
+
+ Iterator<InterceptorData> it = stack.iterator();
+ while (it.hasNext())
+ {
+ Method m = null;
+ InterceptorData data = it.next();
+
+ if (type.equals(InterceptorType.AROUND_INVOKE))
+ {
+ m = data.getAroundInvoke();
+ if (m != null)
+ {
+ ai.add(data);
+ }
+
+ }
+ else if (type.equals(InterceptorType.POST_CONSTRUCT))
+ {
+ m = data.getPostConstruct();
+ if (m != null)
+ {
+ pc.add(data);
+ }
+
+ }
+ else if (type.equals(InterceptorType.PRE_DESTROY))
+ {
+ m = data.getPreDestroy();
+ if (m != null)
+ {
+ pd.add(data);
+ }
+
+ }
+
+ }
+
+ if (type.equals(InterceptorType.AROUND_INVOKE))
+ {
+ return ai;
+ }
+ else if (type.equals(InterceptorType.POST_CONSTRUCT))
+ {
+ return pc;
+
+ }
+ else if (type.equals(InterceptorType.PRE_DESTROY))
+ {
+ return pd;
+ }
+
+ return Collections.EMPTY_LIST;
+ }
+
}
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java?rev=931623&r1=931622&r2=931623&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java Wed Apr 7 17:24:23 2010
@@ -30,7 +30,6 @@ import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -1300,73 +1299,6 @@ public final class WebBeansUtil
}
/**
- * Gets list of interceptors with the given type.
- *
- * @param stack interceptor stack
- * @param type interceptor type
- * @return list of interceptor
- */
-
- public static List<InterceptorData> getInterceptorMethods(List<InterceptorData> stack, InterceptorType type)
- {
- List<InterceptorData> ai = new ArrayList<InterceptorData>();
- List<InterceptorData> pc = new ArrayList<InterceptorData>();
- List<InterceptorData> pd = new ArrayList<InterceptorData>();
-
- Iterator<InterceptorData> it = stack.iterator();
- while (it.hasNext())
- {
- Method m = null;
- InterceptorData data = it.next();
-
- if (type.equals(InterceptorType.AROUND_INVOKE))
- {
- m = data.getAroundInvoke();
- if (m != null)
- {
- ai.add(data);
- }
-
- }
- else if (type.equals(InterceptorType.POST_CONSTRUCT))
- {
- m = data.getPostConstruct();
- if (m != null)
- {
- pc.add(data);
- }
-
- }
- else if (type.equals(InterceptorType.PRE_DESTROY))
- {
- m = data.getPreDestroy();
- if (m != null)
- {
- pd.add(data);
- }
-
- }
-
- }
-
- if (type.equals(InterceptorType.AROUND_INVOKE))
- {
- return ai;
- }
- else if (type.equals(InterceptorType.POST_CONSTRUCT))
- {
- return pc;
-
- }
- else if (type.equals(InterceptorType.PRE_DESTROY))
- {
- return pd;
- }
-
- return Collections.EMPTY_LIST;
- }
-
- /**
* Returns true if array contains the StereoType meta annotation
*
* @param anns annotation array