[jboss-cvs] JBossAS SVN: r72268 - in trunk/ejb3/src/main/org/jboss/ejb3: deployers and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Apr 16 05:30:08 EDT 2008
Author: scott.stark at jboss.org
Date: 2008-04-16 05:30:08 -0400 (Wed, 16 Apr 2008)
New Revision: 72268
Added:
trunk/ejb3/src/main/org/jboss/ejb3/clientmodule/EJBRemoteHandler.java
trunk/ejb3/src/main/org/jboss/ejb3/deployers/JBossASDepdencyPolicy.java
Modified:
trunk/ejb3/src/main/org/jboss/ejb3/clientmodule/ClientENCInjectionContainer.java
trunk/ejb3/src/main/org/jboss/ejb3/deployers/JBoss5DeploymentScope.java
Log:
Relax container dependencies to get ejb2 deployments working while the move to supplies based on jndi names is worked on
Modified: trunk/ejb3/src/main/org/jboss/ejb3/clientmodule/ClientENCInjectionContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/clientmodule/ClientENCInjectionContainer.java 2008-04-16 08:42:18 UTC (rev 72267)
+++ trunk/ejb3/src/main/org/jboss/ejb3/clientmodule/ClientENCInjectionContainer.java 2008-04-16 09:30:08 UTC (rev 72268)
@@ -47,13 +47,13 @@
import org.jboss.ejb3.deployers.JBoss5DependencyPolicy;
import org.jboss.ejb3.deployers.JBoss5DeploymentScope;
import org.jboss.ejb3.deployers.JBoss5DeploymentUnit;
+import org.jboss.ejb3.deployers.JBossASDepdencyPolicy;
import org.jboss.ejb3.enc.DeploymentEjbResolver;
import org.jboss.ejb3.enc.MessageDestinationResolver;
import org.jboss.ejb3.entity.PersistenceUnitDeployment;
import org.jboss.ejb3.javaee.AbstractJavaEEComponent;
import org.jboss.ejb3.javaee.SimpleJavaEEModule;
import org.jboss.injection.DependsHandler;
-import org.jboss.injection.EJBRemoteHandler;
import org.jboss.injection.EncInjector;
import org.jboss.injection.InjectionContainer;
import org.jboss.injection.InjectionHandler;
@@ -100,7 +100,7 @@
private DeploymentEjbResolver ejbResolver;
private DeploymentScope deploymentScope;
private ObjectName objectName;
- private DependencyPolicy dependencyPolicy = new JBoss5DependencyPolicy(this);
+ private DependencyPolicy dependencyPolicy = new JBossASDepdencyPolicy(this);
private MessageDestinationResolver messageDestinationResolver;
Added: trunk/ejb3/src/main/org/jboss/ejb3/clientmodule/EJBRemoteHandler.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/clientmodule/EJBRemoteHandler.java (rev 0)
+++ trunk/ejb3/src/main/org/jboss/ejb3/clientmodule/EJBRemoteHandler.java 2008-04-16 09:30:08 UTC (rev 72268)
@@ -0,0 +1,363 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.clientmodule;
+
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Collection;
+import java.util.Map;
+
+import javax.ejb.EJB;
+import javax.ejb.EJBs;
+import javax.naming.NameNotFoundException;
+
+import org.jboss.ejb3.EJBContainer;
+import org.jboss.ejb3.annotation.IgnoreDependency;
+import org.jboss.injection.EJBInjectionHandler;
+import org.jboss.injection.EjbEncInjector;
+import org.jboss.injection.EncInjector;
+import org.jboss.injection.InjectionContainer;
+import org.jboss.injection.InjectionUtil;
+import org.jboss.injection.Injector;
+import org.jboss.logging.Logger;
+import org.jboss.metadata.javaee.spec.AbstractEJBReferenceMetaData;
+import org.jboss.metadata.javaee.spec.EJBReferenceMetaData;
+import org.jboss.metadata.javaee.spec.RemoteEnvironment;
+
+/**
+ * Local override until the ejb3 code is released for EJBTHREE-1289.
+ *
+ * Searches bean class for all @Inject and create Injectors
+ * for a remote environment.
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 70399 $
+ */
+public class EJBRemoteHandler<X extends RemoteEnvironment> extends EJBInjectionHandler<X>
+{
+ private static final Logger log = Logger.getLogger(EJBRemoteHandler.class);
+
+ public void loadXml(X xml, InjectionContainer container)
+ {
+ if (xml != null)
+ {
+ log.trace("ejbRefs = " + xml.getEjbReferences());
+ if (xml.getEjbReferences() != null) loadEjbRefXml(xml.getEjbReferences(), container);
+ }
+ }
+
+ protected void loadEjbRefXml(Collection<EJBReferenceMetaData> refs, InjectionContainer container)
+ {
+ for (EJBReferenceMetaData ref : refs)
+ {
+ String interfaceName = ref.getRemote();
+ String errorType = "<ejb-ref>";
+
+ ejbRefXml(ref, interfaceName, container, errorType);
+ }
+ }
+
+ protected void ejbRefXml(AbstractEJBReferenceMetaData ref, String interfaceName, InjectionContainer container, String errorType)
+ {
+ String encName = "env/" + ref.getEjbRefName();
+ InjectionUtil.injectionTarget(encName, ref, container, container.getEncInjections());
+ if (container.getEncInjectors().containsKey(encName))
+ return;
+
+ String mappedName = ref.getMappedName();
+ if (mappedName != null && mappedName.equals(""))
+ mappedName = null;
+ if(mappedName == null && ref.getResolvedJndiName() != null)
+ mappedName = ref.getResolvedJndiName();
+
+ String link = ref.getLink();
+ if (link != null && link.trim().equals("")) link = null;
+
+ Class<?> refClass = null;
+
+ if (interfaceName != null)
+ {
+ try
+ {
+ refClass = container.getClassloader().loadClass(interfaceName);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new RuntimeException("could not find " + errorType + "'s local interface " + interfaceName + " in " + container.getDeploymentDescriptorType() + " of " + container.getIdentifier());
+ }
+ }
+
+ //----- injectors
+
+ if (mappedName == null && refClass == null && link == null)
+ {
+ // must be jboss.xml only with @EJB used to define reference. jboss.xml used to tag for ignore dependency
+ // i think it is ok to assume this because the ejb-jar.xml schema should handle any missing elements
+ }
+ else
+ {
+ ejbRefEncInjector(mappedName, encName, refClass, link, errorType, container);
+ if (ref.getIgnoreDependency() != null)
+ {
+ log.debug("IGNORING <ejb-ref> DEPENDENCY: " + encName);
+ return;
+ }
+
+ ejbRefDependency(mappedName, link, container, refClass, errorType, encName);
+ }
+ }
+
+ protected void ejbRefDependency(String mappedName, String link, InjectionContainer container, Class<?> refClass, String errorType, String encName)
+ {
+ if(mappedName != null && mappedName.length() == 0) mappedName = null;
+ if (refClass != null && (refClass.equals(Object.class) || refClass.equals(void.class))) refClass = null;
+
+ if(mappedName != null)
+ {
+ addJNDIDependency(container, mappedName);
+ return;
+ }
+
+ if (refClass != null)
+ {
+ if (link != null && !link.trim().equals(""))
+ {
+ addDependency(container, link, refClass);
+ }
+ else
+ {
+ addDependency(container, refClass);
+ }
+ }
+
+ else
+ {
+ String msg = "IGNORING DEPENDENCY: unable to resolve dependency of EJB, there is too little information";
+ log.warn(msg);
+ }
+ }
+
+ protected void ejbRefEncInjector(String mappedName, String encName, Class refClass, String link, String errorType, InjectionContainer container)
+ {
+ if (refClass != null && (refClass.equals(Object.class) || refClass.equals(void.class))) refClass = null;
+ if (mappedName != null && mappedName.trim().equals("")) mappedName = null;
+
+ EncInjector injector = null;
+
+ if (mappedName == null)
+ {
+ injector = new EjbEncInjector(encName, refClass, link, errorType);
+ }
+ else
+ {
+ injector = new EjbEncInjector(encName, mappedName, errorType);
+ }
+
+ container.getEncInjectors().put(encName, injector);
+ }
+
+ public static EJBContainer getEjbContainer(EJB ref, InjectionContainer container, Class<?> memberType)
+ {
+ EJBContainer rtn = null;
+
+ if (ref.mappedName() != null && !"".equals(ref.mappedName()))
+ {
+ return null;
+ }
+
+ if (ref.beanName().equals("") && memberType == null)
+ throw new RuntimeException("For deployment " + container.getIdentifier() + "not enough information for @EJB. Please fill out the beanName and/or businessInterface attributes");
+
+ Class<?> businessInterface = memberType;
+ if (!ref.beanInterface().getName().equals(Object.class.getName()))
+ {
+ businessInterface = ref.beanInterface();
+ }
+
+ if (ref.beanName().equals(""))
+ {
+ try
+ {
+ rtn = (EJBContainer) container.resolveEjbContainer(businessInterface);
+ }
+ catch (NameNotFoundException e)
+ {
+ log.warn("For deployment " + container.getIdentifier() + " could not find jndi binding based on interface only for @EJB(" + businessInterface.getName() + ") " + e.getMessage());
+ }
+ }
+ else
+ {
+ rtn = (EJBContainer) container.resolveEjbContainer(ref.beanName(), businessInterface);
+ }
+
+ return rtn;
+ }
+
+ public static String getJndiName(EJB ref, InjectionContainer container, Class<?> memberType)
+ {
+ String jndiName;
+
+ if (ref.mappedName() != null && !"".equals(ref.mappedName()))
+ {
+ return ref.mappedName();
+ }
+
+ if (ref.beanName().equals("") && memberType == null)
+ throw new RuntimeException("For deployment " + container.getIdentifier() + "not enough information for @EJB. Please fill out the beanName and/or businessInterface attributes");
+
+ Class<?> businessInterface = memberType;
+ if (!ref.beanInterface().getName().equals(Object.class.getName()))
+ {
+ businessInterface = ref.beanInterface();
+ }
+
+ if (ref.beanName().equals(""))
+ {
+ try
+ {
+ jndiName = container.getEjbJndiName(businessInterface);
+ }
+ catch (NameNotFoundException e)
+ {
+ throw new RuntimeException("For deployment " + container.getIdentifier() + " could not find jndi binding based on interface only for @EJB(" + businessInterface.getName() + ") " + e.getMessage());
+ }
+ if (jndiName == null)
+ {
+ throw new RuntimeException("For deployment " + container.getIdentifier() + " could not find jndi binding based on interface only for @EJB(" + businessInterface.getName() + ")");
+ }
+ }
+ else
+ {
+ jndiName = container.getEjbJndiName(ref.beanName(), businessInterface);
+ if (jndiName == null)
+ {
+ throw new RuntimeException("For EJB " + container.getIdentifier() + "could not find jndi binding based on beanName and business interface for @EJB(" + ref.beanName() + ", " + businessInterface.getName() + ")");
+ }
+ }
+
+ return jndiName;
+ }
+
+ public void handleClassAnnotations(Class<?> clazz, InjectionContainer container)
+ {
+ EJBs ref = container.getAnnotation(EJBs.class, clazz);
+ if (ref != null)
+ {
+ EJB[] ejbs = ref.value();
+
+ for (EJB ejb : ejbs)
+ {
+ handleClassAnnotation(ejb, clazz, container);
+ }
+ }
+ EJB ejbref = container.getAnnotation(EJB.class, clazz);
+ if (ejbref != null) handleClassAnnotation(ejbref, clazz, container);
+ }
+
+ protected void handleClassAnnotation(EJB ejb, Class<?> clazz, InjectionContainer container)
+ {
+ String encName = ejb.name();
+ if (encName == null || encName.equals(""))
+ {
+ throw new RuntimeException("JBoss requires the name of the @EJB in the @EJBs: " + clazz);
+ }
+ encName = "env/" + encName;
+
+ if (container.getEncInjectors().containsKey(encName)) return;
+ ejbRefEncInjector(ejb.mappedName(), encName, ejb.beanInterface(), ejb.beanName(), "@EJB", container);
+
+ // handle dependencies
+
+ if (isIgnoreDependency(container, ejb))
+ log.debug("IGNORING <ejb-ref> DEPENDENCY: " + encName);
+ else
+ ejbRefDependency(ejb.mappedName(), ejb.beanName(), container, ejb.beanInterface(), "@EJB", encName);
+ }
+
+ public void handleMethodAnnotations(Method method, InjectionContainer container, Map<AccessibleObject, Injector> injectors)
+ {
+ EJB ref = container.getAnnotation(EJB.class, method);
+ if (ref != null)
+ {
+ if (!method.getName().startsWith("set"))
+ throw new RuntimeException("@EJB can only be used with a set method: " + method);
+ String encName = getEncName(ref, method);
+ if (!container.getEncInjectors().containsKey(encName))
+ {
+ ejbRefEncInjector(ref.mappedName(), encName, method.getParameterTypes()[0], ref.beanName(), "@EJB", container);
+
+ if (container.getAnnotation(IgnoreDependency.class, method) == null)
+ {
+ if (isIgnoreDependency(container, ref))
+ log.debug("IGNORING <ejb-ref> DEPENDENCY: " + encName);
+ else
+ ejbRefDependency(ref.mappedName(), ref.beanName(), container, method.getParameterTypes()[0], "@EJB", encName);
+ }
+ }
+
+ super.handleMethodAnnotations(method, container, injectors);
+ }
+ }
+
+ public void handleFieldAnnotations(Field field, InjectionContainer container, Map<AccessibleObject, Injector> injectors)
+ {
+ EJB ref = container.getAnnotation(EJB.class, field);
+ if (ref != null)
+ {
+ String encName = getEncName(ref, field);
+ if (!container.getEncInjectors().containsKey(encName))
+ {
+ if (container.getAnnotation(IgnoreDependency.class, field) == null)
+ {
+ if (isIgnoreDependency(container, ref))
+ log.debug("IGNORING <ejb-ref> DEPENDENCY: " + encName);
+ else
+ ejbRefDependency(ref.mappedName(), ref.beanName(), container, field.getType(), "@EJB", encName);
+ }
+ ejbRefEncInjector(ref.mappedName(), encName, field.getType(), ref.beanName(), "@EJB", container);
+ }
+ super.handleFieldAnnotations(field, container, injectors);
+ }
+ }
+
+ protected boolean isIgnoreDependency(InjectionContainer container, EJB ref)
+ {
+ RemoteEnvironment refGroup = container.getEnvironmentRefGroup();
+
+ if (refGroup != null)
+ {
+ if(refGroup.getEjbReferences() != null)
+ for(EJBReferenceMetaData ejbRef : refGroup.getEjbReferences())
+ {
+ if (ejbRef.getEjbRefName().equals(ref.name()))
+ {
+ return ejbRef.getIgnoreDependency() != null;
+ }
+ }
+ }
+
+ // TODO: shouldn't we scan local ejb refs as well?
+
+ return false;
+ }
+}
\ No newline at end of file
Modified: trunk/ejb3/src/main/org/jboss/ejb3/deployers/JBoss5DeploymentScope.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/deployers/JBoss5DeploymentScope.java 2008-04-16 08:42:18 UTC (rev 72267)
+++ trunk/ejb3/src/main/org/jboss/ejb3/deployers/JBoss5DeploymentScope.java 2008-04-16 09:30:08 UTC (rev 72268)
@@ -74,7 +74,7 @@
deployments = new ConcurrentHashMap<String, Ejb3Deployment>();
parent.addAttachment(ATTACHMENT_KEY, deployments);
}
- /* TODO: MappedReferenceMetaDataResolverDeployer output, Look for the endpoint resolver
+ /* MappedReferenceMetaDataResolverDeployer output, Look for the endpoint resolver
endpointResolver = parent.getAttachment(DeploymentEndpointResolver.class);
if(endpointResolver == null)
throw new IllegalStateException("No DeploymentEndpointResolver found in deployment: "+parent);
Added: trunk/ejb3/src/main/org/jboss/ejb3/deployers/JBossASDepdencyPolicy.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/deployers/JBossASDepdencyPolicy.java (rev 0)
+++ trunk/ejb3/src/main/org/jboss/ejb3/deployers/JBossASDepdencyPolicy.java 2008-04-16 09:30:08 UTC (rev 72268)
@@ -0,0 +1,150 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.deployers;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.beans.metadata.plugins.AbstractDemandMetaData;
+import org.jboss.beans.metadata.plugins.AbstractSupplyMetaData;
+import org.jboss.beans.metadata.spi.DemandMetaData;
+import org.jboss.beans.metadata.spi.DependencyMetaData;
+import org.jboss.beans.metadata.spi.SupplyMetaData;
+import org.jboss.ejb3.DependencyPolicy;
+import org.jboss.ejb3.dependency.EjbLinkDemandMetaData;
+import org.jboss.ejb3.javaee.JavaEEComponent;
+import org.jboss.ejb3.kernel.JNDIKernelRegistryPlugin;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class JBossASDepdencyPolicy extends JBoss5DependencyPolicy
+ implements DependencyPolicy
+{
+ private JavaEEComponent component;
+ private Set<DependencyMetaData> dependencies = new HashSet<DependencyMetaData>();
+ private Set<DemandMetaData> demands = new HashSet<DemandMetaData>();
+ private Set<SupplyMetaData> supplies = new HashSet<SupplyMetaData>();
+
+ public JBossASDepdencyPolicy(JavaEEComponent component)
+ {
+ super(component);
+ this.component = component;
+ }
+
+ public void addDependency(String dependency)
+ {
+ addDependency(new AbstractDemandMetaData(dependency));
+ }
+ public void addDependency(DemandMetaData dependency)
+ {
+ demands.add(dependency);
+ }
+ public void addDependency(DependencyMetaData dependency)
+ {
+ dependencies.add(dependency);
+ }
+
+ public void addDependency(Class<?> businessInterface)
+ {
+ addDependency("Class:" + businessInterface.getName());
+ }
+
+ /**
+ * Add a dependency on an enterprise bean.
+ *
+ * Optionally the ejb link is prefixed with the path name to
+ * another ejb-jar file separated with a '#' to the enterprise bean's name.
+ *
+ * @param ejbLink the name of the target enterprise bean
+ * @param businessInterface
+ */
+ public void addDependency(String ejbLink, Class<?> businessInterface)
+ {
+ assert ejbLink != null : "ejbLink is null";
+
+ // Note that businessInterface is always ignored during resolving.
+
+ // FIXME: less hacky
+
+ int hashIndex = ejbLink.indexOf('#');
+ if (hashIndex != -1)
+ {
+ String unitName = ejbLink.substring(0, hashIndex);
+ String ejbName = ejbLink.substring(hashIndex + 1);
+ // Work around ejb2/3 container name mismatches by adding
+ String ejb3Name = component.createObjectName(unitName, ejbName);
+ String ejb2Name = "TODO...";
+ String demand = null;
+ AbstractDemandMetaData admd = new AbstractDemandMetaData(demand);
+ admd.setTransformer("");
+ //addDependency(admd);
+ }
+ else
+ {
+ //addDependency(new EjbLinkDemandMetaData(component, ejbLink));
+ }
+ }
+
+ public void addJNDIName(String name)
+ {
+ assert name != null : "name is null";
+ assert name.length() > 0 : "name is empty";
+
+ addDependency(JNDIKernelRegistryPlugin.JNDI_DEPENDENCY_PREFIX + name);
+ }
+
+ public Set<DependencyMetaData> getDependencies()
+ {
+ return dependencies;
+ }
+ public Set<DemandMetaData> getDemands()
+ {
+ return demands;
+ }
+
+ public void addSupply(Class<?> businessInterface)
+ {
+ supplies.add(new AbstractSupplyMetaData("Class:" + businessInterface.getName()));
+ }
+
+ public Set<SupplyMetaData> getSupplies()
+ {
+ return supplies;
+ }
+ public void addDatasource(String jndiName)
+ {
+ String ds = jndiName;
+ if (ds.startsWith("java:/"))
+ {
+ ds = ds.substring(6);
+
+ }
+ else if (ds.startsWith("java:"))
+ {
+ ds = ds.substring(5);
+ }
+ String onStr = "jboss.jca:name=" + ds + ",service=DataSourceBinding";
+ addDependency(onStr);
+ }
+}
More information about the jboss-cvs-commits
mailing list