// Get the default remote JNDI Name
String defaultRemoteJndiName = smd.getJndiName();
// Create and register a remote proxy factory
String defaultRemoteProxyFactoryKey = this.getProxyFactoryRegistryKey(defaultRemoteJndiName, smd, false);
SessionProxyFactory factory = this.createRemoteProxyFactory(defaultRemoteProxyFactoryKey, containerName,
containerGuid, smd, cl, defaultClientBindUrl, advisor, null);
try
{
this.registerProxyFactory(defaultRemoteProxyFactoryKey, factory, smd);
}
catch (DuplicateBindException dbe)
{
throw new RuntimeException(dbe);
}
// Get Classname to set for Reference
String defaultRemoteClassName = this.getHumanReadableListOfInterfacesInRefAddrs(refAddrsForRemote);
// Create a Reference
Reference defaultRemoteRef = createStandardReference(JndiSessionRegistrarBase.OBJECT_FACTORY_CLASSNAME_PREFIX
+ defaultRemoteClassName, defaultRemoteProxyFactoryKey, containerName, false);
/*
* Set up references for Home
*/
// 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
String home = smd.getHome();
assert home != null : "Home and Business set to be bound together, yet no home is defined";
RefAddr refAddr = new StringRefAddr(
ProxyFactoryReferenceAddressTypes.REF_ADDR_TYPE_PROXY_EJB2x_INTERFACE_HOME_REMOTE, home);
refAddrsForRemote.add(refAddr);
}
// Bind Home (not bound together) if exists
else if (smd.getHome() != null && smd.getHome().trim().length() > 0)
{
String homeType = smd.getHome();
RefAddr refAddrHomeInterface = new StringRefAddr(
ProxyFactoryReferenceAddressTypes.REF_ADDR_TYPE_PROXY_EJB2x_INTERFACE_HOME_REMOTE, homeType);
RefAddr refAddrRemoting = this.createRemotingRefAddr(defaultClientBindUrl);
Reference homeRef = createStandardReference(JndiSessionRegistrarBase.OBJECT_FACTORY_CLASSNAME_PREFIX
+ homeType, defaultRemoteProxyFactoryKey, containerName, false);
homeRef.add(refAddrHomeInterface);
homeRef.add(refAddrRemoting);
String homeAddress = smd.getHomeJndiName();
assert homeAddress != null && !homeAddress.equals("") : "JNDI Address for Remote Home must be defined";
log.debug("Remote Home View for EJB " + smd.getEjbName() + " to be bound into JNDI at \"" + homeAddress
+ "\"");
bindingSet.addHomeRemoteBinding(new JndiReferenceBinding(homeAddress, homeRef));
}
/*
* If no @RemoteBindings are defined, make a default remote binding
*/
// Get RemoteBindings
List<RemoteBindingMetaData> remoteBindings = smd.getRemoteBindings();
// If there are no @RemoteBindings defined
if (remoteBindings == null)
{
// Use the default Client Bind URL
String clientBindUrl = defaultClientBindUrl;
// Create a default remote remoting RefAddr, using the default (as none was explicitly-specified)
RefAddr defaultRemoteRemotingRefAddr = this.createRemotingRefAddr(clientBindUrl);
// Add a Reference Address for the Remoting URL
refAddrsForRemote.add(defaultRemoteRemotingRefAddr);
/*
* Bind ObjectFactory for default remote businesses (and home if bound together)
*/
// Add all Reference Addresses for Default Remote Reference
for (RefAddr refAddr : refAddrsForRemote)
{
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
log.debug("Default Remote Business View for EJB " + smd.getEjbName() + " to be bound into JNDI at \""
+ defaultRemoteJndiName + "\"");
bindingSet.addDefaultRemoteBinding(new JndiReferenceBinding(defaultRemoteJndiName, defaultRemoteRef));
}
// Remote Bindings are defined, create a binding for each
else
{
/*
* Bind all explicitly-declared remote bindings
*/
// For each of the explicitly-defined @RemoteBindings
for (RemoteBindingMetaData binding : remoteBindings)
{
// Get the defined JNDI Name
String remoteBindingJndiName = binding.getJndiName();
// If the JNDI Name isn't defined
if (remoteBindingJndiName == null || remoteBindingJndiName.trim().length() == 0)
{
// Set a default remote binding JNDI name
remoteBindingJndiName = smd.getJndiName();
}
// Get the client bind URL
String clientBindUrl = defaultClientBindUrl;
String remoteBindingClientBindUrl = binding.getClientBindUrl();
if (remoteBindingClientBindUrl != null && remoteBindingClientBindUrl.trim().length() > 0)
{
clientBindUrl = remoteBindingClientBindUrl;
}
// Get the interceptor stack
String interceptorStack = binding.getInterceptorStack();
/*
* Obtain a Proxy Factory for this Binding
*/
// Create and register a remote proxy factory specific to this binding
String remoteBindingProxyFactoryKey = this.getProxyFactoryRegistryKey(remoteBindingJndiName, smd, false);
SessionProxyFactory remoteBindingProxyFactory = null;
boolean reregister = true;
try
{
// Check if it's already available
remoteBindingProxyFactory = Ejb3RegistrarLocator.locateRegistrar().lookup(
remoteBindingProxyFactoryKey, SessionProxyFactory.class);
}
catch (NotBoundException nbe)
{
reregister = false;
}
// If we need to reregister with this newly-defined Proxy Factory
if (reregister)
{
Ejb3RegistrarLocator.locateRegistrar().unbind(remoteBindingProxyFactoryKey);
}
// Create the Proxy Factory
remoteBindingProxyFactory = this.createRemoteProxyFactory(remoteBindingProxyFactoryKey, containerName,
containerGuid, smd, cl, clientBindUrl, advisor, interceptorStack);
try
{
this.registerProxyFactory(remoteBindingProxyFactoryKey, remoteBindingProxyFactory, smd);
}
catch (DuplicateBindException dbe)
{
throw new RuntimeException(dbe);
}
// Create a default remote remoting RefAddr, using the default (as none was explicitly-specified)
RefAddr remoteBindingRemotingRefAddr = this.createRemotingRefAddr(clientBindUrl);
// Create a Reference
Reference remoteBindingRef = createStandardReference(
JndiSessionRegistrarBase.OBJECT_FACTORY_CLASSNAME_PREFIX + defaultRemoteClassName,
remoteBindingProxyFactoryKey, containerName, false);
// Add a Reference Address for the Remoting URL
log.debug("Adding " + RefAddr.class.getSimpleName() + " to @RemoteBinding "
+ Reference.class.getSimpleName() + ": Type \"" + remoteBindingRemotingRefAddr.getType()
+ "\", Content \"" + remoteBindingRemotingRefAddr.getContent() + "\"");
remoteBindingRef.add(remoteBindingRemotingRefAddr);
// Add all Reference Addresses for @RemoteBinding Reference
for (RefAddr refAddr : refAddrsForRemote)
{
log.debug("Adding " + RefAddr.class.getSimpleName() + " to @RemoteBinding "
+ Reference.class.getSimpleName() + ": Type \"" + refAddr.getType() + "\", Content \""
+ refAddr.getContent() + "\"");
remoteBindingRef.add(refAddr);
}
// Create the binding
JndiReferenceBinding remoteBindingJndiBinding = new JndiReferenceBinding(remoteBindingJndiName,
remoteBindingRef);
// Add the binding
bindingSet.addDefaultRemoteBinding(remoteBindingJndiBinding);
}
}
// Bind ObjectFactory specific to each Remote Business Interface
if (businessRemotes != null)
{
for (String businessRemote : businessRemotes)
{
RefAddr refAddrBusinessInterface = new StringRefAddr(
ProxyFactoryReferenceAddressTypes.REF_ADDR_TYPE_PROXY_BUSINESS_INTERFACE_REMOTE, businessRemote);
RefAddr refAddrRemoting = this.createRemotingRefAddr(defaultClientBindUrl);
Reference ref = createStandardReference(JndiSessionRegistrarBase.OBJECT_FACTORY_CLASSNAME_PREFIX
+ businessRemote, defaultRemoteProxyFactoryKey, containerName, false);
ref.add(refAddrBusinessInterface);
ref.add(refAddrRemoting);
String address = JbossSessionBeanJndiNameResolver.resolveJndiName(smd, businessRemote);
log.debug("Remote Business View for " + businessRemote + " of EJB " + smd.getEjbName()
+ " to be bound into JNDI at \"" + address + "\"");
bindingSet.addBusinessRemoteBinding(businessRemote, new JndiReferenceBinding(address, ref));
}
}
}
// If there's a local view
if (hasLocalView)
{
// Get the default local JNDI Name
String defaultLocalJndiName = smd.getLocalJndiName();
// Create and register a local proxy factory
String localProxyFactoryKey = this.getProxyFactoryRegistryKey(defaultLocalJndiName, smd, true);
SessionProxyFactory factory = this.createLocalProxyFactory(localProxyFactoryKey, containerName, containerGuid,
smd, cl, advisor);
try
{
this.registerProxyFactory(localProxyFactoryKey, factory, smd);
}