You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by ge...@apache.org on 2010/04/10 16:16:45 UTC
svn commit: r932727 - in
/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans:
context/ inject/ intercept/ proxy/
Author: gerdogdu
Date: Sat Apr 10 14:16:44 2010
New Revision: 932727
URL: http://svn.apache.org/viewvc?rev=932727&view=rev
Log:
Adding several methods to ContextsService and some updating
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/AbstractContextsService.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ContextFactory.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/OWBInjector.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorDataImpl.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/proxy/JavassistProxyFactory.java
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/AbstractContextsService.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/AbstractContextsService.java?rev=932727&r1=932726&r2=932727&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/AbstractContextsService.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/AbstractContextsService.java Sat Apr 10 14:16:44 2010
@@ -64,5 +64,31 @@ public abstract class AbstractContextsSe
{
return false;
}
-
+
+ @Override
+ public void activateContext(Class<? extends Annotation> scopeType)
+ {
+ if(supportsContext(scopeType))
+ {
+ Context context = getCurrentContext(scopeType);
+ if(context instanceof AbstractContext)
+ {
+ ((AbstractContext)context).setActive(true);
+ }
+ }
+ }
+
+ @Override
+ public void deActivateContext(Class<? extends Annotation> scopeType)
+ {
+ if(supportsContext(scopeType))
+ {
+ Context context = getCurrentContext(scopeType);
+ if(context instanceof AbstractContext)
+ {
+ ((AbstractContext)context).setActive(false);
+ }
+ }
+ }
+
}
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ContextFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ContextFactory.java?rev=932727&r1=932726&r2=932727&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ContextFactory.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ContextFactory.java Sat Apr 10 14:16:44 2010
@@ -92,13 +92,13 @@ public final class ContextFactory
/**
* Creates the application context at the application startup
*
- * @param servletContext servlet context object
+ * @param parameter parameter object
*/
- public static void initApplicationContext(Object servletContext)
+ public static void initApplicationContext(Object parameter)
{
try
{
- contextService.startContext(ApplicationScoped.class, servletContext);
+ contextService.startContext(ApplicationScoped.class, parameter);
}
catch (Exception e)
{
@@ -110,18 +110,18 @@ public final class ContextFactory
* Destroys the application context and all of its components at the end of
* the application.
*
- * @param servletContext servlet context object
+ * @param parameter parameter object
*/
- public static void destroyApplicationContext(Object servletContext)
+ public static void destroyApplicationContext(Object parameter)
{
- contextService.endContext(ApplicationScoped.class, servletContext);
+ contextService.endContext(ApplicationScoped.class, parameter);
}
- public static void initSingletonContext(Object servletContext)
+ public static void initSingletonContext(Object parameter)
{
try
{
- contextService.startContext(Singleton.class, servletContext);
+ contextService.startContext(Singleton.class, parameter);
}
catch (Exception e)
{
@@ -129,9 +129,9 @@ public final class ContextFactory
}
}
- public static void destroySingletonContext(Object servletContext)
+ public static void destroySingletonContext(Object parameter)
{
- contextService.endContext(Singleton.class, servletContext);
+ contextService.endContext(Singleton.class, parameter);
}
public static void initConversationContext(Object context)
@@ -232,4 +232,21 @@ public final class ContextFactory
return context;
}
+
+ /**
+ * Activate context.
+ */
+ public static void activateContext(Class<? extends Annotation> scopeType)
+ {
+ contextService.activateContext(scopeType);
+ }
+
+ /**
+ * Deactivate context.
+ */
+ public static void deActivateContext(Class<? extends Annotation> scopeType)
+ {
+ contextService.deActivateContext(scopeType);
+ }
+
}
\ No newline at end of file
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/OWBInjector.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/OWBInjector.java?rev=932727&r1=932726&r2=932727&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/OWBInjector.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/OWBInjector.java Sat Apr 10 14:16:44 2010
@@ -23,6 +23,7 @@ import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Set;
+import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.InjectionPoint;
@@ -59,9 +60,14 @@ public final class OWBInjector
}
}
- @SuppressWarnings("unchecked")
public OWBInjector inject(Object javaEeComponentInstance) throws Exception
{
+ return inject(javaEeComponentInstance,null);
+ }
+
+ @SuppressWarnings("unchecked")
+ public OWBInjector inject(Object javaEeComponentInstance, CreationalContext<?> creationalContext) throws Exception
+ {
BeanManager beanManager = BeanManagerImpl.getManager();
try
{
@@ -71,7 +77,10 @@ public final class OWBInjector
Set<InjectionPoint> injectionPoints = injectionTarget.getInjectionPoints();
if(injectionPoints != null && injectionPoints.size() > 0)
{
- this.ownerCreationalContext = (CreationalContextImpl<?>) beanManager.createCreationalContext(null);
+ if(creationalContext == null)
+ {
+ this.ownerCreationalContext = (CreationalContextImpl<?>) beanManager.createCreationalContext(null);
+ }
for(InjectionPoint injectionPoint : injectionPoints)
{
@@ -100,6 +109,7 @@ public final class OWBInjector
return null;
}
+
public static boolean checkInjectionPointForInterceptorPassivation(Class<?> clazz)
{
Asserts.nullCheckForClass(clazz);
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorDataImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorDataImpl.java?rev=932727&r1=932726&r2=932727&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorDataImpl.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorDataImpl.java Sat Apr 10 14:16:44 2010
@@ -120,7 +120,7 @@ public class InterceptorDataImpl impleme
* org.apache.webbeans.intercept.InterceptorData#addAroundInvoke(java.lang
* .reflect.Method)
*/
- protected void setAroundInvoke(Method m)
+ public void setAroundInvoke(Method m)
{
this.aroundInvoke = m;
}
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=932727&r1=932726&r2=932727&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 Sat Apr 10 14:16:44 2010
@@ -20,7 +20,6 @@ import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
@@ -29,8 +28,6 @@ import javassist.util.proxy.MethodHandle
import javassist.util.proxy.ProxyFactory;
import javassist.util.proxy.ProxyObject;
-import javax.interceptor.ExcludeClassInterceptors;
-
import org.apache.webbeans.component.AbstractOwbBean;
import org.apache.webbeans.component.InjectionTargetBean;
import org.apache.webbeans.component.OwbBean;
@@ -46,7 +43,6 @@ import org.apache.webbeans.intercept.ejb
import org.apache.webbeans.intercept.webbeans.WebBeansInterceptor;
import org.apache.webbeans.logger.WebBeansLogger;
import org.apache.webbeans.proxy.JavassistProxyFactory;
-import org.apache.webbeans.util.AnnotationUtil;
import org.apache.webbeans.util.ClassUtil;
import org.apache.webbeans.util.WebBeansUtil;
@@ -225,7 +221,7 @@ public abstract class InterceptorHandler
List<InterceptorData> filteredInterceptorStack = new ArrayList<InterceptorData>(interceptorStack);
// Filter both EJB and WebBeans interceptors
- filterCommonInterceptorStackList(filteredInterceptorStack, method, ownerCreationalContext);
+ InterceptorUtil.filterCommonInterceptorStackList(filteredInterceptorStack, method, ownerCreationalContext);
// If there are both interceptors and decorators, add hook
// point to the end of the interceptor stack.
@@ -310,62 +306,7 @@ public abstract class InterceptorHandler
{
return BeanManagerImpl.getManager();
}
-
-
- /**
- * Returns true if this interceptor data is not related
- * false othwewise.
- * @param id interceptor data
- * @param method called method
- * @return true if this interceptor data is not related
- */
- private boolean shouldRemoveInterceptorCommon(InterceptorData id, Method method)
- {
- boolean isMethodAnnotatedWithExcludeInterceptorClass = false;
- if (AnnotationUtil.hasMethodAnnotation(method, ExcludeClassInterceptors.class))
- {
- isMethodAnnotatedWithExcludeInterceptorClass = true;
- }
-
- if (isMethodAnnotatedWithExcludeInterceptorClass)
- {
- // If the interceptor is defined at the class level it should be
- // removed due to ExcludeClassInterceptors method annotation
- if (!id.isDefinedInMethod() && id.isDefinedInInterceptorClass())
- {
- return true;
- }
- }
-
- // If the interceptor is defined in a different method, remove it
- if (id.isDefinedInMethod() && !id.getInterceptorBindingMethod().equals(method))
- {
- return true;
- }
-
- return false;
- }
-
- /**
- * Filter bean interceptor stack.
- * @param stack interceptor stack
- * @param method called method on proxy
- * @param ownerCreationalContext bean creational context
- */
- private void filterCommonInterceptorStackList(List<InterceptorData> stack, Method method, CreationalContextImpl<?> ownerCreationalContext)
- {
- Iterator<InterceptorData> it = stack.iterator();
- while (it.hasNext())
- {
- InterceptorData data = it.next();
-
- if (shouldRemoveInterceptorCommon(data, method))
- {
- it.remove();
- }
- }
- }
-
+
/**
* Write to stream.
* @param s stream
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=932727&r1=932726&r2=932727&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 Sat Apr 10 14:16:44 2010
@@ -35,8 +35,11 @@ import javax.enterprise.inject.spi.Inter
import javax.inject.Inject;
import javax.interceptor.AroundInvoke;
import javax.interceptor.AroundTimeout;
+import javax.interceptor.ExcludeClassInterceptors;
import javax.interceptor.InvocationContext;
+import org.apache.webbeans.component.InjectionTargetBean;
+import org.apache.webbeans.context.creational.CreationalContextImpl;
import org.apache.webbeans.exception.WebBeansConfigurationException;
import org.apache.webbeans.exception.WebBeansException;
import org.apache.webbeans.util.AnnotationUtil;
@@ -404,7 +407,7 @@ public final class InterceptorUtil
* @param type interceptor type
* @return list of interceptor
*/
-
+ @SuppressWarnings("unchecked")
public static List<InterceptorData> getInterceptorMethods(List<InterceptorData> stack, InterceptorType type)
{
List<InterceptorData> ai = new ArrayList<InterceptorData>();
@@ -463,5 +466,70 @@ public final class InterceptorUtil
return Collections.EMPTY_LIST;
}
+
+ /**
+ * Returns true if this interceptor data is not related
+ * false othwewise.
+ * @param id interceptor data
+ * @param method called method
+ * @return true if this interceptor data is not related
+ */
+ private static boolean shouldRemoveInterceptorCommon(InterceptorData id, Method method)
+ {
+ boolean isMethodAnnotatedWithExcludeInterceptorClass = false;
+ if (AnnotationUtil.hasMethodAnnotation(method, ExcludeClassInterceptors.class))
+ {
+ isMethodAnnotatedWithExcludeInterceptorClass = true;
+ }
+
+ if (isMethodAnnotatedWithExcludeInterceptorClass)
+ {
+ // If the interceptor is defined at the class level it should be
+ // removed due to ExcludeClassInterceptors method annotation
+ if (!id.isDefinedInMethod() && id.isDefinedInInterceptorClass())
+ {
+ return true;
+ }
+ }
+
+ // If the interceptor is defined in a different method, remove it
+ if (id.isDefinedInMethod() && !id.getInterceptorBindingMethod().equals(method))
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Filter bean interceptor stack.
+ * @param stack interceptor stack
+ * @param method called method on proxy
+ * @param ownerCreationalContext bean creational context
+ */
+ public static void filterCommonInterceptorStackList(List<InterceptorData> stack, Method method, CreationalContextImpl<?> ownerCreationalContext)
+ {
+ Iterator<InterceptorData> it = stack.iterator();
+ while (it.hasNext())
+ {
+ InterceptorData data = it.next();
+
+ if (shouldRemoveInterceptorCommon(data, method))
+ {
+ it.remove();
+ }
+ }
+ }
+
+ public static Object callAroundInvokes(InjectionTargetBean<?> bean,Object instance, CreationalContextImpl<?> creationalContext,
+ Method proceed, Object[] arguments, List<InterceptorData> stack) throws Exception
+ {
+ InvocationContextImpl impl = new InvocationContextImpl(bean, instance,
+ proceed, arguments, stack, InterceptorType.AROUND_INVOKE);
+ impl.setCreationalContext(creationalContext);
+
+ return impl.proceed();
+
+ }
}
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/JavassistProxyFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/JavassistProxyFactory.java?rev=932727&r1=932726&r2=932727&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/JavassistProxyFactory.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/JavassistProxyFactory.java Sat Apr 10 14:16:44 2010
@@ -56,6 +56,8 @@ public final class JavassistProxyFactory
private static Map<OwbBean<?>, Class<?>> interceptorProxyClasses = new ConcurrentHashMap<OwbBean<?>, Class<?>>();
+ private static Map<OwbBean<?>, Class<?>> ejbProxyClasses = new ConcurrentHashMap<OwbBean<?>, Class<?>>();
+
public static Map<OwbBean<?>, Class<?>> getInterceptorProxyClasses()
{
return interceptorProxyClasses;
@@ -66,6 +68,28 @@ public final class JavassistProxyFactory
normalScopedBeanProxyClasses.clear();
dependentScopedBeanProxyClasses.clear();
interceptorProxyClasses.clear();
+ ejbProxyClasses.clear();
+ }
+
+ public static Class<?> getEjbBeanProxyClass(OwbBean<?> bean)
+ {
+ return ejbProxyClasses.get(bean);
+ }
+
+ public static Class<?> defineEjbBeanProxyClass(OwbBean<?> bean, ProxyFactory factory)
+ {
+ Class<?> clazz = ejbProxyClasses.get(bean);
+ if(clazz != null)
+ {
+ return clazz;
+ }
+ else
+ {
+ clazz = factory.createClass();
+ ejbProxyClasses.put(bean, clazz);
+ }
+
+ return clazz;
}
public static Object createNormalScopedBeanProxy(OwbBean<?> bean, CreationalContext<?> creationalContext)