You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by da...@apache.org on 2007/01/24 05:10:23 UTC
svn commit: r499248 - in /geronimo/server/trunk/modules:
geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/
geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/
geronimo-naming/src/main/java/org/apache/gero...
Author: dain
Date: Tue Jan 23 20:10:20 2007
New Revision: 499248
URL: http://svn.apache.org/viewvc?view=rev&rev=499248
Log:
Fixed ejb-ref and ejb-local-ref to business interfaces
Modified:
geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/EARContext.java
geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/AbstractNamingBuilder.java
geronimo/server/trunk/modules/geronimo-naming/src/main/java/org/apache/geronimo/naming/reference/PersistenceUnitReference.java
geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbDeploymentBuilder.java
geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilder.java
geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/ejbref/AbstractEjbRefBuilder.java
geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/ejbref/ClientEjbRefBuilder.java
geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/ejbref/LocalEjbRefBuilder.java
geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/ejbref/RemoteEjbRefBuilder.java
Modified: geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/EARContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/EARContext.java?view=diff&rev=499248&r1=499247&r2=499248
==============================================================================
--- geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/EARContext.java (original)
+++ geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/EARContext.java Tue Jan 23 20:10:20 2007
@@ -48,6 +48,8 @@
private final Map messageDestinations = new HashMap();
+ private final Map generalData = new HashMap();
+
public EARContext(File baseDir,
File inPlaceConfigurationDir,
Environment environment,
@@ -170,4 +172,7 @@
return messageDestinations;
}
+ public Map getGeneralData() {
+ return generalData;
+ }
}
Modified: geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/AbstractNamingBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/AbstractNamingBuilder.java?view=diff&rev=499248&r1=499247&r2=499248
==============================================================================
--- geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/AbstractNamingBuilder.java (original)
+++ geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/AbstractNamingBuilder.java Tue Jan 23 20:10:20 2007
@@ -43,6 +43,7 @@
import org.apache.geronimo.schema.NamespaceElementConverter;
import org.apache.geronimo.xbeans.geronimo.naming.GerPatternType;
import org.apache.geronimo.xbeans.geronimo.naming.GerAbstractNamingEntryDocument;
+import org.apache.geronimo.xbeans.javaee.XsdStringType;
import org.apache.xmlbeans.QNameSet;
import org.apache.xmlbeans.SchemaType;
import org.apache.xmlbeans.XmlObject;
@@ -176,6 +177,14 @@
}
protected static String getStringValue(org.apache.geronimo.xbeans.javaee.String string) {
+ if (string == null) {
+ return null;
+ }
+ String s = string.getStringValue();
+ return s == null ? null : s.trim();
+ }
+
+ protected static String getStringValue(XsdStringType string) {
if (string == null) {
return null;
}
Modified: geronimo/server/trunk/modules/geronimo-naming/src/main/java/org/apache/geronimo/naming/reference/PersistenceUnitReference.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-naming/src/main/java/org/apache/geronimo/naming/reference/PersistenceUnitReference.java?view=diff&rev=499248&r1=499247&r2=499248
==============================================================================
--- geronimo/server/trunk/modules/geronimo-naming/src/main/java/org/apache/geronimo/naming/reference/PersistenceUnitReference.java (original)
+++ geronimo/server/trunk/modules/geronimo-naming/src/main/java/org/apache/geronimo/naming/reference/PersistenceUnitReference.java Tue Jan 23 20:10:20 2007
@@ -50,7 +50,7 @@
Object entityManagerFactory;
try {
- entityManagerFactory = kernel.invoke(target, "getEntityManagerFactory");
+ entityManagerFactory = kernel.getAttribute(target, "entityManagerFactory");
} catch (Exception e) {
throw (IllegalStateException) new IllegalStateException("Could not get EntityManagerFactory").initCause(e);
}
Modified: geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbDeploymentBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbDeploymentBuilder.java?view=diff&rev=499248&r1=499247&r2=499248
==============================================================================
--- geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbDeploymentBuilder.java (original)
+++ geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbDeploymentBuilder.java Tue Jan 23 20:10:20 2007
@@ -34,6 +34,7 @@
import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
import org.apache.geronimo.naming.deployment.GBeanResourceEnvironmentBuilder;
import org.apache.geronimo.naming.deployment.ResourceEnvironmentSetter;
+import org.apache.geronimo.naming.deployment.AbstractNamingBuilder;
import org.apache.geronimo.openejb.xbeans.ejbjar.OpenejbGeronimoEjbJarType;
import org.apache.geronimo.security.deployment.SecurityConfiguration;
import org.apache.geronimo.security.jacc.ComponentPermissions;
@@ -52,8 +53,6 @@
import org.apache.openejb.jee.EntityBean;
import org.apache.openejb.jee.SessionBean;
import org.apache.openejb.alt.config.ejb.EjbDeployment;
-import org.apache.geronimo.openejb.deployment.ejbref.LocalEjbRefBuilder;
-import org.apache.geronimo.openejb.deployment.ejbref.RemoteEjbRefBuilder;
import org.apache.geronimo.openejb.StatelessDeploymentGBean;
import org.apache.geronimo.openejb.StatefulDeploymentGBean;
import org.apache.geronimo.openejb.EntityDeploymentGBean;
@@ -118,22 +117,22 @@
// Remote
if (remoteBean.getRemote() != null) {
String remoteInterfaceName = remoteBean.getRemote();
- RemoteEjbRefBuilder.assureEJBObjectInterface(remoteInterfaceName, ejbModule.getClassLoader());
+ assureEJBObjectInterface(remoteInterfaceName, ejbModule.getClassLoader());
gbean.setAttribute(EjbInterface.REMOTE.getAttributeName(), remoteInterfaceName);
String homeInterfaceName = remoteBean.getHome();
- RemoteEjbRefBuilder.assureEJBHomeInterface(homeInterfaceName, ejbModule.getClassLoader());
+ assureEJBHomeInterface(homeInterfaceName, ejbModule.getClassLoader());
gbean.setAttribute(EjbInterface.HOME.getAttributeName(), homeInterfaceName);
}
// Local
if (remoteBean.getLocal() != null) {
String localInterfaceName = remoteBean.getLocal();
- LocalEjbRefBuilder.assureEJBLocalObjectInterface(localInterfaceName, ejbModule.getClassLoader());
+ assureEJBLocalObjectInterface(localInterfaceName, ejbModule.getClassLoader());
gbean.setAttribute(EjbInterface.LOCAL.getAttributeName(), localInterfaceName);
String localHomeInterfaceName = remoteBean.getLocalHome();
- LocalEjbRefBuilder.assureEJBLocalHomeInterface(localHomeInterfaceName, ejbModule.getClassLoader());
+ assureEJBLocalHomeInterface(localHomeInterfaceName, ejbModule.getClassLoader());
gbean.setAttribute(EjbInterface.LOCAL_HOME.getAttributeName(), localHomeInterfaceName);
}
@@ -310,4 +309,19 @@
return earContext.getNaming().createChildName(ejbModule.getModuleName(), ejbName, type);
}
+ private static Class assureEJBObjectInterface(String remote, ClassLoader cl) throws DeploymentException {
+ return AbstractNamingBuilder.assureInterface(remote, "javax.ejb.EJBObject", "Remote", cl);
+ }
+
+ private static Class assureEJBHomeInterface(String home, ClassLoader cl) throws DeploymentException {
+ return AbstractNamingBuilder.assureInterface(home, "javax.ejb.EJBHome", "Home", cl);
+ }
+
+ public static Class assureEJBLocalObjectInterface(String local, ClassLoader cl) throws DeploymentException {
+ return AbstractNamingBuilder.assureInterface(local, "javax.ejb.EJBLocalObject", "Local", cl);
+ }
+
+ public static Class assureEJBLocalHomeInterface(String localHome, ClassLoader cl) throws DeploymentException {
+ return AbstractNamingBuilder.assureInterface(localHome, "javax.ejb.EJBLocalHome", "LocalHome", cl);
+ }
}
Modified: geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilder.java?view=diff&rev=499248&r1=499247&r2=499248
==============================================================================
--- geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilder.java (original)
+++ geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilder.java Tue Jan 23 20:10:20 2007
@@ -20,7 +20,6 @@
import java.io.IOException;
import java.net.URI;
import java.net.URL;
-import java.net.URLClassLoader;
import java.net.MalformedURLException;
import java.util.Collection;
import java.util.Collections;
@@ -74,8 +73,6 @@
import org.apache.openejb.assembler.classic.Cmp2Builder;
import org.apache.openejb.assembler.classic.AppInfo;
import org.apache.openejb.jee.EjbJar;
-import org.apache.openejb.jee.EjbLocalRef;
-import org.apache.openejb.jee.EjbRef;
import org.apache.openejb.jee.EnterpriseBean;
import org.apache.openejb.jee.MessageDestinationRef;
import org.apache.openejb.jee.PersistenceContextRef;
@@ -134,9 +131,15 @@
}
private Module createModule(Object plan, JarFile moduleFile, String targetPath, URL specDDUrl, Environment earEnvironment, AbstractName earName, Naming naming, ModuleIDBuilder idBuilder) throws DeploymentException {
- if (moduleFile == null) throw new NullPointerException("moduleFile is null");
- if (targetPath == null) throw new NullPointerException("targetPath is null");
- if (targetPath.endsWith("/")) throw new IllegalArgumentException("targetPath must not end with a '/'");
+ if (moduleFile == null) {
+ throw new NullPointerException("moduleFile is null");
+ }
+ if (targetPath == null) {
+ throw new NullPointerException("targetPath is null");
+ }
+ if (targetPath.endsWith("/")) {
+ throw new IllegalArgumentException("targetPath must not end with a '/'");
+ }
// load the ejb-jar.xml
String ejbJarXml = XmlUtil.loadEjbJarXml(specDDUrl, moduleFile);
@@ -260,14 +263,9 @@
protected static void unmapReferences(EjbJar ejbJar) {
for (EnterpriseBean enterpriseBean : ejbJar.getEnterpriseBeans()) {
enterpriseBean.getEnvEntry().clear();
- for (EjbRef ref : enterpriseBean.getEjbRef()) {
- ref.setMappedName(null);
- ref.getInjectionTarget().clear();
- }
- for (EjbLocalRef ref : enterpriseBean.getEjbLocalRef()) {
- ref.setMappedName(null);
- ref.getInjectionTarget().clear();
- }
+ enterpriseBean.getEjbRef().clear();
+ enterpriseBean.getEjbLocalRef().clear();
+
for (MessageDestinationRef ref : enterpriseBean.getMessageDestinationRef()) {
ref.setMappedName(null);
ref.getInjectionTarget().clear();
@@ -335,6 +333,12 @@
e.printStackTrace();
throw new DeploymentException(e);
}
+ EarData earData = (EarData) earContext.getGeneralData().get(EarData.class);
+ if (earData == null) {
+ earData = new EarData();
+ earContext.getGeneralData().put(EarData.class, earData);
+ }
+ earData.getEjbJars().add(ejbJarInfo);
// generate the CMP2 implementation classes
// Generate the cmp2 concrete subclasses
@@ -430,6 +434,14 @@
// add the Jacc permissions to the ear
ComponentPermissions componentPermissions = ejbDeploymentBuilder.buildComponentPermissions();
earContext.addSecurityContext(ejbModule.getEjbJarInfo().moduleId, componentPermissions);
+ }
+
+ public static class EarData {
+ private final Collection<EjbJarInfo> ejbJars = new ArrayList<EjbJarInfo>();
+
+ public Collection<EjbJarInfo> getEjbJars() {
+ return ejbJars;
+ }
}
Modified: geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/ejbref/AbstractEjbRefBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/ejbref/AbstractEjbRefBuilder.java?view=diff&rev=499248&r1=499247&r2=499248
==============================================================================
--- geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/ejbref/AbstractEjbRefBuilder.java (original)
+++ geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/ejbref/AbstractEjbRefBuilder.java Tue Jan 23 20:10:20 2007
@@ -33,6 +33,7 @@
import org.apache.geronimo.gbean.AbstractNameQuery;
import org.apache.geronimo.gbean.GBeanData;
import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
+import org.apache.geronimo.j2ee.deployment.Module;
import org.apache.geronimo.kernel.GBeanNotFoundException;
import org.apache.geronimo.kernel.config.Configuration;
import org.apache.geronimo.kernel.repository.Artifact;
@@ -41,193 +42,52 @@
import org.apache.geronimo.openejb.EjbReference;
import org.apache.geronimo.openejb.EjbDeployment;
import org.apache.geronimo.openejb.deployment.EjbInterface;
+import org.apache.geronimo.openejb.deployment.EjbModuleBuilder;
+import org.apache.openejb.jee.JndiConsumer;
+import org.apache.openejb.alt.config.JndiEncInfoBuilder;
+import org.apache.openejb.assembler.classic.JndiEncInfo;
+import org.apache.openejb.assembler.classic.JndiEncBuilder;
+import org.apache.openejb.OpenEJBException;
/**
* @version $Rev: 451417 $ $Date: 2006-09-29 13:13:22 -0700 (Fri, 29 Sep 2006) $
*/
public abstract class AbstractEjbRefBuilder extends AbstractNamingBuilder {
- private final static Map<String, String> STATELESS = Collections.singletonMap(NameFactory.J2EE_TYPE, NameFactory.STATELESS_SESSION_BEAN);
- private final static Map<String, String> STATEFUL = Collections.singletonMap(NameFactory.J2EE_TYPE, NameFactory.STATEFUL_SESSION_BEAN);
- private final static Map<String, String> ENTITY = Collections.singletonMap(NameFactory.J2EE_TYPE, NameFactory.ENTITY_BEAN);
protected AbstractEjbRefBuilder(Environment defaultEnvironment) {
super(defaultEnvironment);
}
- protected Reference createEjbRef(String refName, Configuration configuration, String name, String requiredModule, String optionalModule, AbstractNameQuery query, boolean isSession, String homeInterface, String businessInterface, boolean remote) throws DeploymentException {
- AbstractNameQuery match = getEjbRefQuery(refName, configuration, name, requiredModule, optionalModule, query, isSession, homeInterface, businessInterface, remote);
- return new EjbReference(configuration.getId(), match, remote);
- }
-
- protected AbstractNameQuery getEjbRefQuery(String refName, Configuration configuration, String name, String requiredModule, String optionalModule, AbstractNameQuery query, boolean isSession, String homeInterface, String businessInterface, boolean remote) throws DeploymentException {
- AbstractNameQuery match;
- if (query != null) {
- if (remote) {
- checkRemoteProxyInfo(query, homeInterface, businessInterface, configuration);
- } else {
- checkLocalProxyInfo(query, homeInterface, businessInterface, configuration);
- }
- match = new AbstractNameQuery(query.getArtifact(), query.getName(), EjbDeployment.class.getName());
- } else if (name != null) {
- match = getMatch(refName, configuration, name, requiredModule, remote, isSession, homeInterface, businessInterface);
- } else {
- match = getImplicitMatch(refName, configuration, optionalModule, remote, isSession, homeInterface, businessInterface);
- }
- return match;
- }
-
- private AbstractNameQuery getMatch(String refName, Configuration context, String name, String module, boolean isRemote, boolean isSession, String home, String remote) throws DeploymentException {
- Map<String, String> nameQuery = new HashMap<String, String>();
- nameQuery.put(NameFactory.J2EE_NAME, name);
- if (module != null) {
- nameQuery.put(NameFactory.EJB_MODULE, module);
- }
- Artifact id = context.getId();
- Collection<AbstractName> matches = getMatchesFromName(isSession, nameQuery, context, id, isRemote, home, remote);
- if (matches.isEmpty()) {
- matches = getMatchesFromName(isSession, nameQuery, context, null, isRemote, home, remote);
- }
- if (matches.isEmpty()) {
- throw new UnresolvedEJBRefException(refName, !isRemote, isSession, home, remote, false);
- }
- AbstractName match;
- if (matches.size() == 1) {
- match = matches.iterator().next();
- } else {
- throw new UnresolvedEJBRefException(refName, !isRemote, isSession, home, remote, matches.size() > 0);
- }
- return new AbstractNameQuery(stripVersion(match.getArtifact()), match.getName(), EjbDeployment.class.getName());
- }
-
- private Collection<AbstractName> getMatchesFromName(boolean isSession, Map<String, String> nameQuery, Configuration context, Artifact id, boolean isRemote, String home, String remote) {
- Set<GBeanData> gbeanDatas = new HashSet<GBeanData>();
- if (isSession) {
- Map<String, String> q = new HashMap<String, String>(nameQuery);
- q.putAll(STATELESS);
- gbeanDatas.addAll(findGBeanDatas(context, id, q));
-
- q = new HashMap<String, String>(nameQuery);
- q.putAll(STATEFUL);
- gbeanDatas.addAll(findGBeanDatas(context, id, q));
- } else {
- Map<String, String> q = new HashMap<String, String>(nameQuery);
- q.putAll(ENTITY);
- gbeanDatas.addAll(findGBeanDatas(context, id, q));
- }
-
- Collection<AbstractName> matches = new ArrayList<AbstractName>();
- for (GBeanData data : gbeanDatas) {
- if (matchesProxyInfo(data, isRemote, home, remote)) {
- matches.add(data.getAbstractName());
- }
- }
- return matches;
- }
-
- @SuppressWarnings({"unchecked"})
- private Collection<GBeanData> findGBeanDatas(Configuration context, Artifact id, Map<String, String> q) {
- return context.findGBeanDatas(Collections.singleton(new AbstractNameQuery(id, q, EjbDeployment.class.getName())));
- }
-
- private AbstractNameQuery getImplicitMatch(String refName, Configuration context, String module, boolean isRemote, boolean isSession, String home, String remote) throws DeploymentException {
- Collection<AbstractName> matches = getMatchesFromName(isSession, Collections.<String, String>emptyMap(), context, context.getId(), isRemote, home, remote);
- if (matches.isEmpty()) {
- matches = getMatchesFromName(isSession, Collections.<String, String>emptyMap(), context, null, isRemote, home, remote);
- }
- if (matches.isEmpty()) {
- throw new UnresolvedEJBRefException(refName, false, isSession, home, remote, false);
- }
- AbstractName match;
- if (matches.size() == 1) {
- match = matches.iterator().next();
- } else {
- for (Iterator<AbstractName> iterator = matches.iterator(); iterator.hasNext();) {
- AbstractName objectName = iterator.next();
- if (module != null && !(objectName.getName().get(NameFactory.EJB_MODULE).equals(module))) {
- iterator.remove();
- }
- }
- if (matches.size() == 1) {
- match = matches.iterator().next();
- } else {
- throw new UnresolvedEJBRefException(refName, false, isSession, home, remote, matches.size() > 0);
- }
- }
- return new AbstractNameQuery(match);
- }
-
- private boolean matchesProxyInfo(GBeanData data, boolean isRemote, String home, String remote) {
- if (isRemote) {
- return home.equals(getHomeInterface(data)) && remote.equals(getRemoteInterface(data));
- } else {
- return home.equals(getLocalHomeInterface(data)) && remote.equals(getLocalInterface(data));
- }
- }
-
- private void checkLocalProxyInfo(AbstractNameQuery query, String expectedLocalHome, String expectedLocal, Configuration configuration) throws DeploymentException {
+ protected void bindContext(Module module, JndiConsumer jndiConsumer, Map componentContext) throws DeploymentException {
+ Map<String, Object> map = null;
try {
- GBeanData data = configuration.findGBeanData(query);
-
- String actualLocalHome = getLocalHomeInterface(data);
- String actualLocal = getLocalInterface(data);
- if (actualLocalHome == null || actualLocal == null) {
- // EJBs like the MEJB don't have interfaces declared in the gbean data
- return;
- }
-
- if (!expectedLocalHome.equals(actualLocalHome) || !expectedLocal.equals(actualLocal)) {
- throw new DeploymentException("Reference interfaces do not match bean interfaces:\n" +
- "reference localHome: " + expectedLocalHome + "\n" +
- "ejb localHome: " + actualLocalHome + "\n" +
- "reference local: " + expectedLocal + "\n" +
- "ejb local: " + getLocalInterface(data));
- }
- } catch (GBeanNotFoundException e) {
- throw new DeploymentException("Could not locate ejb matching " + query + " in configuration " + configuration.getId());
+ EjbModuleBuilder.EarData earData = (EjbModuleBuilder.EarData) module.getEarContext().getGeneralData().get(EjbModuleBuilder.EarData.class);
+ JndiEncInfoBuilder jndiEncInfoBuilder = new JndiEncInfoBuilder(earData.getEjbJars());
+ JndiEncInfo jndiEncInfo = jndiEncInfoBuilder.build(jndiConsumer, "GeronimoEnc");
+ JndiEncBuilder jndiEncBuilder = new JndiEncBuilder(jndiEncInfo);
+ map = jndiEncBuilder.buildMap();
+ } catch (OpenEJBException e) {
+ throw new DeploymentException(e);
}
- }
- private void checkRemoteProxyInfo(AbstractNameQuery query, String expectedHome, String expectedRemote, Configuration configuration) throws DeploymentException {
- try {
- GBeanData data = configuration.findGBeanData(query);
+ for (Map.Entry<String, Object> entry : map.entrySet()) {
+ String name = entry.getKey();
+ Object value = entry.getValue();
- String actualHome = getHomeInterface(data);
- String actualRemote = getRemoteInterface(data);
- if (actualHome == null || actualRemote == null) {
- // EJBs like the MEJB don't have interfaces declared in the gbean data
- return;
+ // work with names prefixed with java:comp/
+ if (name.startsWith("java:comp/")) {
+ name = name.substring("java:comp/".length());
}
- if (!expectedHome.equals(actualHome) || !expectedRemote.equals(actualRemote)) {
- throw new DeploymentException("Reference interfaces do not match bean interfaces:\n" +
- "reference home: " + expectedHome + "\n" +
- "ejb home: " + actualHome + "\n" +
- "reference remote: " + expectedRemote + "\n" +
- "ejb remote: " + actualRemote);
+ // if this is a ref it will be prefixed with env/
+ if (name.startsWith("env/")) {
+ getJndiContextMap(componentContext).put(name, wrapReference(value));
}
- } catch (GBeanNotFoundException e) {
- // we can't verify remote ejb refs if the GBean can't be found
- // could be a reference to an ejb in another application that hasn't been loaded yet
}
}
- private static Artifact stripVersion(Artifact artifact) {
- return new Artifact(artifact.getGroupId(), artifact.getArtifactId(), (String) null, artifact.getType());
- }
-
- private static String getHomeInterface(GBeanData data) {
- return (String) data.getAttribute(EjbInterface.HOME.getAttributeName());
- }
-
- private static String getRemoteInterface(GBeanData data) {
- return (String) data.getAttribute(EjbInterface.REMOTE.getAttributeName());
- }
-
- private static String getLocalHomeInterface(GBeanData data) {
- return (String) data.getAttribute(EjbInterface.LOCAL_HOME.getAttributeName());
- }
-
- private static String getLocalInterface(GBeanData data) {
- return (String) data.getAttribute(EjbInterface.LOCAL.getAttributeName());
+ // this method exists so client refs can be made remote
+ protected Object wrapReference(Object value) {
+ return value;
}
}
Modified: geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/ejbref/ClientEjbRefBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/ejbref/ClientEjbRefBuilder.java?view=diff&rev=499248&r1=499247&r2=499248
==============================================================================
--- geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/ejbref/ClientEjbRefBuilder.java (original)
+++ geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/ejbref/ClientEjbRefBuilder.java Tue Jan 23 20:10:20 2007
@@ -19,18 +19,13 @@
import java.net.URI;
import java.net.URISyntaxException;
-import javax.naming.Reference;
-import org.apache.geronimo.common.DeploymentException;
-import org.apache.geronimo.gbean.AbstractNameQuery;
-import org.apache.geronimo.gbean.GBeanData;
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GBeanInfoBuilder;
import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
-import org.apache.geronimo.kernel.GBeanNotFoundException;
-import org.apache.geronimo.kernel.config.Configuration;
import org.apache.geronimo.kernel.repository.Environment;
import org.apache.geronimo.openejb.ClientEjbReference;
+import org.apache.openejb.core.ivm.naming.IntraVmJndiReference;
/**
* @version $Rev: 451417 $ $Date: 2006-09-29 13:13:22 -0700 (Fri, 29 Sep 2006) $
@@ -43,21 +38,14 @@
uri = new URI("ejb", null, host, port, null, null, null);
}
- protected Reference createEjbRef(String refName, Configuration configuration, String name, String requiredModule, String optionalModule, AbstractNameQuery query, boolean isSession, String homeInterface, String businessInterface, boolean remote) throws DeploymentException {
- AbstractNameQuery match = getEjbRefQuery(refName, configuration, name, requiredModule, optionalModule, query, isSession, homeInterface, businessInterface, remote);
-
- GBeanData data = null;
- try {
- data = configuration.findGBeanData(match);
- } catch (GBeanNotFoundException ignored) {
- throw new DeploymentException("Ejb not found for ejb-ref " + refName);
- }
-
- String deploymentId = (String) data.getAttribute("deploymentId");
- if (deploymentId == null) {
- throw new DeploymentException(("EjbDeployment GBeanData does not contain a \"deploymentId\" attribute"));
+ protected Object wrapReference(Object value) {
+ IntraVmJndiReference intraVmJndiReference = (IntraVmJndiReference) value;
+ String deploymentId = intraVmJndiReference.getJndiName();
+ if (deploymentId.startsWith("java:openejb/ejb/")) {
+ deploymentId = deploymentId.substring("java:openejb/ejb/".length());
}
- return new ClientEjbReference(uri.toString(), deploymentId);
+ ClientEjbReference clientRef = new ClientEjbReference(uri.toString(), deploymentId);
+ return clientRef;
}
public static final GBeanInfo GBEAN_INFO;
Modified: geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/ejbref/LocalEjbRefBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/ejbref/LocalEjbRefBuilder.java?view=diff&rev=499248&r1=499247&r2=499248
==============================================================================
--- geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/ejbref/LocalEjbRefBuilder.java (original)
+++ geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/ejbref/LocalEjbRefBuilder.java Tue Jan 23 20:10:20 2007
@@ -36,8 +36,15 @@
import org.apache.geronimo.xbeans.geronimo.naming.GerEjbLocalRefType;
import org.apache.geronimo.xbeans.geronimo.naming.GerPatternType;
import org.apache.geronimo.xbeans.javaee.EjbLocalRefType;
+import org.apache.geronimo.xbeans.javaee.EjbRefType;
+import org.apache.geronimo.xbeans.javaee.InjectionTargetType;
import org.apache.xmlbeans.QNameSet;
import org.apache.xmlbeans.XmlObject;
+import org.apache.openejb.jee.JndiConsumer;
+import org.apache.openejb.jee.ApplicationClient;
+import org.apache.openejb.jee.EjbRef;
+import org.apache.openejb.jee.InjectionTarget;
+import org.apache.openejb.jee.EjbLocalRef;
/**
* @version $Revision: 470469 $ $Date: 2006-11-02 10:43:34 -0800 (Thu, 02 Nov 2006) $
@@ -67,88 +74,49 @@
public void buildNaming(XmlObject specDD, XmlObject plan, Configuration localConfiguration, Configuration remoteConfiguration, Module module, Map componentContext) throws DeploymentException {
List<EjbLocalRefType> ejbLocalRefs = convert(specDD.selectChildren(ejbLocalRefQNameSet), J2EE_CONVERTER, EjbLocalRefType.class, EjbLocalRefType.type);
- XmlObject[] gerEjbLocalRefsUntyped = plan == null ? NO_REFS : plan.selectChildren(GER_EJB_LOCAL_REF_QNAME_SET);
- Map<String, GerEjbLocalRefType> ejbLocalRefMap = mapEjbLocalRefs(gerEjbLocalRefsUntyped);
- ClassLoader cl = module.getEarContext().getClassLoader();
-
- for (EjbLocalRefType ejbLocalRef : ejbLocalRefs) {
- String ejbRefName = getStringValue(ejbLocalRef.getEjbRefName());
- GerEjbLocalRefType localRef = ejbLocalRefMap.get(ejbRefName);
-
- Reference ejbReference = createEjbLocalRef(remoteConfiguration, module.getModuleURI(), ejbLocalRef, localRef, cl);
- if (ejbReference != null) {
- //noinspection unchecked
- getJndiContextMap(componentContext).put(ENV + ejbRefName, ejbReference);
- }
- }
- }
- private Reference createEjbLocalRef(Configuration ejbContext, URI moduleURI, EjbLocalRefType ejbLocalRef, GerEjbLocalRefType localRef, ClassLoader cl) throws DeploymentException {
- String refName = getStringValue(ejbLocalRef.getEjbRefName());
-
- String local = getStringValue(ejbLocalRef.getLocal());
- try {
- assureEJBLocalObjectInterface(local, cl);
- } catch (DeploymentException e) {
- throw new DeploymentException("Error processing 'local' element for EJB Local Reference '" + refName + "' for module '" + moduleURI + "': " + e.getMessage());
- }
+ // build jndi consumer
+ JndiConsumer jndiConsumer = new ApplicationClient();
+ for (EjbLocalRefType xmlbeansRef : ejbLocalRefs) {
+ // create the ejb-ref
+ EjbLocalRef ref = new EjbLocalRef();
+ jndiConsumer.getEjbLocalRef().add(ref);
+
+ // ejb-ref-name
+ ref.setEjbRefName(getStringValue(xmlbeansRef.getEjbRefName()));
+
+ // ejb-ref-type
+ String refType = getStringValue(xmlbeansRef.getEjbRefType());
+ if ("SESSION".equalsIgnoreCase(refType)) {
+ ref.setEjbRefType(org.apache.openejb.jee.EjbRefType.SESSION);
+ } else if ("ENTITY".equalsIgnoreCase(refType)) {
+ ref.setEjbRefType(org.apache.openejb.jee.EjbRefType.ENTITY);
+ }
- String localHome = getStringValue(ejbLocalRef.getLocalHome());
- try {
- assureEJBLocalHomeInterface(localHome, cl);
- } catch (DeploymentException e) {
- throw new DeploymentException("Error processing 'local-home' element for EJB Local Reference '" + refName + "' for module '" + moduleURI + "': " + e.getMessage());
- }
+ // home
+ ref.setLocalHome(getStringValue(xmlbeansRef.getLocalHome()));
- boolean isSession = "Session".equals(getStringValue(ejbLocalRef.getEjbRefType()));
+ // remote
+ ref.setLocal(getStringValue(xmlbeansRef.getLocal()));
- String ejbLink = null;
- if (localRef != null && localRef.isSetEjbLink()) {
- ejbLink = localRef.getEjbLink();
- } else if (ejbLocalRef.isSetEjbLink()) {
- ejbLink = getStringValue(ejbLocalRef.getEjbLink());
- }
+ // ejb-link
+ ref.setEjbLink(getStringValue(xmlbeansRef.getEjbLink()));
- String optionalModule;
- if (moduleURI == null) {
- optionalModule = null;
- } else {
- optionalModule = moduleURI.toString();
- }
-
- String requiredModule = null;
- AbstractNameQuery containerQuery = null;
- if (ejbLink != null) {
- String[] bits = ejbLink.split("#");
- if (bits.length == 2) {
- //look only in specified module.
- requiredModule = bits[0];
- ejbLink = bits[1];
- }
- } else if (localRef != null) {
- GerPatternType patternType = localRef.getPattern();
- containerQuery = buildAbstractNameQuery(patternType, null, NameFactory.EJB_MODULE, null);
- }
- return createEjbRef(refName, ejbContext, ejbLink, requiredModule, optionalModule, containerQuery, isSession, localHome, local, false);
- }
-
- private static Map<String, GerEjbLocalRefType> mapEjbLocalRefs(XmlObject[] refs) {
- Map<String, GerEjbLocalRefType> refMap = new HashMap<String, GerEjbLocalRefType>();
- if (refs != null) {
- for (int i = 0; i < refs.length; i++) {
- GerEjbLocalRefType ref = (GerEjbLocalRefType) refs[i].copy().changeType(GerEjbLocalRefType.type);
- refMap.put(ref.getRefName().trim(), ref);
+ // mapped-name
+ ref.setMappedName(getStringValue(xmlbeansRef.getMappedName()));
+
+ // injection-targets
+ if (xmlbeansRef.getInjectionTargetArray() != null) {
+ for (InjectionTargetType injectionTargetType : xmlbeansRef.getInjectionTargetArray()) {
+ InjectionTarget injectionTarget = new InjectionTarget();
+ injectionTarget.setInjectionTargetClass(getStringValue(injectionTargetType.getInjectionTargetClass()));
+ injectionTarget.setInjectionTargetName(getStringValue(injectionTargetType.getInjectionTargetName()));
+ ref.getInjectionTarget().add(injectionTarget);
+ }
}
}
- return refMap;
- }
-
- public static Class assureEJBLocalObjectInterface(String local, ClassLoader cl) throws DeploymentException {
- return assureInterface(local, "javax.ejb.EJBLocalObject", "Local", cl);
- }
- public static Class assureEJBLocalHomeInterface(String localHome, ClassLoader cl) throws DeploymentException {
- return assureInterface(localHome, "javax.ejb.EJBLocalHome", "LocalHome", cl);
+ bindContext(module, jndiConsumer, componentContext);
}
public static final GBeanInfo GBEAN_INFO;
Modified: geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/ejbref/RemoteEjbRefBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/ejbref/RemoteEjbRefBuilder.java?view=diff&rev=499248&r1=499247&r2=499248
==============================================================================
--- geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/ejbref/RemoteEjbRefBuilder.java (original)
+++ geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/ejbref/RemoteEjbRefBuilder.java Tue Jan 23 20:10:20 2007
@@ -17,16 +17,11 @@
package org.apache.geronimo.openejb.deployment.ejbref;
-import java.net.URI;
-import java.util.Collections;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import javax.naming.Reference;
import javax.xml.namespace.QName;
import org.apache.geronimo.common.DeploymentException;
-import org.apache.geronimo.gbean.AbstractNameQuery;
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GBeanInfoBuilder;
import org.apache.geronimo.j2ee.deployment.Module;
@@ -34,9 +29,12 @@
import org.apache.geronimo.kernel.config.Configuration;
import org.apache.geronimo.kernel.repository.Environment;
import org.apache.geronimo.xbeans.geronimo.naming.GerEjbRefDocument;
-import org.apache.geronimo.xbeans.geronimo.naming.GerEjbRefType;
-import org.apache.geronimo.xbeans.geronimo.naming.GerPatternType;
import org.apache.geronimo.xbeans.javaee.EjbRefType;
+import org.apache.geronimo.xbeans.javaee.InjectionTargetType;
+import org.apache.openejb.jee.ApplicationClient;
+import org.apache.openejb.jee.EjbRef;
+import org.apache.openejb.jee.InjectionTarget;
+import org.apache.openejb.jee.JndiConsumer;
import org.apache.xmlbeans.QNameSet;
import org.apache.xmlbeans.XmlObject;
@@ -67,103 +65,54 @@
}
public void buildNaming(XmlObject specDD, XmlObject plan, Configuration localConfiguration, Configuration remoteConfiguration, Module module, Map componentContext) throws DeploymentException {
- List<EjbRefType> ejbRefs = convert(specDD.selectChildren(ejbRefQNameSet), J2EE_CONVERTER, EjbRefType.class, EjbRefType.type);
- XmlObject[] gerEjbRefsUntyped = plan == null ? NO_REFS : plan.selectChildren(GER_EJB_REF_QNAME_SET);
- Map<String, GerEjbRefType> ejbRefMap = mapEjbRefs(gerEjbRefsUntyped);
- ClassLoader cl = module.getEarContext().getClassLoader();
-
- for (EjbRefType ejbRef : ejbRefs) {
- String ejbRefName = getStringValue(ejbRef.getEjbRefName());
- GerEjbRefType remoteRef = ejbRefMap.get(ejbRefName);
-
- Reference ejbReference = createEjbRef(remoteConfiguration, module.getModuleURI(), ejbRef, remoteRef, cl);
- if (ejbReference != null) {
- //noinspection unchecked
- getJndiContextMap(componentContext).put(ENV + ejbRefName, ejbReference);
- }
- }
+ JndiConsumer jndiConsumer = createJndiConsumer(specDD);
+ bindContext(module, jndiConsumer, componentContext);
}
- private Reference createEjbRef(Configuration ejbContext, URI moduleURI, EjbRefType ejbRef, GerEjbRefType remoteRef, ClassLoader cl) throws DeploymentException {
- String refName = getStringValue(ejbRef.getEjbRefName());
-
- String remote = getStringValue(ejbRef.getRemote());
- try {
- assureEJBObjectInterface(remote, cl);
- } catch (DeploymentException e) {
- throw new DeploymentException("Error processing 'remote' element for EJB Reference '" + refName + "' for module '" + moduleURI + "': " + e.getMessage());
- }
-
- String home = getStringValue(ejbRef.getHome());
- try {
- assureEJBHomeInterface(home, cl);
- } catch (DeploymentException e) {
- throw new DeploymentException("Error processing 'home' element for EJB Reference '" + refName + "' for module '" + moduleURI + "': " + e.getMessage());
- }
-
- boolean isSession = "Session".equals(getStringValue(ejbRef.getEjbRefType()));
+ protected JndiConsumer createJndiConsumer(XmlObject specDD) throws DeploymentException {
+ List<EjbRefType> ejbRefs = convert(specDD.selectChildren(ejbRefQNameSet), J2EE_CONVERTER, EjbRefType.class, EjbRefType.type);
- // MEJB
- if (isSession && remote.equals("javax.management.j2ee.Management") && home.equals("javax.management.j2ee.ManagementHome")) {
- AbstractNameQuery query = new AbstractNameQuery(null, Collections.singletonMap("name", "ejb/mgmt/MEJB"));
- return createEjbRef(null, ejbContext, null, null, null, query, isSession, home, remote, true);
- }
+ // build jndi consumer
+ JndiConsumer jndiConsumer = new ApplicationClient();
+ for (EjbRefType xmlbeansRef : ejbRefs) {
+ // create the ejb-ref
+ EjbRef ref = new EjbRef();
+ jndiConsumer.getEjbRef().add(ref);
+
+ // ejb-ref-name
+ ref.setEjbRefName(getStringValue(xmlbeansRef.getEjbRefName()));
+
+ // ejb-ref-type
+ String refType = getStringValue(xmlbeansRef.getEjbRefType());
+ if ("SESSION".equalsIgnoreCase(refType)) {
+ ref.setEjbRefType(org.apache.openejb.jee.EjbRefType.SESSION);
+ } else if ("ENTITY".equalsIgnoreCase(refType)) {
+ ref.setEjbRefType(org.apache.openejb.jee.EjbRefType.ENTITY);
+ }
- // corba refs are handled by another builder
- if (remoteRef != null && remoteRef.isSetNsCorbaloc()) {
- return null;
- }
+ // home
+ ref.setHome(getStringValue(xmlbeansRef.getHome()));
- String ejbLink = null;
- if (remoteRef != null && remoteRef.isSetEjbLink()) {
- ejbLink = remoteRef.getEjbLink();
- } else if (ejbRef.isSetEjbLink()) {
- ejbLink = getStringValue(ejbRef.getEjbLink());
- }
+ // remote
+ ref.setRemote(getStringValue(xmlbeansRef.getRemote()));
- String optionalModule;
- if (moduleURI == null) {
- optionalModule = null;
- } else {
- optionalModule = moduleURI.toString();
- }
+ // ejb-link
+ ref.setEjbLink(getStringValue(xmlbeansRef.getEjbLink()));
- String requiredModule = null;
- AbstractNameQuery containerQuery = null;
- if (ejbLink != null) {
- String[] bits = ejbLink.split("#");
- if (bits.length == 2) {
- //look only in specified module.
- requiredModule = bits[0];
- if (moduleURI != null) {
- requiredModule = moduleURI.resolve(requiredModule).getPath();
+ // mapped-name
+ ref.setMappedName(getStringValue(xmlbeansRef.getMappedName()));
+
+ // injection-targets
+ if (xmlbeansRef.getInjectionTargetArray() != null) {
+ for (InjectionTargetType injectionTargetType : xmlbeansRef.getInjectionTargetArray()) {
+ InjectionTarget injectionTarget = new InjectionTarget();
+ injectionTarget.setInjectionTargetClass(getStringValue(injectionTargetType.getInjectionTargetClass()));
+ injectionTarget.setInjectionTargetName(getStringValue(injectionTargetType.getInjectionTargetName()));
+ ref.getInjectionTarget().add(injectionTarget);
}
- ejbLink = bits[1];
}
- } else if (remoteRef != null) {
- GerPatternType patternType = remoteRef.getPattern();
- containerQuery = buildAbstractNameQuery(patternType, null, NameFactory.EJB_MODULE, null);
}
- return createEjbRef(refName, ejbContext, ejbLink, requiredModule, optionalModule, containerQuery, isSession, home, remote, true);
- }
-
- private static Map<String, GerEjbRefType> mapEjbRefs(XmlObject[] refs) {
- Map<String, GerEjbRefType> refMap = new HashMap<String, GerEjbRefType>();
- if (refs != null) {
- for (int i = 0; i < refs.length; i++) {
- GerEjbRefType ref = (GerEjbRefType) refs[i].copy().changeType(GerEjbRefType.type);
- refMap.put(ref.getRefName().trim(), ref);
- }
- }
- return refMap;
- }
-
- public static Class assureEJBObjectInterface(String remote, ClassLoader cl) throws DeploymentException {
- return assureInterface(remote, "javax.ejb.EJBObject", "Remote", cl);
- }
-
- public static Class assureEJBHomeInterface(String home, ClassLoader cl) throws DeploymentException {
- return assureInterface(home, "javax.ejb.EJBHome", "Home", cl);
+ return jndiConsumer;
}
public static final GBeanInfo GBEAN_INFO;