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/07/01 19:37:08 UTC
svn commit: r959733 - in /openwebbeans/trunk/webbeans-openejb/src:
main/java/org/apache/webbeans/ejb/
main/java/org/apache/webbeans/ejb/resource/
test/java/org/apache/webbeans/ejb/
Author: gerdogdu
Date: Thu Jul 1 17:37:08 2010
New Revision: 959733
URL: http://svn.apache.org/viewvc?rev=959733&view=rev
Log:
Improvement in @EJB injections for OpenEJB. Now supports injecting ejbs witihin the same module with @EJB InterfaceType, example, @EJB ICalculator calculator
Added:
openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/resource/EJBInstanceProxy.java (with props)
Modified:
openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/EjbPlugin.java
openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/resource/ResourceInjectionProcessor.java
openwebbeans/trunk/webbeans-openejb/src/test/java/org/apache/webbeans/ejb/EjbTestContext.java
Modified: openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/EjbPlugin.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/EjbPlugin.java?rev=959733&r1=959732&r2=959733&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/EjbPlugin.java (original)
+++ openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/EjbPlugin.java Thu Jul 1 17:37:08 2010
@@ -22,6 +22,9 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
@@ -32,66 +35,80 @@ import javax.enterprise.inject.spi.Sessi
import org.apache.openejb.Container;
import org.apache.openejb.DeploymentInfo;
+import org.apache.openejb.OpenEJBException;
import org.apache.openejb.assembler.classic.AppInfo;
import org.apache.openejb.assembler.classic.Assembler;
import org.apache.openejb.assembler.classic.DeploymentListener;
import org.apache.openejb.assembler.classic.EjbJarInfo;
import org.apache.openejb.assembler.classic.EnterpriseBeanInfo;
+import org.apache.openejb.assembler.classic.JndiBuilder;
+import org.apache.openejb.assembler.classic.JndiBuilder.JndiNameStrategy;
import org.apache.openejb.core.CoreContainerSystem;
+import org.apache.openejb.core.CoreDeploymentInfo;
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.config.WebBeansFinder;
import org.apache.webbeans.ejb.common.util.EjbDefinitionUtility;
import org.apache.webbeans.ejb.common.util.EjbUtility;
import org.apache.webbeans.ejb.component.OpenEjbBean;
+import org.apache.webbeans.ejb.resource.EJBInstanceProxy;
import org.apache.webbeans.ejb.service.OpenEJBSecurityService;
import org.apache.webbeans.ejb.service.OpenEJBTransactionService;
import org.apache.webbeans.exception.WebBeansConfigurationException;
import org.apache.webbeans.logger.WebBeansLogger;
+import org.apache.webbeans.plugins.PluginLoader;
import org.apache.webbeans.spi.SecurityService;
import org.apache.webbeans.spi.TransactionService;
import org.apache.webbeans.spi.plugins.AbstractOwbPlugin;
import org.apache.webbeans.spi.plugins.OpenWebBeansEjbPlugin;
+import org.apache.webbeans.util.SecurityUtil;
/**
* EJB related stuff.
* <p>
* EJB functionality depends on OpenEJB.
* </p>
+ *
* @version $Rev$ $Date$
- *
*/
public class EjbPlugin extends AbstractOwbPlugin implements OpenWebBeansEjbPlugin, DeploymentListener
{
private ContainerSystem containerSystem = null;
-
+
// OpenEJB assembler
private Assembler assembler;
-
+
private WebBeansLogger logger = WebBeansLogger.getLogger(EjbPlugin.class);
-
+
// List of deployed applications
private final Set<AppInfo> deployedApplications = new CopyOnWriteArraySet<AppInfo>();
-
+
// TODO it should be Map<Class<?>,DeploymentInfo[]>
- private Map<Class<?>,DeploymentInfo> statelessBeans = new ConcurrentHashMap<Class<?>, DeploymentInfo>();
-
- private Map<Class<?>,DeploymentInfo> statefulBeans = new ConcurrentHashMap<Class<?>, DeploymentInfo>();
-
- private Map<Class<?>,DeploymentInfo> singletonBeans = new ConcurrentHashMap<Class<?>, DeploymentInfo>();
-
+ private Map<Class<?>, DeploymentInfo> statelessBeans = new ConcurrentHashMap<Class<?>, DeploymentInfo>();
+
+ private Map<Class<?>, DeploymentInfo> statefulBeans = new ConcurrentHashMap<Class<?>, DeploymentInfo>();
+
+ private Map<Class<?>, DeploymentInfo> singletonBeans = new ConcurrentHashMap<Class<?>, DeploymentInfo>();
+
+ //EJB Interface to instances
+ private Map<String, EJBInstanceProxy<?>> ejbInstances = new ConcurrentHashMap<String, EJBInstanceProxy<?>>();
+
private static final TransactionService TRANSACTION_SERVICE = new OpenEJBTransactionService();
-
+
private static final SecurityService SECURITY_SERVICE = new OpenEJBSecurityService();
+ private final Map<String, JndiNameStrategy> nameStrategies = new TreeMap<String, JndiNameStrategy>();
+
public EjbPlugin()
{
-
+
}
-
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
* @see org.apache.webbeans.plugins.AbstractOwbPlugin#shutDown()
*/
@Override
@@ -104,7 +121,9 @@ public class EjbPlugin extends AbstractO
this.statelessBeans.clear();
this.statefulBeans.clear();
this.singletonBeans.clear();
- this.containerSystem = null;
+ this.containerSystem = null;
+ this.ejbInstances.clear();
+ this.assembler.removeDeploymentListener(this);
}
catch (Exception e)
{
@@ -112,9 +131,20 @@ public class EjbPlugin extends AbstractO
}
}
+ @SuppressWarnings("unchecked")
+ public <T> T getEjbInstance(String intfName, Class<T> intf) throws Exception
+ {
+ EJBInstanceProxy<T> proxy = (EJBInstanceProxy<T>) this.ejbInstances.get(intfName);
+ if (proxy != null)
+ {
+ return intf.cast(proxy.getObject());
+ }
+ return null;
+ }
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
* @see org.apache.webbeans.plugins.AbstractOwbPlugin#startUp()
*/
@Override
@@ -128,7 +158,7 @@ public class EjbPlugin extends AbstractO
{
throw new WebBeansConfigurationException(e);
}
-
+
// Get container and assembler from OpenEJB
containerSystem = (CoreContainerSystem) SystemInstance.get().getComponent(ContainerSystem.class);
assembler = SystemInstance.get().getComponent(Assembler.class);
@@ -145,9 +175,8 @@ public class EjbPlugin extends AbstractO
}
/**
- * OpenEJB call back method
- * It is used to get the list of deployed application and store the Stateless
- * and Stateful pools localy.
+ * OpenEJB call back method It is used to get the list of deployed
+ * application and store the Stateless and Stateful pools localy.
*
* @param appInfo applications informations
*/
@@ -159,48 +188,55 @@ public class EjbPlugin extends AbstractO
List<DeploymentInfo> statelessList = new ArrayList<DeploymentInfo>();
List<DeploymentInfo> statefulList = new ArrayList<DeploymentInfo>();
List<DeploymentInfo> singletonList = new ArrayList<DeploymentInfo>();
-
+
for (EjbJarInfo ejbJar : appInfo.ejbJars)
{
for (EnterpriseBeanInfo bean : ejbJar.enterpriseBeans)
{
switch (bean.type)
{
- case EnterpriseBeanInfo.STATELESS:
- statelessList.add(containerSystem.getDeploymentInfo(bean.ejbDeploymentId));
- break;
- case EnterpriseBeanInfo.STATEFUL:
- statefulList.add(containerSystem.getDeploymentInfo(bean.ejbDeploymentId));
- break;
- case EnterpriseBeanInfo.SINGLETON:
- singletonList.add(containerSystem.getDeploymentInfo(bean.ejbDeploymentId));
- break;
- default:
- break;
+ case EnterpriseBeanInfo.STATELESS:
+ statelessList.add(containerSystem.getDeploymentInfo(bean.ejbDeploymentId));
+ break;
+ case EnterpriseBeanInfo.STATEFUL:
+ statefulList.add(containerSystem.getDeploymentInfo(bean.ejbDeploymentId));
+ break;
+ case EnterpriseBeanInfo.SINGLETON:
+ singletonList.add(containerSystem.getDeploymentInfo(bean.ejbDeploymentId));
+ break;
+ default:
+ break;
}
}
}
+
+ //Means that this is not the our deployment archive
+ boolean result = addBeanDeploymentInfos(statelessList.toArray(new DeploymentInfo[statelessList.size()]), SessionBeanType.STATELESS);
+ if(!result)
+ {
+ deployedApplications.remove(appInfo);
+ return;
+ }
- addBeanDeploymentInfos(statelessList.toArray(new DeploymentInfo[statelessList.size()]), SessionBeanType.STATELESS);
addBeanDeploymentInfos(statefulList.toArray(new DeploymentInfo[statefulList.size()]), SessionBeanType.STATEFUL);
addBeanDeploymentInfos(singletonList.toArray(new DeploymentInfo[singletonList.size()]), SessionBeanType.SINGLETON);
}
-
}
/**
- * OpenEJB callback method
- * Not used.
+ * OpenEJB callback method Not used.
*/
public void beforeApplicationDestroyed(AppInfo appInfo)
{
- this.deployedApplications.remove(appInfo);
- for (EjbJarInfo ejbJar : appInfo.ejbJars)
+ if(this.deployedApplications.contains(appInfo))
{
- for (EnterpriseBeanInfo bean : ejbJar.enterpriseBeans)
+ this.deployedApplications.remove(appInfo);
+ for (EjbJarInfo ejbJar : appInfo.ejbJars)
{
- switch (bean.type)
+ for (EnterpriseBeanInfo bean : ejbJar.enterpriseBeans)
{
+ switch (bean.type)
+ {
case EnterpriseBeanInfo.STATELESS:
this.statelessBeans.remove(containerSystem.getDeploymentInfo(bean.ejbDeploymentId).getBeanClass());
break;
@@ -212,31 +248,34 @@ public class EjbPlugin extends AbstractO
break;
default:
break;
+ }
+
+ this.ejbInstances.remove(bean.ejbName);
}
- }
- }
+ }
+ }
}
-
+
public <T> Bean<T> defineSessionBean(Class<T> clazz, ProcessAnnotatedType<T> processAnnotatedTypeEvent)
{
- if(!isSessionBean(clazz))
+ if (!isSessionBean(clazz))
{
throw new IllegalArgumentException("Given class is not an session bean class");
}
-
+
DeploymentInfo info = null;
SessionBeanType type = SessionBeanType.STATELESS;
-
- if(isStatelessBean(clazz))
+
+ if (isStatelessBean(clazz))
{
info = this.statelessBeans.get(clazz);
}
- else if(isStatefulBean(clazz))
+ else if (isStatefulBean(clazz))
{
info = this.statefulBeans.get(clazz);
type = SessionBeanType.STATEFUL;
}
- else if(isSingletonBean(clazz))
+ else if (isSingletonBean(clazz))
{
info = this.singletonBeans.get(clazz);
type = SessionBeanType.SINGLETON;
@@ -245,68 +284,91 @@ public class EjbPlugin extends AbstractO
{
throw new IllegalArgumentException("Illegal EJB type with class : " + clazz.getName());
}
-
+
OpenEjbBean<T> bean = new OpenEjbBean<T>(clazz);
bean.setDeploymentInfo(info);
bean.setEjbType(type);
-
+
EjbUtility.fireEvents(clazz, bean, processAnnotatedTypeEvent);
-
+
return bean;
}
public boolean isSessionBean(Class<?> clazz)
{
- if(this.containerSystem == null)
+ if (this.containerSystem == null)
{
this.containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
Container[] containers = this.containerSystem.containers();
- for(Container container : containers)
+ for (Container container : containers)
{
DeploymentInfo[] deployments = container.deployments();
- if(container instanceof StatelessContainer)
+ if (container instanceof StatelessContainer)
{
- addBeanDeploymentInfos(deployments, SessionBeanType.STATELESS);
+ addBeanDeploymentInfos(deployments, SessionBeanType.STATELESS);
}
- else if(container instanceof StatefulContainer)
+ else if (container instanceof StatefulContainer)
{
- addBeanDeploymentInfos(deployments, SessionBeanType.STATEFUL);
+ addBeanDeploymentInfos(deployments, SessionBeanType.STATEFUL);
}
- else if(container instanceof SingletonContainer)
+ else if (container instanceof SingletonContainer)
{
- addBeanDeploymentInfos(deployments, SessionBeanType.SINGLETON);
- }
+ addBeanDeploymentInfos(deployments, SessionBeanType.SINGLETON);
+ }
}
}
-
-
+
return isSingletonBean(clazz) || isStatelessBean(clazz) || isStatefulBean(clazz);
}
-
- private void addBeanDeploymentInfos(DeploymentInfo[] deployments, SessionBeanType type)
+
+ private boolean addBeanDeploymentInfos(DeploymentInfo[] deployments, SessionBeanType type)
{
- for(DeploymentInfo deployment : deployments)
+ for (DeploymentInfo deployment : deployments)
{
- if(type.equals(SessionBeanType.STATELESS))
- {
- this.statelessBeans.put(deployment.getBeanClass(),deployment);
- }
- else if(type.equals(SessionBeanType.STATEFUL))
- {
- this.statefulBeans.put(deployment.getBeanClass(),deployment);
- }
- else if(type.equals(SessionBeanType.SINGLETON))
+ boolean inTest = Boolean.valueOf(SecurityUtil.doPrivilegedGetSystemProperty("EjbPlugin.test", "false"));
+ boolean classLoaderEquality = deployment.getBeanClass().getClassLoader().equals(WebBeansFinder.
+ getSingletonClassLoader(PluginLoader.getInstance()));
+
+ //Yes, this EJB archive is deployed within this web application
+ if(inTest || classLoaderEquality)
{
- this.singletonBeans.put(deployment.getBeanClass(), deployment);
+ if (type.equals(SessionBeanType.STATELESS))
+ {
+ this.statelessBeans.put(deployment.getBeanClass(), deployment);
+ }
+ else if (type.equals(SessionBeanType.STATEFUL))
+ {
+ this.statefulBeans.put(deployment.getBeanClass(), deployment);
+ }
+ else if (type.equals(SessionBeanType.SINGLETON))
+ {
+ this.singletonBeans.put(deployment.getBeanClass(), deployment);
+ }
+
+ Map<String, EJBInstanceProxy<?>> bindings = getEjbBindings((CoreDeploymentInfo) deployment);
+ for (Entry<String, EJBInstanceProxy<?>> entry : bindings.entrySet())
+ {
+ String beanName = entry.getKey();
+ if (!this.ejbInstances.containsKey(beanName))
+ {
+ EJBInstanceProxy<?> ejb = entry.getValue();
+ this.ejbInstances.put(beanName, ejb);
+ logger.info("Exported EJB " + deployment.getEjbName() + " with interface " + entry.getValue().getInterface().getName());
+ }
+ }
+
+ return true;
}
- }
+ }
+
+ return false;
}
-
+
public void isManagedBean(Class<?> clazz) throws WebBeansConfigurationException
{
- if(isSessionBean(clazz))
+ if (isSessionBean(clazz))
{
- throw new WebBeansConfigurationException("Managed Bean implementation class : " + clazz.getName() + " can not be sesion bean class");
+ throw new WebBeansConfigurationException("Managed Bean implementation class : " + clazz.getName() + " can not be sesion bean class");
}
}
@@ -327,35 +389,101 @@ public class EjbPlugin extends AbstractO
public Object getSessionBeanProxy(Bean<?> bean, Class<?> iface, CreationalContext<?> creationalContext)
{
- return EjbDefinitionUtility.defineEjbBeanProxy((OpenEjbBean<?>)bean,iface, creationalContext);
+ return EjbDefinitionUtility.defineEjbBeanProxy((OpenEjbBean<?>) bean, iface, creationalContext);
}
-
-
- @Override
+
+ @Override
public <T> T getSupportedService(Class<T> serviceClass)
{
- if(serviceClass == TransactionService.class)
+ if (serviceClass == TransactionService.class)
{
- return serviceClass.cast(TRANSACTION_SERVICE);
+ return serviceClass.cast(TRANSACTION_SERVICE);
}
- else if(serviceClass == SecurityService.class)
+ else if (serviceClass == SecurityService.class)
{
return serviceClass.cast(SECURITY_SERVICE);
}
-
+
return null;
}
@Override
public boolean supportService(Class<?> serviceClass)
{
- if((serviceClass == TransactionService.class) ||
- serviceClass == SecurityService.class)
+ if ((serviceClass == TransactionService.class) || serviceClass == SecurityService.class)
{
return true;
}
-
+
return false;
}
+
+ public JndiNameStrategy createStrategy(AppInfo appInfo, List<DeploymentInfo> deployments, DeploymentInfo deployment) throws OpenEJBException
+ {
+ JndiNameStrategy strategy = nameStrategies.get(deployment.getModuleID());
+ if (strategy != null)
+ {
+ return strategy;
+ }
+
+ String deploymentId = (String) deployment.getDeploymentID();
+ for (EjbJarInfo ejbJar : appInfo.ejbJars)
+ {
+ if (ejbJar.moduleId.equals(deployment.getModuleID()))
+ {
+ Set<String> moduleDeploymentIds = new TreeSet<String>();
+ for (EnterpriseBeanInfo enterpriseBean : ejbJar.enterpriseBeans)
+ {
+ moduleDeploymentIds.add(enterpriseBean.ejbDeploymentId);
+ }
+ Map<String, DeploymentInfo> moduleDeployments = new TreeMap<String, DeploymentInfo>();
+ for (DeploymentInfo deploymentInfo : deployments)
+ {
+ if (moduleDeploymentIds.contains(deploymentId))
+ {
+ moduleDeployments.put((String) deploymentInfo.getDeploymentID(), deploymentInfo);
+ }
+ }
+ strategy = JndiBuilder.createStrategy(ejbJar, moduleDeployments);
+ for (String moduleDeploymentId : moduleDeploymentIds)
+ {
+ nameStrategies.put(moduleDeploymentId, strategy);
+ }
+ return strategy;
+ }
+ }
+ return null;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Map<String, EJBInstanceProxy<?>> getEjbBindings(CoreDeploymentInfo deployment)
+ {
+ Map<String, EJBInstanceProxy<?>> bindings = new TreeMap<String, EJBInstanceProxy<?>>();
+
+ Class<?> remoteHome = deployment.getHomeInterface();
+ if (remoteHome != null)
+ {
+ bindings.put(remoteHome.getName(), new EJBInstanceProxy(deployment, remoteHome));
+ }
+
+ Class<?> localHome = deployment.getLocalHomeInterface();
+ if (localHome != null)
+ {
+ bindings.put(localHome.getName(), new EJBInstanceProxy(deployment, remoteHome));
+ }
+
+ for (Class<?> businessLocal : deployment.getBusinessLocalInterfaces())
+ {
+ bindings.put(businessLocal.getName(), new EJBInstanceProxy(deployment, businessLocal));
+ }
+
+ for (Class<?> businessRemote : deployment.getBusinessRemoteInterfaces())
+ {
+ bindings.put(businessRemote.getName(), new EJBInstanceProxy(deployment, businessRemote));
+ }
+
+ return bindings;
+ }
+
}
Added: openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/resource/EJBInstanceProxy.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/resource/EJBInstanceProxy.java?rev=959733&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/resource/EJBInstanceProxy.java (added)
+++ openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/resource/EJBInstanceProxy.java Thu Jul 1 17:37:08 2010
@@ -0,0 +1,130 @@
+/*
+ * 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.resource;
+
+import org.apache.openejb.DeploymentInfo;
+import org.apache.openejb.assembler.classic.JndiBuilder;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.spi.ContainerSystem;
+
+/**
+ * Get from OpenEJB spring project and changed.
+ */
+public class EJBInstanceProxy<T>
+{
+ private Object deploymentId;
+ private DeploymentInfo deploymentInfo;
+ private Class<T> intf;
+
+ public EJBInstanceProxy()
+ {
+
+ }
+
+ public EJBInstanceProxy(DeploymentInfo deploymentInfo, Class<T> intf)
+ {
+ this.deploymentInfo = deploymentInfo;
+ this.intf = intf;
+ }
+
+ public Object getDeploymentId()
+ {
+ if (deploymentId != null)
+ {
+ return deploymentId;
+ }
+ else if (deploymentInfo != null)
+ {
+ return deploymentInfo.getDeploymentID();
+ }
+ return null;
+ }
+
+ public void setDeploymentId(Object deploymentId)
+ {
+ this.deploymentId = deploymentId;
+ }
+
+ public DeploymentInfo getDeploymentInfo()
+ {
+ if (deploymentInfo != null)
+ {
+ return deploymentInfo;
+ }
+ else if (deploymentId != null)
+ {
+ ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
+ DeploymentInfo deploymentInfo = containerSystem.getDeploymentInfo(deploymentId);
+ return deploymentInfo;
+ }
+ return null;
+ }
+
+ public void setDeploymentInfo(DeploymentInfo deploymentInfo)
+ {
+ this.deploymentInfo = deploymentInfo;
+ }
+
+ public Class<T> getInterface()
+ {
+ return intf;
+ }
+
+ public void setInterface(Class<T> intf)
+ {
+ this.intf = intf;
+ }
+
+ public T getObject() throws Exception
+ {
+ if (intf == null)
+ {
+ throw new NullPointerException("intf is null");
+ }
+
+ DeploymentInfo deploymentInfo = getDeploymentInfo();
+ if (deploymentInfo == null)
+ {
+ throw new IllegalStateException("DeploymentInfo or DeploymentID must be set before EJB can be retrieved");
+ }
+
+ // this is the pattern for the internal jndi name
+ String jndiName = "java:openejb/Deployment/" + JndiBuilder.format(deploymentInfo.getDeploymentID(), getInterface().getName());
+
+ // perform the lookup against the jndi context in the container
+ // system
+ ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
+ Object proxy = containerSystem.getJNDIContext().lookup(jndiName);
+ if (!intf.isInstance(proxy))
+ {
+ throw new IllegalArgumentException("EJB at " + jndiName + " is not an instance of " + intf.getName() + ", but is " + proxy.getClass().getName());
+ }
+ return intf.cast(proxy);
+ }
+
+ public Class<T> getObjectType()
+ {
+ return getInterface();
+ }
+
+ public boolean isSingleton()
+ {
+ return false;
+ }
+}
Propchange: openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/resource/EJBInstanceProxy.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/resource/ResourceInjectionProcessor.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/resource/ResourceInjectionProcessor.java?rev=959733&r1=959732&r2=959733&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/resource/ResourceInjectionProcessor.java (original)
+++ openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/resource/ResourceInjectionProcessor.java Thu Jul 1 17:37:08 2010
@@ -19,7 +19,6 @@
package org.apache.webbeans.ejb.resource;
import java.lang.annotation.Annotation;
-import java.lang.reflect.InvocationTargetException;
import javax.annotation.Resource;
import javax.ejb.EJB;
@@ -36,19 +35,24 @@ import javax.xml.ws.WebServiceRef;
import org.apache.openejb.loader.SystemInstance;
import org.apache.openejb.persistence.JtaEntityManager;
import org.apache.openejb.persistence.JtaEntityManagerRegistry;
+import org.apache.webbeans.ejb.EjbPlugin;
+import org.apache.webbeans.logger.WebBeansLogger;
+import org.apache.webbeans.plugins.PluginLoader;
import org.apache.webbeans.spi.api.ResourceReference;
class ResourceInjectionProcessor
{
private Context context = null;
+
+ private static final WebBeansLogger logger = WebBeansLogger.getLogger(ResourceInjectionProcessor.class);
ResourceInjectionProcessor(Context context)
{
this.context = context;
}
- public <X, T extends Annotation> X getResourceReference(ResourceReference<X, T> resourceReference) throws IllegalAccessException, InvocationTargetException, NamingException
+ public <X, T extends Annotation> X getResourceReference(ResourceReference<X, T> resourceReference) throws Exception
{
X resource = null;
@@ -61,17 +65,62 @@ class ResourceInjectionProcessor
if(resourceReference.supports(Resource.class))
{
Resource annotation = resourceReference.getAnnotation(Resource.class);
- resource= lookupFieldResource(context, "openejb/Resource/"+annotation.name(), resourceReference.getResourceType());
+ String name = annotation.name();
+ if(name == null || name.equals(""))
+ {
+ name = resourceReference.getOwnerClass() + "/" + resourceReference.getName();
+ }
+
+ resource= lookupFieldResource(context, "openejb/Resource/"+name, resourceReference.getResourceType());
}
else if(resourceReference.supports(EJB.class))
{
EJB annotation = resourceReference.getAnnotation(EJB.class);
- resource = lookupFieldResource(context, "openejb/Deployment/"+annotation.name(), resourceReference.getResourceType());
+
+ String intf = null;
+ if(annotation.beanInterface() != null
+ && annotation.beanInterface() != Object.class
+ && !annotation.beanInterface().equals(""))
+ {
+ intf = annotation.beanInterface().getName();
+ }
+
+ if(intf == null)
+ {
+ intf = resourceReference.getResourceType().getName();
+ }
+
+ if(intf == null && annotation.beanName() == null)
+ {
+ if(logger.wblWillLogWarn())
+ {
+ logger.warn("To inject @EJBs into the managed beans you have to give @EJB(beanName), " +
+ "trying to get inject with @EJB(name) where name is the internal JNDI name of the OpenEJB Bean");
+ }
+
+ String name = annotation.name();
+ if(name == null || name.equals(""))
+ {
+ name = resourceReference.getOwnerClass() + "/" + resourceReference.getName();
+ }
+
+ resource = lookupFieldResource(context, "openejb/Deployment/"+ name, resourceReference.getResourceType());
+ }
+ else
+ {
+ EjbPlugin plugin =(EjbPlugin) PluginLoader.getInstance().getEjbPlugin();
+ return plugin.getEjbInstance(intf, resourceReference.getResourceType());
+ }
}
else if(resourceReference.supports(WebServiceRef.class))
{
WebServiceRef annotation = resourceReference.getAnnotation(WebServiceRef.class);
- resource = lookupFieldResource(context, annotation.name(), resourceReference.getResourceType());
+ String name = annotation.name();
+ if(name == null || name.equals(""))
+ {
+ name = resourceReference.getOwnerClass() + "/" + resourceReference.getName();
+ }
+ resource = lookupFieldResource(context, name, resourceReference.getResourceType());
}
else if(resourceReference.supports(PersistenceUnit.class))
{
Modified: openwebbeans/trunk/webbeans-openejb/src/test/java/org/apache/webbeans/ejb/EjbTestContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-openejb/src/test/java/org/apache/webbeans/ejb/EjbTestContext.java?rev=959733&r1=959732&r2=959733&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-openejb/src/test/java/org/apache/webbeans/ejb/EjbTestContext.java (original)
+++ openwebbeans/trunk/webbeans-openejb/src/test/java/org/apache/webbeans/ejb/EjbTestContext.java Thu Jul 1 17:37:08 2010
@@ -43,6 +43,8 @@ public abstract class EjbTestContext
System.out.println("INIT EJB");
OpenEJB.init(System.getProperties());
+ System.setProperty("EjbPlugin.test", "true");
+
} catch(Exception e)
{
e.printStackTrace();
Re: svn commit: r959733 - in /openwebbeans/trunk/webbeans-openejb/src: main/java/org/apache/webbeans/ejb/ main/java/org/apache/webbeans/ejb/resource/ test/java/org/apache/webbeans/ejb/
Posted by Gurkan Erdogdu <gu...@yahoo.com>.
Yes, you are so right! I forgot to add same thing for other types :)
Thanks;
--Gurkan
________________________________
From: Eric Covener <co...@gmail.com>
To: dev@openwebbeans.apache.org
Sent: Fri, July 16, 2010 4:04:22 AM
Subject: Re: svn commit: r959733 - in /openwebbeans/trunk/webbeans-openejb/src:
main/java/org/apache/webbeans/ejb/ main/java/org/apache/webbeans/ejb/resource/
test/java/org/apache/webbeans/ejb/
> +
> + //Means that this is not the our deployment archive
> + boolean result = addBeanDeploymentInfos(statelessList.toArray(new
>DeploymentInfo[statelessList.size()]), SessionBeanType.STATELESS);
> + if(!result)
> + {
> + deployedApplications.remove(appInfo);
> + return;
> + }
>
> - addBeanDeploymentInfos(statelessList.toArray(new
>DeploymentInfo[statelessList.size()]), SessionBeanType.STATELESS);
> addBeanDeploymentInfos(statefulList.toArray(new
>DeploymentInfo[statefulList.size()]), SessionBeanType.STATEFUL);
> addBeanDeploymentInfos(singletonList.toArray(new
>DeploymentInfo[singletonList.size()]), SessionBeanType.SINGLETON);
> }
Gurkan,
Doesn't this disable EJB support for applications that don't have
stateless session beans but might have a singleton or an SFSB?
Is it as simple as making sure none of them return true before
removing deployed app?
--
Eric Covener
covener@gmail.com
Re: svn commit: r959733 - in /openwebbeans/trunk/webbeans-openejb/src:
main/java/org/apache/webbeans/ejb/ main/java/org/apache/webbeans/ejb/resource/
test/java/org/apache/webbeans/ejb/
Posted by Eric Covener <co...@gmail.com>.
> +
> + //Means that this is not the our deployment archive
> + boolean result = addBeanDeploymentInfos(statelessList.toArray(new DeploymentInfo[statelessList.size()]), SessionBeanType.STATELESS);
> + if(!result)
> + {
> + deployedApplications.remove(appInfo);
> + return;
> + }
>
> - addBeanDeploymentInfos(statelessList.toArray(new DeploymentInfo[statelessList.size()]), SessionBeanType.STATELESS);
> addBeanDeploymentInfos(statefulList.toArray(new DeploymentInfo[statefulList.size()]), SessionBeanType.STATEFUL);
> addBeanDeploymentInfos(singletonList.toArray(new DeploymentInfo[singletonList.size()]), SessionBeanType.SINGLETON);
> }
Gurkan,
Doesn't this disable EJB support for applications that don't have
stateless session beans but might have a singleton or an SFSB?
Is it as simple as making sure none of them return true before
removing deployed app?
--
Eric Covener
covener@gmail.com