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 2009/07/15 21:46:35 UTC
svn commit: r794379 - in /incubator/openwebbeans/trunk/webbeans-ejb/src/main:
java/org/apache/webbeans/ejb/ java/org/apache/webbeans/ejb/proxy/
resources/META-INF/ resources/META-INF/services/
Author: gerdogdu
Date: Wed Jul 15 19:46:35 2009
New Revision: 794379
URL: http://svn.apache.org/viewvc?rev=794379&view=rev
Log:
Update/delete old code. Support for session beans using OpenEJB container in Tomcat.
Added:
incubator/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/EjbPlugin.java (with props)
incubator/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/proxy/EjbBeanProxyHandler.java (with props)
incubator/openwebbeans/trunk/webbeans-ejb/src/main/resources/META-INF/
incubator/openwebbeans/trunk/webbeans-ejb/src/main/resources/META-INF/services/
incubator/openwebbeans/trunk/webbeans-ejb/src/main/resources/META-INF/services/org.apache.webbeans.plugins.OpenWebBeansPlugin
Added: incubator/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/EjbPlugin.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/EjbPlugin.java?rev=794379&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/EjbPlugin.java (added)
+++ incubator/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/EjbPlugin.java Wed Jul 15 19:46:35 2009
@@ -0,0 +1,156 @@
+/*
+ * 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.ejb;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.SessionBeanType;
+
+import org.apache.openejb.Container;
+import org.apache.openejb.DeploymentInfo;
+import org.apache.openejb.core.singleton.SingletonContainer;
+import org.apache.openejb.core.stateful.StatefulContainer;
+import org.apache.openejb.core.stateless.StatelessContainer;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.spi.ContainerSystem;
+import org.apache.webbeans.ejb.component.EjbBean;
+import org.apache.webbeans.ejb.util.EjbDefinitionUtility;
+import org.apache.webbeans.ejb.util.EjbUtility;
+import org.apache.webbeans.plugins.AbstractOpenWebBeansPlugin;
+import org.apache.webbeans.plugins.OpenWebBeansEjbPlugin;
+
+public class EjbPlugin extends AbstractOpenWebBeansPlugin implements OpenWebBeansEjbPlugin
+{
+ private ContainerSystem containerSystem = null;
+
+ private Map<Class<?>,DeploymentInfo> statelessBeans = new HashMap<Class<?>, DeploymentInfo>();
+
+ private Map<Class<?>,DeploymentInfo> statefullBeans = new HashMap<Class<?>, DeploymentInfo>();
+
+ private Map<Class<?>,DeploymentInfo> singletonBeans = new HashMap<Class<?>, DeploymentInfo>();
+
+ public EjbPlugin()
+ {
+
+ }
+
+ @Override
+ public <T> Bean<T> defineEjbComponent(Class<T> clazz)
+ {
+ DeploymentInfo info = null;
+ SessionBeanType type = SessionBeanType.STATELESS;
+
+ if(isStatelessBean(clazz))
+ {
+ info = this.statelessBeans.get(clazz);
+ }
+ else if(isStatefulBean(clazz))
+ {
+ info = this.statefullBeans.get(clazz);
+ type = SessionBeanType.STATEFUL;
+ }
+ else if(isSingletonBean(clazz))
+ {
+ info = this.singletonBeans.get(clazz);
+ type = SessionBeanType.SINGLETON;
+ }
+ else
+ {
+ throw new IllegalArgumentException("Illegal EJB type with class : " + clazz.getName());
+ }
+
+ EjbBean<T> bean = new EjbBean<T>(clazz);
+ bean.setDeploymentInfo(info);
+ bean.setEjbType(type);
+
+ EjbUtility.fireEvents(clazz, bean);
+
+ return bean;
+ }
+
+ @Override
+ public boolean isEjbClass(Class<?> clazz)
+ {
+ if(this.containerSystem == null)
+ {
+ this.containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
+ Container[] containers = this.containerSystem.containers();
+ for(Container container : containers)
+ {
+ DeploymentInfo[] deployments = container.deployments();
+ if(container instanceof StatelessContainer)
+ {
+ addBeanDeploymentInfos(deployments, SessionBeanType.STATELESS);
+ }
+ else if(container instanceof StatefulContainer)
+ {
+ addBeanDeploymentInfos(deployments, SessionBeanType.STATEFUL);
+ }
+ else if(container instanceof SingletonContainer)
+ {
+ addBeanDeploymentInfos(deployments, SessionBeanType.SINGLETON);
+ }
+ }
+ }
+
+
+ return isSingletonBean(clazz) || isStatelessBean(clazz) || isStatefulBean(clazz);
+ }
+
+ private void addBeanDeploymentInfos(DeploymentInfo[] deployments, SessionBeanType type)
+ {
+ for(DeploymentInfo deployment : deployments)
+ {
+ if(type.equals(SessionBeanType.STATELESS))
+ {
+ this.statelessBeans.put(deployment.getBeanClass(),deployment);
+ }
+ else if(type.equals(SessionBeanType.STATEFUL))
+ {
+ this.statefullBeans.put(deployment.getBeanClass(),deployment);
+ }
+ else if(type.equals(SessionBeanType.SINGLETON))
+ {
+ this.singletonBeans.put(deployment.getBeanClass(), deployment);
+ }
+ }
+ }
+
+ @Override
+ public boolean isSingletonBean(Class<?> clazz)
+ {
+ return this.singletonBeans.containsKey(clazz);
+ }
+
+ @Override
+ public boolean isStatefulBean(Class<?> clazz)
+ {
+ return this.statefullBeans.containsKey(clazz);
+ }
+
+ @Override
+ public boolean isStatelessBean(Class<?> clazz)
+ {
+ return this.statelessBeans.containsKey(clazz);
+ }
+
+ @Override
+ public Object getProxy(Bean<?> bean)
+ {
+ return EjbDefinitionUtility.defineEjbBeanProxy((EjbBean<?>)bean);
+ }
+
+}
Propchange: incubator/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/EjbPlugin.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/proxy/EjbBeanProxyHandler.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/proxy/EjbBeanProxyHandler.java?rev=794379&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/proxy/EjbBeanProxyHandler.java (added)
+++ incubator/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/proxy/EjbBeanProxyHandler.java Wed Jul 15 19:46:35 2009
@@ -0,0 +1,61 @@
+/*
+ * 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.ejb.proxy;
+
+import java.lang.reflect.Method;
+
+import javax.enterprise.context.spi.Context;
+import javax.enterprise.context.spi.Contextual;
+import javax.enterprise.context.spi.CreationalContext;
+
+import org.apache.webbeans.container.BeanManagerImpl;
+import org.apache.webbeans.context.creational.CreationalContextFactory;
+import org.apache.webbeans.ejb.component.EjbBean;
+import org.apache.webbeans.ejb.interceptor.OpenWebBeansEjbInterceptor;
+
+import javassist.util.proxy.MethodHandler;
+
+@SuppressWarnings("unchecked")
+public class EjbBeanProxyHandler implements MethodHandler
+{
+ private EjbBean<?> ejbBean;
+
+ public EjbBeanProxyHandler(EjbBean<?> ejbBean)
+ {
+ this.ejbBean = ejbBean;
+ }
+
+ @Override
+ public Object invoke(Object instance, Method method, Method proceed, Object[] arguments) throws Exception
+ {
+ OpenWebBeansEjbInterceptor.setThreadLocal(this.ejbBean);
+
+ //Context of the bean
+ Context webbeansContext = BeanManagerImpl.getManager().getContext(ejbBean.getScopeType());
+
+ //Get bean instance from context
+ Object webbeansInstance = webbeansContext.get((Contextual<Object>)this.ejbBean, (CreationalContext<Object>)CreationalContextFactory.getInstance().getCreationalContext(this.ejbBean));
+
+ Object result = method.invoke(webbeansInstance, arguments);
+
+ OpenWebBeansEjbInterceptor.unsetThreadLocal();
+
+ return result;
+ }
+
+
+}
Propchange: incubator/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/proxy/EjbBeanProxyHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/openwebbeans/trunk/webbeans-ejb/src/main/resources/META-INF/services/org.apache.webbeans.plugins.OpenWebBeansPlugin
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-ejb/src/main/resources/META-INF/services/org.apache.webbeans.plugins.OpenWebBeansPlugin?rev=794379&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-ejb/src/main/resources/META-INF/services/org.apache.webbeans.plugins.OpenWebBeansPlugin (added)
+++ incubator/openwebbeans/trunk/webbeans-ejb/src/main/resources/META-INF/services/org.apache.webbeans.plugins.OpenWebBeansPlugin Wed Jul 15 19:46:35 2009
@@ -0,0 +1,21 @@
+#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.
+
+# this file contains the service implementation for the
+# JMS integration into OpenWebBeans
+# this file contains information for java.util.ServiceLoader
+org.apache.webbeans.ejb.EjbPlugin
\ No newline at end of file