[jboss-cvs] JBossAS SVN: r73671 - in projects/ejb3/trunk/proxy/src: main/java/org/jboss/ejb3/proxy/objectstore and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sun May 25 20:24:21 EDT 2008
Author: ALRubinger
Date: 2008-05-25 20:24:21 -0400 (Sun, 25 May 2008)
New Revision: 73671
Added:
projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/jndiregistrar/JndiSessionRegistrarBase.java
projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/jndiregistrar/JndiStatefulSessionRegistrar.java
projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/jndiregistrar/JndiStatelessSessionRegistrar.java
Removed:
projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/jndiregistrar/JndiRegistrar.java
Modified:
projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/objectstore/ObjectStoreBindings.java
projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/container/SessionContainer.java
projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/container/StatefulContainer.java
projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/container/StatelessContainer.java
projects/ejb3/trunk/proxy/src/test/resources/log4j.xml
projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/session/unit/ProxySessionTestCase-beans.xml
Log:
[EJBTHREE-1345] Use Polymorphism for JndiRegistrar, implement for SFSB
Deleted: projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/jndiregistrar/JndiRegistrar.java
===================================================================
--- projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/jndiregistrar/JndiRegistrar.java 2008-05-25 12:33:17 UTC (rev 73670)
+++ projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/jndiregistrar/JndiRegistrar.java 2008-05-26 00:24:21 UTC (rev 73671)
@@ -1,618 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.proxy.jndiregistrar;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.naming.Context;
-import javax.naming.NamingException;
-import javax.naming.RefAddr;
-import javax.naming.Reference;
-import javax.naming.StringRefAddr;
-import javax.naming.spi.ObjectFactory;
-
-import org.jboss.ejb3.common.registrar.spi.DuplicateBindException;
-import org.jboss.ejb3.common.registrar.spi.Ejb3RegistrarLocator;
-import org.jboss.ejb3.common.string.StringUtils;
-import org.jboss.ejb3.proxy.factory.ProxyFactory;
-import org.jboss.ejb3.proxy.factory.session.stateless.StatelessSessionLocalProxyFactory;
-import org.jboss.ejb3.proxy.factory.session.stateless.StatelessSessionRemoteProxyFactory;
-import org.jboss.ejb3.proxy.objectfactory.ProxyFactoryReferenceAddressTypes;
-import org.jboss.logging.Logger;
-import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
-import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
-import org.jboss.metadata.ejb.spec.BusinessLocalsMetaData;
-import org.jboss.metadata.ejb.spec.BusinessRemotesMetaData;
-import org.jboss.naming.Util;
-import org.jboss.util.NotImplementedException;
-
-/**
- * JndiRegistrar
- *
- * Responsible for binding of ObjectFactories and
- * creation/registration of associated ProxyFactories
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-public class JndiRegistrar
-{
- // --------------------------------------------------------------------------------||
- // Class Members ------------------------------------------------------------------||
- // --------------------------------------------------------------------------------||
-
- private static final Logger log = Logger.getLogger(JndiRegistrar.class);
-
- /**
- * The value appended to the key used to bind proxy factories to the registry
- */
- private static final String KEY_SUFFIX_PROXY_FACTORY_REGISTRY = "/ProxyFactory";
-
- /**
- * The value appended to the key used to bind local proxy factories to the registry
- */
- private static final String KEY_SUFFIX_PROXY_FACTORY_REGISTRY_LOCAL = JndiRegistrar.KEY_SUFFIX_PROXY_FACTORY_REGISTRY
- + "/local";
-
- /**
- * The value appended to the key used to bind local remote factories to the registry
- */
- private static final String KEY_SUFFIX_PROXY_FACTORY_REGISTRY_REMOTE = JndiRegistrar.KEY_SUFFIX_PROXY_FACTORY_REGISTRY
- + "/remote";
-
- private static final String OBJECT_FACTORY_CLASSNAME_PREFIX = "Proxy for: ";
-
- // --------------------------------------------------------------------------------||
- // Instance Members ---------------------------------------------------------------||
- // --------------------------------------------------------------------------------||
-
- /**
- * Context under which we'll bind to JNDI
- */
- private Context context;
-
- /**
- * Fully-qualified class name of the JNDI Object Factory to Reference for SLSBs
- */
- private String statelessSessionProxyObjectFactoryType;
-
- //TODO @Service, SFSB
-
- // --------------------------------------------------------------------------------||
- // Constructor --------------------------------------------------------------------||
- // --------------------------------------------------------------------------------||
-
- /**
- * Creates a JNDI Deployer from the specified configuration properties, none of
- * which may be null.
- *
- * @param context The JNDI Context into which Objects will be bound
- * @param statelessSessionProxyObjectFactoryType String representation of the JNDI Object Factory to use for SLSBs
- */
- public JndiRegistrar(final Context context, String statelessSessionProxyObjectFactoryType)
- {
- // Set the Context
- assert context != null : this + " may not be configured with null " + Context.class.getName();
- this.setContext(context);
- log.debug("Using " + Context.class.getName() + ": " + context);
-
- /*
- * Perform some assertions and logging
- */
-
- // Set the SLSB Proxy Object Factory Type
- assert statelessSessionProxyObjectFactoryType != null && !statelessSessionProxyObjectFactoryType.equals("") : "SLSB Proxy "
- + ObjectFactory.class.getSimpleName() + " must be specified.";
- this.setStatelessSessionProxyObjectFactoryType(statelessSessionProxyObjectFactoryType);
- log.debug("Using SLSB JNDI " + ObjectFactory.class.getSimpleName() + ": "
- + this.getStatelessSessionProxyObjectFactoryType());
- }
-
- // --------------------------------------------------------------------------------||
- // Functional Methods -------------------------------------------------------------||
- // --------------------------------------------------------------------------------||
-
- /**
- * Binds into JNDI all appropriate objects required
- * by the EJB described by the specified metadata. Additionally
- * responsible for creation and registration of any all ProxyFactory
- * implementations required by the EJB
- *
- * @param md
- * @param cl The CL of the Container
- * @param containerName The name under which the target container is registered
- */
- public void bindEjb(final JBossEnterpriseBeanMetaData md, final ClassLoader cl, final String containerName)
- {
- // If we've got a SessionBean
- if (md.isSession())
- {
- // Assert castable
- assert (md instanceof JBossSessionBeanMetaData) : md + " claims to be a Session Bean but is not of type "
- + JBossSessionBeanMetaData.class.getName();
- JBossSessionBeanMetaData smd = null;
- try
- {
- smd = JBossSessionBeanMetaData.class.cast(md);
- }
- catch (ClassCastException cce)
- {
- throw new RuntimeException(md + " claiming to be Session Bean could not be cast to "
- + JBossSessionBeanMetaData.class.getName(), cce);
- }
-
- // Delegate out to session-specific handling
- log.debug("Found Session Bean: " + smd.getEjbName());
- this.bindSessionEjb(smd, cl, containerName);
- }
-
- //TODO If this is @Service
- else if (md.isService())
- {
- //TODO @Service Impl
- return;
- }
- // Does not report itself as a supported bean type
- else
- {
- // Should not be reached
- throw new RuntimeException(md
- + " reports that it is not Session, Service, or Message-Driven; it must be one of these.");
- }
- }
-
- /**
- * Binds into JNDI all objects appropriate for the Session Bean
- * described by the specified metadata
- *
- * @param smd
- * @param cl The classloader associated with the Container
- * described by the specified metadata
- * @param The name under which the target container is registered
- */
- protected void bindSessionEjb(JBossSessionBeanMetaData smd, ClassLoader cl, String containerName)
- {
- // If Stateful
- if (smd.isStateful())
- {
- //TODO Implement SFSB
- throw new NotImplementedException("ALR");
- }
- // If Stateless
- else if (smd.isStateless())
- {
- //TODO
- /*
- * Externalize most of this logic in another
- * method such that it may be reused for SFSB; this
- * is gross :)
- */
-
- // Get Business Locals
- BusinessLocalsMetaData businessLocals = smd.getBusinessLocals();
-
- // Get Business Remotes
- BusinessRemotesMetaData businessRemotes = smd.getBusinessRemotes();
-
- // Get Local Home
- String localHome = StringUtils.adjustWhitespaceStringToNull(smd.getLocalHome());
-
- // Get Remote Home
- String remoteHome = StringUtils.adjustWhitespaceStringToNull(smd.getHome());
-
- // Determine if there are local/remote views
- boolean hasLocalView = (localHome != null || businessLocals.size() < 1);
- boolean hasRemoteView = (remoteHome != null || businessRemotes.size() < 1);
-
- // If no local or remote views
- if (!hasLocalView && !hasRemoteView)
- {
- throw new RuntimeException("EJB " + smd.getEjbName() + " has no local or remote views defined.");
- }
-
- /*
- * Create and Register Proxy Factories
- */
-
- // If there's a local view
- String localProxyFactoryKey = null;
- if (hasLocalView)
- {
- // Create and register a local proxy factory
- ProxyFactory factory = new StatelessSessionLocalProxyFactory(smd, cl);
- localProxyFactoryKey = this.registerProxyFactory(factory, smd, true);
- }
-
- // If there's a remote view
- String remoteProxyFactoryKey = null;
- if (hasRemoteView)
- {
- // Create and register a local proxy factory
- ProxyFactory factory = new StatelessSessionRemoteProxyFactory(smd, cl);
- remoteProxyFactoryKey = this.registerProxyFactory(factory, smd, false);
- }
-
- /*
- * Bind Remote ObjectFactories to JNDI
- */
-
- if (hasRemoteView)
- {
-
- // Initialize Reference Addresses to attach to default remote JNDI Reference
- List<RefAddr> refAddrsForDefaultRemote = new ArrayList<RefAddr>();
-
- // For each of the remote business interfaces, make a Reference Address
- for (String businessRemote : businessRemotes)
- {
- RefAddr refAddr = new StringRefAddr(
- ProxyFactoryReferenceAddressTypes.REF_ADDR_TYPE_PROXY_BUSINESS_INTERFACE_REMOTE, businessRemote);
- refAddrsForDefaultRemote.add(refAddr);
- }
-
- // Determine if remote home and business remotes are bound to same JNDI Address
- boolean bindRemoteAndHomeTogether = this.isHomeAndBusinessBoundTogether(smd, false);
- if (bindRemoteAndHomeTogether)
- {
- // Add a Reference Address for the Remote Home
- RefAddr refAddr = new StringRefAddr(
- ProxyFactoryReferenceAddressTypes.REF_ADDR_TYPE_PROXY_EJB2x_INTERFACE_HOME_REMOTE, smd.getHome());
- refAddrsForDefaultRemote.add(refAddr);
- }
- // Bind Home (not bound together) if exists
- else if (smd.getHome() != null && !smd.getHome().equals(""))
- {
- String homeType = smd.getHome();
- RefAddr refAddr = new StringRefAddr(
- ProxyFactoryReferenceAddressTypes.REF_ADDR_TYPE_PROXY_EJB2x_INTERFACE_HOME_REMOTE, homeType);
- Reference homeRef = new Reference(JndiRegistrar.OBJECT_FACTORY_CLASSNAME_PREFIX + homeType, this
- .getStatelessSessionProxyObjectFactoryType(), null);
- homeRef.add(refAddr);
- String homeAddress = smd.determineResolvedJndiName(homeType);
- log.debug("Remote Home View for EJB " + smd.getEjbName() + " to be bound into JNDI at \"" + homeAddress
- + "\"");
- this.bind(homeRef, homeAddress, remoteProxyFactoryKey, containerName);
- }
-
- /*
- * Bind ObjectFactory for default remote businesses (and home if bound together)
- */
-
- // Get Classname to set for Reference
- String defaultRemoteClassName = this.getHumanReadableListOfInterfacesInRefAddrs(refAddrsForDefaultRemote);
-
- // Create a Reference
- Reference defaultRemoteRef = new Reference(JndiRegistrar.OBJECT_FACTORY_CLASSNAME_PREFIX
- + defaultRemoteClassName, this.getStatelessSessionProxyObjectFactoryType(), null);
-
- // Add all Reference Addresses for Default Remote Reference
- for (RefAddr refAddr : refAddrsForDefaultRemote)
- {
- log.debug("Adding " + RefAddr.class.getSimpleName() + " to Default Remote "
- + Reference.class.getSimpleName() + ": Type \"" + refAddr.getType() + "\", Content \""
- + refAddr.getContent() + "\"");
- defaultRemoteRef.add(refAddr);
- }
-
- // Bind the Default Remote Reference to JNDI
- String defaultRemoteAddress = smd.determineJndiName();
- log.debug("Default Remote View for EJB " + smd.getEjbName() + " to be bound into JNDI at \""
- + defaultRemoteAddress + "\"");
- this.bind(defaultRemoteRef, defaultRemoteAddress, remoteProxyFactoryKey, containerName);
-
- // Bind ObjectFactory specific to each Remote Business Interface
- for (String businessRemote : businessRemotes)
- {
- RefAddr refAddr = new StringRefAddr(
- ProxyFactoryReferenceAddressTypes.REF_ADDR_TYPE_PROXY_BUSINESS_INTERFACE_REMOTE, businessRemote);
- Reference ref = new Reference(JndiRegistrar.OBJECT_FACTORY_CLASSNAME_PREFIX + businessRemote, this
- .getStatelessSessionProxyObjectFactoryType(), null);
- ref.add(refAddr);
- String address = smd.determineResolvedJndiName(businessRemote);
- log.debug("Remote Business View for " + businessRemote + " of EJB " + smd.getEjbName()
- + " to be bound into JNDI at \"" + address + "\"");
- this.bind(ref, address, remoteProxyFactoryKey, containerName);
-
- }
- }
-
- if (hasLocalView)
- {
- // Initialize Reference Addresses to attach to default local JNDI Reference
- List<RefAddr> refAddrsForDefaultLocal = new ArrayList<RefAddr>();
-
- // For each of the local business interfaces, make a Reference Address
- for (String businessLocal : businessLocals)
- {
- RefAddr refAddr = new StringRefAddr(
- ProxyFactoryReferenceAddressTypes.REF_ADDR_TYPE_PROXY_BUSINESS_INTERFACE_LOCAL, businessLocal);
- refAddrsForDefaultLocal.add(refAddr);
- }
-
- // Determine if local home and business locals are bound to same JNDI Address
- boolean bindLocalAndLocalHomeTogether = this.isHomeAndBusinessBoundTogether(smd, true);
- if (bindLocalAndLocalHomeTogether)
- {
- // Add a Reference Address for the Local Home
- RefAddr refAddr = new StringRefAddr(
- ProxyFactoryReferenceAddressTypes.REF_ADDR_TYPE_PROXY_EJB2x_INTERFACE_HOME_LOCAL, smd
- .getLocalHome());
- refAddrsForDefaultLocal.add(refAddr);
- }
- // Bind Local Home (not bound together) if exists
- else if (smd.getLocalHome() != null && !smd.getLocalHome().equals(""))
- {
- String localHomeType = smd.getLocalHome();
- RefAddr refAddr = new StringRefAddr(
- ProxyFactoryReferenceAddressTypes.REF_ADDR_TYPE_PROXY_EJB2x_INTERFACE_HOME_LOCAL, localHomeType);
- Reference localHomeRef = new Reference(JndiRegistrar.OBJECT_FACTORY_CLASSNAME_PREFIX + localHomeType,
- this.getStatelessSessionProxyObjectFactoryType(), null);
- localHomeRef.add(refAddr);
- String localHomeAddress = smd.determineResolvedJndiName(localHomeType);
- log.debug("Local Home View for EJB " + smd.getEjbName() + " to be bound into JNDI at \""
- + localHomeAddress + "\"");
- this.bind(localHomeRef, localHomeAddress, localProxyFactoryKey, containerName);
- }
-
- /*
- * Bind ObjectFactory for default local businesses (and LocalHome if bound together)
- */
-
- // Get Classname to set for Reference
- String defaultLocalClassName = this.getHumanReadableListOfInterfacesInRefAddrs(refAddrsForDefaultLocal);
-
- // Create a Reference
- Reference defaultLocalRef = new Reference(JndiRegistrar.OBJECT_FACTORY_CLASSNAME_PREFIX
- + defaultLocalClassName, this.getStatelessSessionProxyObjectFactoryType(), null);
-
- // Add all Reference Addresses for Default Local Reference
- for (RefAddr refAddr : refAddrsForDefaultLocal)
- {
- log.debug("Adding " + RefAddr.class.getSimpleName() + " to Default Local "
- + Reference.class.getSimpleName() + ": Type \"" + refAddr.getType() + "\", Content \""
- + refAddr.getContent() + "\"");
- defaultLocalRef.add(refAddr);
- }
-
- // Bind the Default Local Reference to JNDI
- String defaultLocalAddress = smd.determineLocalJndiName();
- log.debug("Default Local View for EJB " + smd.getEjbName() + " to be bound into JNDI at \""
- + defaultLocalAddress + "\"");
- this.bind(defaultLocalRef, defaultLocalAddress, localProxyFactoryKey, containerName);
-
- // Bind ObjectFactory specific to each Local Business Interface
- for (String businessLocal : businessLocals)
- {
- RefAddr refAddr = new StringRefAddr(
- ProxyFactoryReferenceAddressTypes.REF_ADDR_TYPE_PROXY_BUSINESS_INTERFACE_LOCAL, businessLocal);
- Reference ref = new Reference(JndiRegistrar.OBJECT_FACTORY_CLASSNAME_PREFIX + businessLocal, this
- .getStatelessSessionProxyObjectFactoryType(), null);
- ref.add(refAddr);
- String address = smd.determineResolvedJndiName(businessLocal);
- log.debug("Local Business View for " + businessLocal + " of EJB " + smd.getEjbName()
- + " to be bound into JNDI at \"" + address + "\"");
- this.bind(ref, address, localProxyFactoryKey, containerName);
-
- }
- }
-
- }
- // Not SLSB or SFSB, error
- else
- {
- // Should not be reached
- throw new RuntimeException(smd
- + " reports that it is neither Stateful nor Stateless, but Session Bean must be one of these.");
- }
-
- }
-
- // --------------------------------------------------------------------------------||
- // Helper Methods -----------------------------------------------------------------||
- // --------------------------------------------------------------------------------||
-
- /**
- * Binds the specified Reference into JNDI at the specified address, adding
- * the requisite key for the ProxyFactory within the Registry and the requisite
- * target EJB Container Name as ReferenceAddresses
- *
- * @param ref
- * @param address
- * @param proxyFactoryRegistryKey The key under which the proxy factory
- * for this reference is stored in the proxy factory registry
- * @param containerName The target container to be used in invocations from Proxies obtained from this address
- */
- protected void bind(Reference ref, String address, String proxyFactoryRegistryKey, String containerName)
- {
- // Add the Proxy Factory Registry key for this Reference
- RefAddr proxyFactoryRefAddr = new StringRefAddr(
- ProxyFactoryReferenceAddressTypes.REF_ADDR_TYPE_PROXY_FACTORY_REGISTRY_KEY, proxyFactoryRegistryKey);
- ref.add(proxyFactoryRefAddr);
-
- // Add the Container name for this Reference
- RefAddr containerRefAddr = new StringRefAddr(ProxyFactoryReferenceAddressTypes.REF_ADDR_TYPE_EJBCONTAINER_NAME,
- containerName);
- ref.add(containerRefAddr);
-
- // Bind
- try
- {
- Util.rebind(this.getContext(), address, ref);
- log.debug("Bound " + ref.getClass().getName() + " into JNDI at \"" + address + "\"");
- }
- catch (NamingException e)
- {
- throw new RuntimeException("Could not bind " + ref + " into JNDI at \"" + address + "\"", e);
- }
- }
-
- /**
- * Returns whether the business interfaces and EJB2.x Home should be bound to
- * the same JNDI Name
- *
- * @param smd
- * @param isLocal
- * @return
- */
- protected boolean isHomeAndBusinessBoundTogether(JBossSessionBeanMetaData smd, boolean isLocal)
- {
- // Initialize
- boolean bindTogether = false;
-
- // If local
- if (isLocal)
- {
- // Bind together if Local Default JNDI Name == Local Home JNDI Name
- bindTogether = smd.determineLocalJndiName().equals(smd.getLocalHomeJndiName());
- }
- // If Remote
- else
- {
- // Bind together if Local Default JNDI Name == Local Home JNDI Name
- bindTogether = smd.determineJndiName().equals(smd.getHomeJndiName());
- }
-
- // Return
- return bindTogether;
- }
-
- /**
- * Returns the name of the unique key under which a Proxy Factory will
- * be registered. Will follow form:
- *
- * ejbName/ProxyFactory/(local|remote)
- *
- * ...depending upon the specified "isLocal" flag
- *
- * @param md
- * @param isLocal
- */
- protected String getProxyFactoryRegistryKey(JBossEnterpriseBeanMetaData md, boolean isLocal)
- {
- // Initialize
- String suffix = null;
-
- // Set Suffix
- if (isLocal)
- {
- suffix = JndiRegistrar.KEY_SUFFIX_PROXY_FACTORY_REGISTRY_LOCAL;
- }
- else
- {
- suffix = JndiRegistrar.KEY_SUFFIX_PROXY_FACTORY_REGISTRY_REMOTE;
- }
-
- // Assemble and return
- String key = md.getEjbName() + suffix;
- return key;
- }
-
- /**
- * Makes a comma-delimited list of interfaces bound for setting the
- * Classname of the Reference. This will show up in JNDIView and make
- * it clear to application developers what will be castable from the lookup result
- *
- * @param refAddrs
- * @return
- */
- protected String getHumanReadableListOfInterfacesInRefAddrs(List<RefAddr> refAddrs)
- {
- // Make a Comma-delimited list of interfaces bound for setting the Classname of the Reference
- // This will show up in JNDIView and make it clear to application developers
- // what will be castable from the lookup result
- StringBuffer defaultRemotes = new StringBuffer();
- int remotesCount = 0;
- for (RefAddr refAddr : refAddrs)
- {
- remotesCount++;
- defaultRemotes.append(refAddr.getContent());
- if (remotesCount < refAddrs.size())
- {
- defaultRemotes.append(", ");
- }
- }
- return defaultRemotes.toString();
- }
-
- /**
- * Registers the specified proxy factory into the registry
- *
- * @param factory
- * @param smd Metadata describing the EJB
- * @param isLocal
- * @return The key under which the ProxyFactory was registered
- */
- protected String registerProxyFactory(ProxyFactory factory, JBossEnterpriseBeanMetaData smd, boolean isLocal)
- {
- // Get a unique key
- String key = this.getProxyFactoryRegistryKey(smd, isLocal);
-
- // Register
- log.debug("Registering " + factory + " under key \"" + key + "\"...");
- try
- {
- Ejb3RegistrarLocator.locateRegistrar().bind(key, factory);
- }
- catch (DuplicateBindException e)
- {
- throw new RuntimeException("Could not register " + factory + " under an already registered key, \"" + key
- + "\"", e);
- }
-
- /*
- * Note on registry key collisions:
- *
- * Indicates that either the keys created are not unique or that we're attempting to redeploy
- * an EJB that was not properly deregistered. Either way, this is a programmatic problem
- * and not the fault of the bean developer/deployer
- */
-
- // Return the key
- return key;
- }
-
- // --------------------------------------------------------------------------------||
- // Accessors / Mutators -----------------------------------------------------------||
- // --------------------------------------------------------------------------------||
-
- public Context getContext()
- {
- return context;
- }
-
- public void setContext(Context context)
- {
- this.context = context;
- }
-
- public String getStatelessSessionProxyObjectFactoryType()
- {
- return statelessSessionProxyObjectFactoryType;
- }
-
- public void setStatelessSessionProxyObjectFactoryType(String statelessSessionProxyObjectFactoryType)
- {
- this.statelessSessionProxyObjectFactoryType = statelessSessionProxyObjectFactoryType;
- }
-
-}
Copied: projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/jndiregistrar/JndiSessionRegistrarBase.java (from rev 73670, projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/jndiregistrar/JndiRegistrar.java)
===================================================================
--- projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/jndiregistrar/JndiSessionRegistrarBase.java (rev 0)
+++ projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/jndiregistrar/JndiSessionRegistrarBase.java 2008-05-26 00:24:21 UTC (rev 73671)
@@ -0,0 +1,584 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.proxy.jndiregistrar;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.RefAddr;
+import javax.naming.Reference;
+import javax.naming.StringRefAddr;
+import javax.naming.spi.ObjectFactory;
+
+import org.jboss.ejb3.common.registrar.spi.DuplicateBindException;
+import org.jboss.ejb3.common.registrar.spi.Ejb3RegistrarLocator;
+import org.jboss.ejb3.common.string.StringUtils;
+import org.jboss.ejb3.proxy.factory.ProxyFactory;
+import org.jboss.ejb3.proxy.factory.session.SessionProxyFactory;
+import org.jboss.ejb3.proxy.objectfactory.ProxyFactoryReferenceAddressTypes;
+import org.jboss.logging.Logger;
+import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
+import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
+import org.jboss.metadata.ejb.spec.BusinessLocalsMetaData;
+import org.jboss.metadata.ejb.spec.BusinessRemotesMetaData;
+import org.jboss.naming.Util;
+
+/**
+ * JndiSessionRegistrarBase
+ *
+ * Responsible for binding of ObjectFactories and
+ * creation/registration of associated ProxyFactories,
+ * centralizing operations common to that of all Session
+ * EJB Implementations
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public abstract class JndiSessionRegistrarBase
+{
+ // --------------------------------------------------------------------------------||
+ // Class Members ------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ private static final Logger log = Logger.getLogger(JndiSessionRegistrarBase.class);
+
+ /**
+ * The value appended to the key used to bind proxy factories to the registry
+ */
+ private static final String KEY_SUFFIX_PROXY_FACTORY_REGISTRY = "/ProxyFactory";
+
+ /**
+ * The value appended to the key used to bind local proxy factories to the registry
+ */
+ private static final String KEY_SUFFIX_PROXY_FACTORY_REGISTRY_LOCAL = JndiSessionRegistrarBase.KEY_SUFFIX_PROXY_FACTORY_REGISTRY
+ + "/local";
+
+ /**
+ * The value appended to the key used to bind local remote factories to the registry
+ */
+ private static final String KEY_SUFFIX_PROXY_FACTORY_REGISTRY_REMOTE = JndiSessionRegistrarBase.KEY_SUFFIX_PROXY_FACTORY_REGISTRY
+ + "/remote";
+
+ private static final String OBJECT_FACTORY_CLASSNAME_PREFIX = "Proxy for: ";
+
+ // --------------------------------------------------------------------------------||
+ // Instance Members ---------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Context under which we'll bind to JNDI
+ */
+ private Context context;
+
+ /**
+ * Fully-qualified class name of the JNDI Object Factory to Reference
+ */
+ private String sessionProxyObjectFactoryType;
+
+ //TODO @Service, SFSB
+
+ // --------------------------------------------------------------------------------||
+ // Constructor --------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Creates a JNDI Registrar from the specified configuration properties, none of
+ * which may be null.
+ *
+ * @param context The JNDI Context into which Objects will be bound
+ * @param sessionProxyObjectFactoryType String representation of the JNDI Object
+ * Factory Class Name (fully-qualified) to use for this Session EJB
+ */
+ public JndiSessionRegistrarBase(final Context context, final String sessionProxyObjectFactoryType)
+ {
+ // Set the Context
+ assert context != null : this + " may not be configured with null " + Context.class.getName();
+ this.setContext(context);
+ log.debug("Using " + Context.class.getName() + ": " + context);
+
+ /*
+ * Perform some assertions and logging
+ */
+
+ // Set the Proxy Object Factory Type
+ assert sessionProxyObjectFactoryType != null && !sessionProxyObjectFactoryType.equals("") : "Session EJB Proxy "
+ + ObjectFactory.class.getSimpleName() + " must be specified.";
+ this.setSessionProxyObjectFactoryType(sessionProxyObjectFactoryType);
+ log.debug("Using Session EJB JNDI " + ObjectFactory.class.getSimpleName() + ": "
+ + this.getSessionProxyObjectFactoryType());
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Functional Methods -------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Binds into JNDI all appropriate objects required
+ * by the EJB described by the specified metadata. Additionally
+ * responsible for creation and registration of any all ProxyFactory
+ * implementations required by the EJB
+ *
+ * @param md
+ * @param cl The CL of the Container
+ * @param containerName The name under which the target container is registered
+ */
+ public void bindEjb(final JBossEnterpriseBeanMetaData md, final ClassLoader cl, final String containerName)
+ {
+ // Assert castable
+ assert (md instanceof JBossSessionBeanMetaData) : md + " claims to be a Session Bean but is not of type "
+ + JBossSessionBeanMetaData.class.getName();
+ JBossSessionBeanMetaData smd = null;
+ try
+ {
+ smd = JBossSessionBeanMetaData.class.cast(md);
+ }
+ catch (ClassCastException cce)
+ {
+ throw new RuntimeException(md + " claiming to be Session Bean could not be cast to "
+ + JBossSessionBeanMetaData.class.getName(), cce);
+ }
+
+ // Log
+ String ejbName = smd.getEjbName();
+ log.debug("Found Session Bean: " + ejbName);
+
+ // Get Business Locals
+ BusinessLocalsMetaData businessLocals = smd.getBusinessLocals();
+
+ // Get Business Remotes
+ BusinessRemotesMetaData businessRemotes = smd.getBusinessRemotes();
+
+ // Get Local Home
+ String localHome = StringUtils.adjustWhitespaceStringToNull(smd.getLocalHome());
+
+ // Get Remote Home
+ String remoteHome = StringUtils.adjustWhitespaceStringToNull(smd.getHome());
+
+ // Determine if there are local/remote views
+ boolean hasLocalView = (localHome != null || businessLocals.size() < 1);
+ boolean hasRemoteView = (remoteHome != null || businessRemotes.size() < 1);
+
+ // If no local or remote views
+ if (!hasLocalView && !hasRemoteView)
+ {
+ throw new RuntimeException("EJB " + smd.getEjbName() + " has no local or remote views defined.");
+ }
+
+ /*
+ * Create and Register Proxy Factories
+ */
+
+ // If there's a local view
+ String localProxyFactoryKey = null;
+ if (hasLocalView)
+ {
+ // Create and register a local proxy factory
+ ProxyFactory factory = this.createLocalProxyFactory(smd, cl);
+ localProxyFactoryKey = this.registerProxyFactory(factory, smd, true);
+ }
+
+ // If there's a remote view
+ String remoteProxyFactoryKey = null;
+ if (hasRemoteView)
+ {
+ // Create and register a local proxy factory
+ ProxyFactory factory = this.createRemoteProxyFactory(smd, cl);
+ remoteProxyFactoryKey = this.registerProxyFactory(factory, smd, false);
+ }
+
+ /*
+ * Bind Remote ObjectFactories to JNDI
+ */
+
+ if (hasRemoteView)
+ {
+
+ // Initialize Reference Addresses to attach to default remote JNDI Reference
+ List<RefAddr> refAddrsForDefaultRemote = new ArrayList<RefAddr>();
+
+ // For each of the remote business interfaces, make a Reference Address
+ for (String businessRemote : businessRemotes)
+ {
+ RefAddr refAddr = new StringRefAddr(
+ ProxyFactoryReferenceAddressTypes.REF_ADDR_TYPE_PROXY_BUSINESS_INTERFACE_REMOTE, businessRemote);
+ refAddrsForDefaultRemote.add(refAddr);
+ }
+
+ // Determine if remote home and business remotes are bound to same JNDI Address
+ boolean bindRemoteAndHomeTogether = this.isHomeAndBusinessBoundTogether(smd, false);
+ if (bindRemoteAndHomeTogether)
+ {
+ // Add a Reference Address for the Remote Home
+ RefAddr refAddr = new StringRefAddr(
+ ProxyFactoryReferenceAddressTypes.REF_ADDR_TYPE_PROXY_EJB2x_INTERFACE_HOME_REMOTE, smd.getHome());
+ refAddrsForDefaultRemote.add(refAddr);
+ }
+ // Bind Home (not bound together) if exists
+ else if (smd.getHome() != null && !smd.getHome().equals(""))
+ {
+ String homeType = smd.getHome();
+ RefAddr refAddr = new StringRefAddr(
+ ProxyFactoryReferenceAddressTypes.REF_ADDR_TYPE_PROXY_EJB2x_INTERFACE_HOME_REMOTE, homeType);
+ Reference homeRef = new Reference(JndiSessionRegistrarBase.OBJECT_FACTORY_CLASSNAME_PREFIX + homeType, this
+ .getSessionProxyObjectFactoryType(), null);
+ homeRef.add(refAddr);
+ String homeAddress = smd.determineResolvedJndiName(homeType);
+ log.debug("Remote Home View for EJB " + smd.getEjbName() + " to be bound into JNDI at \"" + homeAddress
+ + "\"");
+ this.bind(homeRef, homeAddress, remoteProxyFactoryKey, containerName);
+ }
+
+ /*
+ * Bind ObjectFactory for default remote businesses (and home if bound together)
+ */
+
+ // Get Classname to set for Reference
+ String defaultRemoteClassName = this.getHumanReadableListOfInterfacesInRefAddrs(refAddrsForDefaultRemote);
+
+ // Create a Reference
+ Reference defaultRemoteRef = new Reference(JndiSessionRegistrarBase.OBJECT_FACTORY_CLASSNAME_PREFIX
+ + defaultRemoteClassName, this.getSessionProxyObjectFactoryType(), null);
+
+ // Add all Reference Addresses for Default Remote Reference
+ for (RefAddr refAddr : refAddrsForDefaultRemote)
+ {
+ log.debug("Adding " + RefAddr.class.getSimpleName() + " to Default Remote "
+ + Reference.class.getSimpleName() + ": Type \"" + refAddr.getType() + "\", Content \""
+ + refAddr.getContent() + "\"");
+ defaultRemoteRef.add(refAddr);
+ }
+
+ // Bind the Default Remote Reference to JNDI
+ String defaultRemoteAddress = smd.determineJndiName();
+ log.debug("Default Remote View for EJB " + smd.getEjbName() + " to be bound into JNDI at \""
+ + defaultRemoteAddress + "\"");
+ this.bind(defaultRemoteRef, defaultRemoteAddress, remoteProxyFactoryKey, containerName);
+
+ // Bind ObjectFactory specific to each Remote Business Interface
+ for (String businessRemote : businessRemotes)
+ {
+ RefAddr refAddr = new StringRefAddr(
+ ProxyFactoryReferenceAddressTypes.REF_ADDR_TYPE_PROXY_BUSINESS_INTERFACE_REMOTE, businessRemote);
+ Reference ref = new Reference(JndiSessionRegistrarBase.OBJECT_FACTORY_CLASSNAME_PREFIX + businessRemote,
+ this.getSessionProxyObjectFactoryType(), null);
+ ref.add(refAddr);
+ String address = smd.determineResolvedJndiName(businessRemote);
+ log.debug("Remote Business View for " + businessRemote + " of EJB " + smd.getEjbName()
+ + " to be bound into JNDI at \"" + address + "\"");
+ this.bind(ref, address, remoteProxyFactoryKey, containerName);
+
+ }
+ }
+
+ if (hasLocalView)
+ {
+ // Initialize Reference Addresses to attach to default local JNDI Reference
+ List<RefAddr> refAddrsForDefaultLocal = new ArrayList<RefAddr>();
+
+ // For each of the local business interfaces, make a Reference Address
+ for (String businessLocal : businessLocals)
+ {
+ RefAddr refAddr = new StringRefAddr(
+ ProxyFactoryReferenceAddressTypes.REF_ADDR_TYPE_PROXY_BUSINESS_INTERFACE_LOCAL, businessLocal);
+ refAddrsForDefaultLocal.add(refAddr);
+ }
+
+ // Determine if local home and business locals are bound to same JNDI Address
+ boolean bindLocalAndLocalHomeTogether = this.isHomeAndBusinessBoundTogether(smd, true);
+ if (bindLocalAndLocalHomeTogether)
+ {
+ // Add a Reference Address for the Local Home
+ RefAddr refAddr = new StringRefAddr(
+ ProxyFactoryReferenceAddressTypes.REF_ADDR_TYPE_PROXY_EJB2x_INTERFACE_HOME_LOCAL, smd.getLocalHome());
+ refAddrsForDefaultLocal.add(refAddr);
+ }
+ // Bind Local Home (not bound together) if exists
+ else if (smd.getLocalHome() != null && !smd.getLocalHome().equals(""))
+ {
+ String localHomeType = smd.getLocalHome();
+ RefAddr refAddr = new StringRefAddr(
+ ProxyFactoryReferenceAddressTypes.REF_ADDR_TYPE_PROXY_EJB2x_INTERFACE_HOME_LOCAL, localHomeType);
+ Reference localHomeRef = new Reference(JndiSessionRegistrarBase.OBJECT_FACTORY_CLASSNAME_PREFIX
+ + localHomeType, this.getSessionProxyObjectFactoryType(), null);
+ localHomeRef.add(refAddr);
+ String localHomeAddress = smd.determineResolvedJndiName(localHomeType);
+ log.debug("Local Home View for EJB " + smd.getEjbName() + " to be bound into JNDI at \"" + localHomeAddress
+ + "\"");
+ this.bind(localHomeRef, localHomeAddress, localProxyFactoryKey, containerName);
+ }
+
+ /*
+ * Bind ObjectFactory for default local businesses (and LocalHome if bound together)
+ */
+
+ // Get Classname to set for Reference
+ String defaultLocalClassName = this.getHumanReadableListOfInterfacesInRefAddrs(refAddrsForDefaultLocal);
+
+ // Create a Reference
+ Reference defaultLocalRef = new Reference(JndiSessionRegistrarBase.OBJECT_FACTORY_CLASSNAME_PREFIX
+ + defaultLocalClassName, this.getSessionProxyObjectFactoryType(), null);
+
+ // Add all Reference Addresses for Default Local Reference
+ for (RefAddr refAddr : refAddrsForDefaultLocal)
+ {
+ log.debug("Adding " + RefAddr.class.getSimpleName() + " to Default Local "
+ + Reference.class.getSimpleName() + ": Type \"" + refAddr.getType() + "\", Content \""
+ + refAddr.getContent() + "\"");
+ defaultLocalRef.add(refAddr);
+ }
+
+ // Bind the Default Local Reference to JNDI
+ String defaultLocalAddress = smd.determineLocalJndiName();
+ log.debug("Default Local View for EJB " + smd.getEjbName() + " to be bound into JNDI at \""
+ + defaultLocalAddress + "\"");
+ this.bind(defaultLocalRef, defaultLocalAddress, localProxyFactoryKey, containerName);
+
+ // Bind ObjectFactory specific to each Local Business Interface
+ for (String businessLocal : businessLocals)
+ {
+ RefAddr refAddr = new StringRefAddr(
+ ProxyFactoryReferenceAddressTypes.REF_ADDR_TYPE_PROXY_BUSINESS_INTERFACE_LOCAL, businessLocal);
+ Reference ref = new Reference(JndiSessionRegistrarBase.OBJECT_FACTORY_CLASSNAME_PREFIX + businessLocal,
+ this.getSessionProxyObjectFactoryType(), null);
+ ref.add(refAddr);
+ String address = smd.determineResolvedJndiName(businessLocal);
+ log.debug("Local Business View for " + businessLocal + " of EJB " + smd.getEjbName()
+ + " to be bound into JNDI at \"" + address + "\"");
+ this.bind(ref, address, localProxyFactoryKey, containerName);
+
+ }
+ }
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Contracts ----------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Creates and returns a new local proxy factory for this Session Bean
+ *
+ * @param smd The metadata representing this Session EJB
+ * @param cl The ClassLoader for this EJB Container
+ */
+ protected abstract SessionProxyFactory createLocalProxyFactory(final JBossSessionBeanMetaData smd,
+ final ClassLoader cl);
+
+ /**
+ * Creates and returns a new remote proxy factory for this Session Bean
+ *
+ * @param smd The metadata representing this Session EJB
+ * @param cl The ClassLoader for this EJB Container
+ */
+ protected abstract SessionProxyFactory createRemoteProxyFactory(final JBossSessionBeanMetaData smd,
+ final ClassLoader cl);
+
+ // --------------------------------------------------------------------------------||
+ // Helper Methods -----------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Binds the specified Reference into JNDI at the specified address, adding
+ * the requisite key for the ProxyFactory within the Registry and the requisite
+ * target EJB Container Name as ReferenceAddresses
+ *
+ * @param ref
+ * @param address
+ * @param proxyFactoryRegistryKey The key under which the proxy factory
+ * for this reference is stored in the proxy factory registry
+ * @param containerName The target container to be used in invocations from Proxies obtained from this address
+ */
+ protected void bind(Reference ref, String address, String proxyFactoryRegistryKey, String containerName)
+ {
+ // Add the Proxy Factory Registry key for this Reference
+ RefAddr proxyFactoryRefAddr = new StringRefAddr(
+ ProxyFactoryReferenceAddressTypes.REF_ADDR_TYPE_PROXY_FACTORY_REGISTRY_KEY, proxyFactoryRegistryKey);
+ ref.add(proxyFactoryRefAddr);
+
+ // Add the Container name for this Reference
+ RefAddr containerRefAddr = new StringRefAddr(ProxyFactoryReferenceAddressTypes.REF_ADDR_TYPE_EJBCONTAINER_NAME,
+ containerName);
+ ref.add(containerRefAddr);
+
+ // Bind
+ try
+ {
+ Util.rebind(this.getContext(), address, ref);
+ log.debug("Bound " + ref.getClass().getName() + " into JNDI at \"" + address + "\"");
+ }
+ catch (NamingException e)
+ {
+ throw new RuntimeException("Could not bind " + ref + " into JNDI at \"" + address + "\"", e);
+ }
+ }
+
+ /**
+ * Returns whether the business interfaces and EJB2.x Home should be bound to
+ * the same JNDI Name
+ *
+ * @param smd
+ * @param isLocal
+ * @return
+ */
+ protected boolean isHomeAndBusinessBoundTogether(JBossSessionBeanMetaData smd, boolean isLocal)
+ {
+ // Initialize
+ boolean bindTogether = false;
+
+ // If local
+ if (isLocal)
+ {
+ // Bind together if Local Default JNDI Name == Local Home JNDI Name
+ bindTogether = smd.determineLocalJndiName().equals(smd.getLocalHomeJndiName());
+ }
+ // If Remote
+ else
+ {
+ // Bind together if Local Default JNDI Name == Local Home JNDI Name
+ bindTogether = smd.determineJndiName().equals(smd.getHomeJndiName());
+ }
+
+ // Return
+ return bindTogether;
+ }
+
+ /**
+ * Returns the name of the unique key under which a Proxy Factory will
+ * be registered. Will follow form:
+ *
+ * ejbName/ProxyFactory/(local|remote)
+ *
+ * ...depending upon the specified "isLocal" flag
+ *
+ * @param md
+ * @param isLocal
+ */
+ protected String getProxyFactoryRegistryKey(JBossEnterpriseBeanMetaData md, boolean isLocal)
+ {
+ // Initialize
+ String suffix = null;
+
+ // Set Suffix
+ if (isLocal)
+ {
+ suffix = JndiSessionRegistrarBase.KEY_SUFFIX_PROXY_FACTORY_REGISTRY_LOCAL;
+ }
+ else
+ {
+ suffix = JndiSessionRegistrarBase.KEY_SUFFIX_PROXY_FACTORY_REGISTRY_REMOTE;
+ }
+
+ // Assemble and return
+ String key = md.getEjbName() + suffix;
+ return key;
+ }
+
+ /**
+ * Makes a comma-delimited list of interfaces bound for setting the
+ * Classname of the Reference. This will show up in JNDIView and make
+ * it clear to application developers what will be castable from the lookup result
+ *
+ * @param refAddrs
+ * @return
+ */
+ protected String getHumanReadableListOfInterfacesInRefAddrs(List<RefAddr> refAddrs)
+ {
+ // Make a Comma-delimited list of interfaces bound for setting the Classname of the Reference
+ // This will show up in JNDIView and make it clear to application developers
+ // what will be castable from the lookup result
+ StringBuffer defaultRemotes = new StringBuffer();
+ int remotesCount = 0;
+ for (RefAddr refAddr : refAddrs)
+ {
+ remotesCount++;
+ defaultRemotes.append(refAddr.getContent());
+ if (remotesCount < refAddrs.size())
+ {
+ defaultRemotes.append(", ");
+ }
+ }
+ return defaultRemotes.toString();
+ }
+
+ /**
+ * Registers the specified proxy factory into the registry
+ *
+ * @param factory
+ * @param smd Metadata describing the EJB
+ * @param isLocal
+ * @return The key under which the ProxyFactory was registered
+ */
+ protected String registerProxyFactory(ProxyFactory factory, JBossEnterpriseBeanMetaData smd, boolean isLocal)
+ {
+ // Get a unique key
+ String key = this.getProxyFactoryRegistryKey(smd, isLocal);
+
+ // Register
+ log.debug("Registering " + factory + " under key \"" + key + "\"...");
+ try
+ {
+ Ejb3RegistrarLocator.locateRegistrar().bind(key, factory);
+ }
+ catch (DuplicateBindException e)
+ {
+ /*
+ * Note on registry key collisions:
+ *
+ * Indicates that either the keys created are not unique or that we're attempting to redeploy
+ * an EJB that was not properly deregistered. Either way, this is a programmatic problem
+ * and not the fault of the bean provider/developer/deployer
+ */
+
+ throw new RuntimeException("Could not register " + factory + " under an already registered key, \"" + key
+ + "\"", e);
+ }
+
+ // Return the key
+ return key;
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Accessors / Mutators -----------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ public Context getContext()
+ {
+ return context;
+ }
+
+ public void setContext(Context context)
+ {
+ this.context = context;
+ }
+
+ public String getSessionProxyObjectFactoryType()
+ {
+ return sessionProxyObjectFactoryType;
+ }
+
+ public void setSessionProxyObjectFactoryType(String sessionProxyObjectFactoryType)
+ {
+ this.sessionProxyObjectFactoryType = sessionProxyObjectFactoryType;
+ }
+
+}
Added: projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/jndiregistrar/JndiStatefulSessionRegistrar.java
===================================================================
--- projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/jndiregistrar/JndiStatefulSessionRegistrar.java (rev 0)
+++ projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/jndiregistrar/JndiStatefulSessionRegistrar.java 2008-05-26 00:24:21 UTC (rev 73671)
@@ -0,0 +1,88 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.proxy.jndiregistrar;
+
+import javax.naming.Context;
+
+import org.jboss.ejb3.proxy.factory.session.SessionProxyFactory;
+import org.jboss.ejb3.proxy.factory.session.stateful.StatefulSessionLocalProxyFactory;
+import org.jboss.ejb3.proxy.factory.session.stateful.StatefulSessionRemoteProxyFactory;
+import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
+
+/**
+ * JndiStatefulSessionRegistrar
+ *
+ * Responsible for binding of ObjectFactories and
+ * creation/registration of associated ProxyFactories,
+ * centralizing operations for SFSB Implementations
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class JndiStatefulSessionRegistrar extends JndiSessionRegistrarBase
+{
+
+ // --------------------------------------------------------------------------------||
+ // Constructor --------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Creates a JNDI Registrar from the specified configuration properties, none of
+ * which may be null.
+ *
+ * @param context The JNDI Context into which Objects will be bound
+ * @param statelessSessionProxyObjectFactoryType String representation of the JNDI Object Factory to use for SLSBs
+ */
+ public JndiStatefulSessionRegistrar(Context context, String statelessSessionProxyObjectFactoryType)
+ {
+ super(context, statelessSessionProxyObjectFactoryType);
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Required Implementations -------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Creates and returns a new local proxy factory for this SFSB
+ *
+ * @param smd The metadata representing this SFSB
+ * @param cl The ClassLoader for this EJB Container
+ */
+ @Override
+ protected SessionProxyFactory createLocalProxyFactory(JBossSessionBeanMetaData smd, ClassLoader cl)
+ {
+ return new StatefulSessionLocalProxyFactory(smd, cl);
+ }
+
+ /**
+ * Creates and returns a new remote proxy factory for this SFSB
+ *
+ * @param smd The metadata representing this SFSB
+ * @param cl The ClassLoader for this EJB Container
+ */
+ @Override
+ protected SessionProxyFactory createRemoteProxyFactory(final JBossSessionBeanMetaData smd, final ClassLoader cl)
+ {
+ return new StatefulSessionRemoteProxyFactory(smd, cl);
+ }
+
+}
Added: projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/jndiregistrar/JndiStatelessSessionRegistrar.java
===================================================================
--- projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/jndiregistrar/JndiStatelessSessionRegistrar.java (rev 0)
+++ projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/jndiregistrar/JndiStatelessSessionRegistrar.java 2008-05-26 00:24:21 UTC (rev 73671)
@@ -0,0 +1,88 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.proxy.jndiregistrar;
+
+import javax.naming.Context;
+
+import org.jboss.ejb3.proxy.factory.session.SessionProxyFactory;
+import org.jboss.ejb3.proxy.factory.session.stateless.StatelessSessionLocalProxyFactory;
+import org.jboss.ejb3.proxy.factory.session.stateless.StatelessSessionRemoteProxyFactory;
+import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
+
+/**
+ * JndiStatelessSessionRegistrar
+ *
+ * Responsible for binding of ObjectFactories and
+ * creation/registration of associated ProxyFactories,
+ * centralizing operations for SLSB Implementations
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class JndiStatelessSessionRegistrar extends JndiSessionRegistrarBase
+{
+
+ // --------------------------------------------------------------------------------||
+ // Constructor --------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Creates a JNDI Registrar from the specified configuration properties, none of
+ * which may be null.
+ *
+ * @param context The JNDI Context into which Objects will be bound
+ * @param statelessSessionProxyObjectFactoryType String representation of the JNDI Object Factory to use for SLSBs
+ */
+ public JndiStatelessSessionRegistrar(Context context, String statelessSessionProxyObjectFactoryType)
+ {
+ super(context, statelessSessionProxyObjectFactoryType);
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Required Implementations -------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Creates and returns a new local proxy factory for this SLSB
+ *
+ * @param smd The metadata representing this SLSB
+ * @param cl The ClassLoader for this EJB Container
+ */
+ @Override
+ protected SessionProxyFactory createLocalProxyFactory(JBossSessionBeanMetaData smd, ClassLoader cl)
+ {
+ return new StatelessSessionLocalProxyFactory(smd, cl);
+ }
+
+ /**
+ * Creates and returns a new remote proxy factory for this Session Bean
+ *
+ * @param smd The metadata representing this Session EJB
+ * @param cl The ClassLoader for this EJB Container
+ */
+ @Override
+ protected SessionProxyFactory createRemoteProxyFactory(final JBossSessionBeanMetaData smd, final ClassLoader cl)
+ {
+ return new StatelessSessionRemoteProxyFactory(smd, cl);
+ }
+
+}
Modified: projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/objectstore/ObjectStoreBindings.java
===================================================================
--- projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/objectstore/ObjectStoreBindings.java 2008-05-25 12:33:17 UTC (rev 73670)
+++ projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/objectstore/ObjectStoreBindings.java 2008-05-26 00:24:21 UTC (rev 73671)
@@ -26,6 +26,10 @@
*
* Defines constants used in binding POJOs to
* the Object Store
+ *
+ * These values must match those either used to
+ * Register beans programmatically or via
+ * XML Configuration
*
* @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
* @version $Revision: $
@@ -78,6 +82,27 @@
* The following are Bindings used as Object Store Bean Names
*/
- String OBJECTSTORE_BEAN_NAME_JNDI_REGISTRAR = ObjectStoreBindings.OBJECTSTORE_NAMESPACE_EJB3 + "JndiRegistrar";
+ /**
+ * Namespace for all JNDI Registrars
+ */
+ String OBJECTSTORE_NAMESPACE_JNDI_REGISTRAR = ObjectStoreBindings.OBJECTSTORE_NAMESPACE_EJB3 + "JndiRegistrar.";
+ /**
+ * Namespace for Session EJB JNDI Registrars
+ */
+ String OBJECTSTORE_NAMESPACE_JNDI_REGISTRAR_SESSION = ObjectStoreBindings.OBJECTSTORE_NAMESPACE_JNDI_REGISTRAR
+ + "Session.";
+
+ /**
+ * Bind name for SLSB JNDI Registrar
+ */
+ String OBJECTSTORE_BEAN_NAME_JNDI_REGISTRAR_SLSB = ObjectStoreBindings.OBJECTSTORE_NAMESPACE_JNDI_REGISTRAR_SESSION
+ + "SLSBJndiRegistrar";
+
+ /**
+ * Bind name for SFSB JNDI Registrar
+ */
+ String OBJECTSTORE_BEAN_NAME_JNDI_REGISTRAR_SFSB = ObjectStoreBindings.OBJECTSTORE_NAMESPACE_JNDI_REGISTRAR_SESSION
+ + "SFSBJndiRegistrar";
+
}
Modified: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/container/SessionContainer.java
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/container/SessionContainer.java 2008-05-25 12:33:17 UTC (rev 73670)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/container/SessionContainer.java 2008-05-26 00:24:21 UTC (rev 73671)
@@ -29,9 +29,8 @@
import org.jboss.beans.metadata.api.annotations.Stop;
import org.jboss.ejb3.common.registrar.spi.Ejb3RegistrarLocator;
import org.jboss.ejb3.common.registrar.spi.NotBoundException;
-import org.jboss.ejb3.proxy.jndiregistrar.JndiRegistrar;
+import org.jboss.ejb3.proxy.jndiregistrar.JndiSessionRegistrarBase;
import org.jboss.ejb3.proxy.lang.SerializableMethod;
-import org.jboss.ejb3.proxy.objectstore.ObjectStoreBindings;
import org.jboss.logging.Logger;
import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
@@ -161,7 +160,7 @@
log.info("Starting " + this);
// Obtain registrar
- JndiRegistrar registrar = this.getJndiRegistrar();
+ JndiSessionRegistrarBase registrar = this.getJndiRegistrar();
// Bind all appropriate references/factories to Global JNDI for Client access, if a JNDI Registrar is present
if (registrar != null)
@@ -170,8 +169,8 @@
}
else
{
- log.warn("No " + JndiRegistrar.class.getSimpleName() + " was found; byassing binding of Proxies to "
- + this.getName() + " in Global JNDI.");
+ log.warn("No " + JndiSessionRegistrarBase.class.getSimpleName()
+ + " was found; byassing binding of Proxies to " + this.getName() + " in Global JNDI.");
}
}
@@ -182,35 +181,37 @@
log.info("Stopping " + this);
//TODO We need to unbind the EJB, something like:
- //JndiRegistrar.unbindEjb(this.metaData);
+ //JndiSessionRegistrarBase.unbindEjb(this.metaData);
// or some key by which the registrar will keep track of all bindings
}
/**
- * Obtains the JndiRegistrar from MC, null if not found
+ * Obtains the JndiSessionRegistrarBase from MC, null if not found
*
* @return
*/
- protected JndiRegistrar getJndiRegistrar()
+ protected JndiSessionRegistrarBase getJndiRegistrar()
{
+ // Initialize
+ String jndiRegistrarBindName = this.getJndiRegistrarBindName();
+
// Lookup
Object obj = null;
-
try
{
- obj = Ejb3RegistrarLocator.locateRegistrar().lookup(ObjectStoreBindings.OBJECTSTORE_BEAN_NAME_JNDI_REGISTRAR);
+ obj = Ejb3RegistrarLocator.locateRegistrar().lookup(jndiRegistrarBindName);
}
// If not installed, warn and return null
catch (NotBoundException e)
{
- log.warn("No " + JndiRegistrar.class.getName() + " was found installed in MC at "
- + ObjectStoreBindings.OBJECTSTORE_BEAN_NAME_JNDI_REGISTRAR);
+ log.warn("No " + JndiSessionRegistrarBase.class.getName()
+ + " was found installed in the ObjectStore (Registry) at " + jndiRegistrarBindName);
return null;
}
// Cast
- JndiRegistrar registrar = (JndiRegistrar) obj;
+ JndiSessionRegistrarBase registrar = (JndiSessionRegistrarBase) obj;
// Return
return registrar;
@@ -227,6 +228,13 @@
*/
protected abstract String createContainerName();
+ /**
+ * Returns the name under which the JNDI Registrar for this container is bound
+ *
+ * @return
+ */
+ protected abstract String getJndiRegistrarBindName();
+
// --------------------------------------------------------------------------------||
// Accessors / Mutators -----------------------------------------------------------||
// --------------------------------------------------------------------------------||
Modified: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/container/StatefulContainer.java
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/container/StatefulContainer.java 2008-05-25 12:33:17 UTC (rev 73670)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/container/StatefulContainer.java 2008-05-26 00:24:21 UTC (rev 73671)
@@ -109,6 +109,16 @@
+ UUID.randomUUID();
}
+ /**
+ * Returns the name under which the JNDI Registrar for this container is bound
+ *
+ * @return
+ */
+ protected String getJndiRegistrarBindName()
+ {
+ return ObjectStoreBindings.OBJECTSTORE_BEAN_NAME_JNDI_REGISTRAR_SFSB;
+ }
+
// --------------------------------------------------------------------------------||
// Accessors / Mutators -----------------------------------------------------------||
// --------------------------------------------------------------------------------||
Modified: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/container/StatelessContainer.java
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/container/StatelessContainer.java 2008-05-25 12:33:17 UTC (rev 73670)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/container/StatelessContainer.java 2008-05-26 00:24:21 UTC (rev 73671)
@@ -51,4 +51,14 @@
return ObjectStoreBindings.OBJECTSTORE_NAMESPACE_EJBCONTAINER_STATELESS + this.getMetaData().getEjbName() + "/"
+ UUID.randomUUID();
}
+
+ /**
+ * Returns the name under which the JNDI Registrar for this container is bound
+ *
+ * @return
+ */
+ protected String getJndiRegistrarBindName()
+ {
+ return ObjectStoreBindings.OBJECTSTORE_BEAN_NAME_JNDI_REGISTRAR_SLSB;
+ }
}
Modified: projects/ejb3/trunk/proxy/src/test/resources/log4j.xml
===================================================================
--- projects/ejb3/trunk/proxy/src/test/resources/log4j.xml 2008-05-25 12:33:17 UTC (rev 73670)
+++ projects/ejb3/trunk/proxy/src/test/resources/log4j.xml 2008-05-26 00:24:21 UTC (rev 73671)
@@ -65,14 +65,10 @@
<priority value="INFO"/>
</category>
- <category name="org.jboss.ejb3.test.proxy">
+ <category name="org.jboss.ejb3">
<priority value="ALL"/>
</category>
- <category name="org.jboss.ejb3.proxy">
- <priority value="ALL"/>
- </category>
-
<!-- ======================= -->
<!-- Setup the Root category -->
<!-- ======================= -->
Modified: projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/session/unit/ProxySessionTestCase-beans.xml
===================================================================
--- projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/session/unit/ProxySessionTestCase-beans.xml 2008-05-25 12:33:17 UTC (rev 73670)
+++ projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/session/unit/ProxySessionTestCase-beans.xml 2008-05-26 00:24:21 UTC (rev 73671)
@@ -2,13 +2,19 @@
xsi:schemaLocation="urn:jboss:bean-deployer:2.0 bean-deployer_2_0.xsd"
xmlns="urn:jboss:bean-deployer:2.0">
- <!-- JNDI -->
+ <!--
+
+ JNDI
+
+ The requisite Naming Server
+
+ -->
<bean name="NameServer" class="org.jnp.server.SingletonNamingServer" />
- <!--
+ <!--
+ JNDI Registrars
- JNDI Registrar
The JNDI Registrar is responsible for all JNDI Bindings for
an EJB. Its constructor takes the following arguments, in order:
@@ -18,10 +24,11 @@
String statelessSessionProxyObjectFactoryType The JNDI ObjectFactory implementation to use for SLSB
...more later when SFSB, @Service, MDB Implemented
-
-->
- <bean name="org.jboss.ejb3.JndiRegistrar"
- class="org.jboss.ejb3.proxy.jndiregistrar.JndiRegistrar">
+
+ <!-- SLSB JNDI Registrar -->
+ <bean name="org.jboss.ejb3.JndiRegistrar.Session.SLSBJndiRegistrar"
+ class="org.jboss.ejb3.proxy.jndiregistrar.JndiStatelessSessionRegistrar">
<constructor>
<parameter>
<inject bean="org.jboss.ejb3.JndiContext" />
@@ -33,6 +40,21 @@
<depends>NameServer</depends>
</bean>
+ <!-- SFSB JNDI Registrar -->
+ <bean name="org.jboss.ejb3.JndiRegistrar.Session.SFSBJndiRegistrar"
+ class="org.jboss.ejb3.proxy.jndiregistrar.JndiStatefulSessionRegistrar">
+ <constructor>
+ <parameter>
+ <inject bean="org.jboss.ejb3.JndiContext" />
+ </parameter>
+ <parameter>
+ org.jboss.ejb3.proxy.objectfactory.session.stateless.StatefulSessionProxyObjectFactory
+ </parameter>
+ </constructor>
+ <depends>NameServer</depends>
+ </bean>
+
+ <!-- JNDI Registrar Configuration -->
<bean name="org.jboss.ejb3.JndiContext"
class="javax.naming.InitialContext" />
More information about the jboss-cvs-commits
mailing list