You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by ad...@apache.org on 2012/02/20 20:59:23 UTC
svn commit: r1291425 -
/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiPlugin.java
Author: adc
Date: Mon Feb 20 19:59:23 2012
New Revision: 1291425
URL: http://svn.apache.org/viewvc?rev=1291425&view=rev
Log:
Trivial cleanup.
Modified:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiPlugin.java
Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiPlugin.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiPlugin.java?rev=1291425&r1=1291424&r2=1291425&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiPlugin.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiPlugin.java Mon Feb 20 19:59:23 2012
@@ -16,19 +16,20 @@
*/
package org.apache.openejb.cdi;
-import org.apache.openejb.AppContext;
-import org.apache.openejb.BeanContext;
-import org.apache.openejb.OpenEJBException;
-import org.apache.openejb.assembler.classic.ProxyInterfaceResolver;
-import org.apache.openejb.core.CoreUserTransaction;
-import org.apache.openejb.loader.SystemInstance;
-import org.apache.openejb.spi.ContainerSystem;
-import org.apache.openejb.util.LogCategory;
-import org.apache.openejb.util.Logger;
+import java.lang.reflect.Method;
+import java.util.List;
+import java.util.Set;
+import java.util.WeakHashMap;
+import javax.ejb.Stateful;
+import javax.enterprise.context.spi.Context;
+import javax.enterprise.context.spi.Contextual;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.ProcessAnnotatedType;
+
import org.apache.webbeans.config.WebBeansContext;
import org.apache.webbeans.config.WebBeansFinder;
import org.apache.webbeans.container.InjectionResolver;
-import org.apache.webbeans.ee.event.TransactionalEventNotifier;
import org.apache.webbeans.portable.events.discovery.BeforeShutdownImpl;
import org.apache.webbeans.spi.ResourceInjectionService;
import org.apache.webbeans.spi.SecurityService;
@@ -38,132 +39,112 @@ import org.apache.webbeans.spi.plugins.O
import org.apache.webbeans.spi.plugins.OpenWebBeansJavaEEPlugin;
import org.apache.webbeans.util.WebBeansUtil;
-import javax.ejb.Stateful;
-import javax.enterprise.context.spi.Context;
-import javax.enterprise.context.spi.Contextual;
-import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.event.TransactionPhase;
-import javax.enterprise.inject.spi.Bean;
-import javax.enterprise.inject.spi.ObserverMethod;
-import javax.enterprise.inject.spi.ProcessAnnotatedType;
-import javax.naming.NamingException;
-import javax.transaction.SystemException;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-import javax.transaction.UserTransaction;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.AccessibleObject;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.security.Principal;
-import java.security.PrivilegedActionException;
-import java.util.List;
-import java.util.Properties;
-import java.util.Set;
-import java.util.WeakHashMap;
+import org.apache.openejb.AppContext;
+import org.apache.openejb.BeanContext;
+import org.apache.openejb.OpenEJBException;
+
public class CdiPlugin extends AbstractOwbPlugin implements OpenWebBeansJavaEEPlugin, OpenWebBeansEjbPlugin {
- private AppContext appContext;
+ private AppContext appContext;
private Set<Class<?>> beans;
- private WebBeansContext webBeansContext;
- private CdiAppContextsService contexsServices;
+ private WebBeansContext webBeansContext;
+ private CdiAppContextsService contexsServices;
+
+ @Override
+ public void shutDown() {
+ super.shutDown();
+ // this plugin may have been installed in a non-ejb lifecycle???
+ if (beans != null) {
+ this.beans.clear();
+ }
+ }
+
+ public void setAppContext(AppContext appContext) {
+ this.appContext = appContext;
+ }
+
+ public void configureDeployments(List<BeanContext> ejbDeployments) {
+ WeakHashMap<Class<?>, Object> beans = new WeakHashMap<Class<?>, Object>();
+ for (BeanContext deployment : ejbDeployments) {
+ if (deployment.getComponentType().isSession()) {
+ beans.put(deployment.getBeanClass(), null);
+ }
+ }
+ this.beans = beans.keySet();
+ }
+
+ public CdiAppContextsService getContexsServices() {
+ return contexsServices;
+ }
- @Override
- public void shutDown() {
- super.shutDown();
- // this plugin may have been installed in a non-ejb lifecycle???
- if (beans != null) {
- this.beans.clear();
- }
- }
-
- public void setAppContext(AppContext appContext) {
- this.appContext = appContext;
- }
-
- public void configureDeployments(List<BeanContext> ejbDeployments) {
- WeakHashMap<Class<?>, Object> beans = new WeakHashMap<Class<?>, Object>();
- for (BeanContext deployment : ejbDeployments) {
- if (deployment.getComponentType().isSession()) {
- beans.put(deployment.getBeanClass(), null);
- }
- }
- this.beans = beans.keySet();
- }
-
- public CdiAppContextsService getContexsServices() {
- return contexsServices;
- }
-
- public void startup() {
- webBeansContext = appContext.getWebBeansContext();
- this.contexsServices = (CdiAppContextsService) webBeansContext.getContextsService();
- this.contexsServices.init(null);
- }
-
- public void stop() throws OpenEJBException {
- ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
- try {
- // Setting context class loader for cleaning
- Thread.currentThread().setContextClassLoader(appContext.getClassLoader());
+ public void startup() {
+ webBeansContext = appContext.getWebBeansContext();
+ this.contexsServices = (CdiAppContextsService) webBeansContext.getContextsService();
+ this.contexsServices.init(null);
+ }
- // Fire shut down
- appContext.getBeanManager().fireEvent(new BeforeShutdownImpl(), new Annotation[0]);
+ public void stop() throws OpenEJBException {
+ ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
+ try {
+ // Setting context class loader for cleaning
+ Thread.currentThread().setContextClassLoader(appContext.getClassLoader());
+
+ // Fire shut down
+ appContext.getBeanManager().fireEvent(new BeforeShutdownImpl());
- // Destroys context
- this.contexsServices.destroy(null);
+ // Destroys context
+ this.contexsServices.destroy(null);
- // Free all plugin resources
+ // Free all plugin resources
webBeansContext.getPluginLoader().shutDown();
- // Clear extensions
- webBeansContext.getExtensionLoader().clear();
+ // Clear extensions
+ webBeansContext.getExtensionLoader().clear();
+
+ // Delete Resolutions Cache
+ InjectionResolver.getInstance().clearCaches();
+
+ // Delte proxies
+ webBeansContext.getJavassistProxyFactory().clear();
- // Delete Resolutions Cache
- InjectionResolver.getInstance().clearCaches();
+ // Delete AnnotateTypeCache
+ webBeansContext.getAnnotatedElementFactory().clear();
+
+ // JMs Manager clear
+ webBeansContext.getjMSManager().clear();
+
+ // Clear the resource injection service
+ CdiResourceInjectionService injectionServices = (CdiResourceInjectionService) webBeansContext.getService(ResourceInjectionService.class);
+ injectionServices.clear();
+
+ // Clear singleton list
+ WebBeansFinder.clearInstances(WebBeansUtil.getCurrentClassLoader());
+
+ } catch (Exception e) {
+ throw new OpenEJBException(e);
+ } finally {
+ Thread.currentThread().setContextClassLoader(oldCl);
+ }
+ }
+
+ @Override
+ public <T> T getSupportedService(Class<T> serviceClass) {
+ return supportService(serviceClass) ? serviceClass.cast(this) : null;
+ }
- // Delte proxies
- webBeansContext.getJavassistProxyFactory().clear();
+ @Override
+ public void isManagedBean(Class<?> clazz) {
+ }
- // Delete AnnotateTypeCache
- webBeansContext.getAnnotatedElementFactory().clear();
-
- // JMs Manager clear
- webBeansContext.getjMSManager().clear();
-
- // Clear the resource injection service
- CdiResourceInjectionService injectionServices = (CdiResourceInjectionService) webBeansContext.getService(ResourceInjectionService.class);
- injectionServices.clear();
-
- // Clear singleton list
- WebBeansFinder.clearInstances(WebBeansUtil.getCurrentClassLoader());
-
- } catch (Exception e) {
- throw new OpenEJBException(e);
- } finally {
- Thread.currentThread().setContextClassLoader(oldCl);
- }
- }
-
- @Override
- public <T> T getSupportedService(Class<T> serviceClass) {
- return supportService(serviceClass) ? serviceClass.cast(this) : null;
- }
-
- @Override
- public void isManagedBean(Class<?> clazz) {
- }
-
- @Override
- public boolean supportService(Class<?> serviceClass) {
- return serviceClass == TransactionService.class || serviceClass == SecurityService.class;
- }
+ @Override
+ public boolean supportService(Class<?> serviceClass) {
+ return serviceClass == TransactionService.class || serviceClass == SecurityService.class;
+ }
- @Override
- public Object getSessionBeanProxy(Bean<?> bean, Class<?> interfce, CreationalContext<?> creationalContext) {
+ @Override
+ public Object getSessionBeanProxy(Bean<?> bean, Class<?> interfce, CreationalContext<?> creationalContext) {
final Context context = webBeansContext.getBeanManagerImpl().getContext(bean.getScope());
@@ -172,38 +153,37 @@ public class CdiPlugin extends AbstractO
return context.get(component, cc);
- }
+ }
+
+ @Override
+ public boolean isSessionBean(Class<?> clazz) {
+ // this may be called from a web app without ejbs in which case beans will not have been initialized by openejb.
+ return beans != null && beans.contains(clazz);
+ }
+
+ @Override
+ public <T> Bean<T> defineSessionBean(Class<T> clazz, ProcessAnnotatedType<T> processAnnotateTypeEvent) {
+ throw new IllegalStateException("Statement should never be reached");
+ }
- @Override
- public boolean isSessionBean(Class<?> clazz) {
- // this may be called from a web app without ejbs in which case beans will not have been initialized by openejb.
- return beans != null && beans.contains(clazz);
- }
-
- @Override
- public <T> Bean<T> defineSessionBean(Class<T> clazz, ProcessAnnotatedType<T> processAnnotateTypeEvent) {
- throw new IllegalStateException("Statement should never be reached");
- }
-
- @Override
- public boolean isSingletonBean(Class<?> clazz) {
- throw new IllegalStateException("Statement should never be reached");
- }
+ @Override
+ public boolean isSingletonBean(Class<?> clazz) {
+ throw new IllegalStateException("Statement should never be reached");
+ }
- @Override
- public boolean isStatefulBean(Class<?> clazz) {
+ @Override
+ public boolean isStatefulBean(Class<?> clazz) {
// TODO Make the EjbPlugin pass in the Bean<T> instance
- return clazz.isAnnotationPresent(Stateful.class);
- }
+ return clazz.isAnnotationPresent(Stateful.class);
+ }
- @Override
- public boolean isStatelessBean(Class<?> clazz) {
- throw new IllegalStateException("Statement should never be reached");
- }
+ @Override
+ public boolean isStatelessBean(Class<?> clazz) {
+ throw new IllegalStateException("Statement should never be reached");
+ }
@Override
public Method resolveViewMethod(Bean<?> component, Method declaredMethod) {
-// if (true)return declaredMethod;
if (!(component instanceof CdiEjbBean)) return declaredMethod;
CdiEjbBean cdiEjbBean = (CdiEjbBean) component;
@@ -213,7 +193,7 @@ public class CdiPlugin extends AbstractO
for (Class intface : beanContext.getBusinessLocalInterfaces()) {
try {
return intface.getMethod(declaredMethod.getName(), declaredMethod.getParameterTypes());
- } catch (NoSuchMethodException e) {
+ } catch (NoSuchMethodException ignore) {
}
}
return declaredMethod;