{
return;
}
DefaultJndiBindingPolicy jndibindingPolicy = DefaultJNDIBindingPolicyFactory.getDefaultJNDIBindingPolicy();
SessionBeanJNDINameResolver jndiNameResolver = JNDIPolicyBasedJNDINameResolverFactory.getJNDINameResolver(
sessionBean, jndibindingPolicy);
// TODO: Rethink
String containerRegistryKey = container.getObjectName().getCanonicalName();
String containerGUID = Ejb3Registry.guid(container);
ProxyFactory proxyFactory = new ReflectProxyFactory();
Context jndiCtx = null;
try
{
jndiCtx = new InitialContext();
}
catch (NamingException ne)
{
throw new RuntimeException("Could not create jndi context for jndi binders", ne);
}
Set<Class<?>> allLocalinterfaces = new HashSet<Class<?>>();
// get the client side AOP interceptor(s) for local business interface of the singleton bean
Interceptor[] clientInterceptors = this.getLocalClientInterceptors(container);
for (String businessLocal : businessLocals)
{
Class<?> businessLocalIntf = null;
try
{
businessLocalIntf = unit.getClassLoader().loadClass(businessLocal);
}
catch (ClassNotFoundException cnfe)
{
throw new RuntimeException("Could not load business local interface " + businessLocal, cnfe);
}
allLocalinterfaces.add(businessLocalIntf);
InvocationHandler invocationHandler = new SingletonBeanLocalInvocationHandler(containerRegistryKey,
businessLocal, clientInterceptors);
// time to create a proxy
Object proxy = proxyFactory.createProxy(new Class<?>[]
{businessLocalIntf}, invocationHandler);
// bind to jndi
String jndiName = jndiNameResolver.resolveJNDIName(sessionBean, businessLocal);
JNDIBinderImpl jndiBinder = new JNDIBinderImpl(jndiCtx, jndiName, proxy);
String binderMCBeanName = JNDI_BINDER_MC_BEAN_PREFIX + jndiName;
BeanMetaData jndiBinderBMD = createBeanMetaData(binderMCBeanName, jndiBinder, container);
DeploymentUnit parentUnit = unit.getParent();
parentUnit.addAttachment(BeanMetaData.class + ":" + binderMCBeanName, jndiBinderBMD);
}
List<LocalBindingMetaData> localBindings = sessionBean.getLocalBindings();
if (localBindings == null || localBindings.isEmpty())
{
InvocationHandler invocationHandler = new SingletonBeanLocalInvocationHandler(containerRegistryKey, containerGUID, clientInterceptors);
String defaultBusinessLocalJNDIName = jndiNameResolver.resolveLocalBusinessDefaultJNDIName(sessionBean);
Object proxy = proxyFactory.createProxy(allLocalinterfaces.toArray(new Class<?>[allLocalinterfaces.size()]),
invocationHandler);
JNDIBinderImpl jndiBinder = new JNDIBinderImpl(jndiCtx, defaultBusinessLocalJNDIName, proxy);
String binderMCBeanName = JNDI_BINDER_MC_BEAN_PREFIX + defaultBusinessLocalJNDIName;
BeanMetaData jndiBinderBMD = createBeanMetaData(binderMCBeanName, jndiBinder, container);
DeploymentUnit parentUnit = unit.getParent();
parentUnit.addAttachment(BeanMetaData.class + ":" + binderMCBeanName, jndiBinderBMD);
}
else
{
for (LocalBindingMetaData localBinding : localBindings)
{
String jndiName = localBinding.getJndiName();
// if not explicitly specified, then use the default jndi name
if (jndiName == null)
{
jndiName = jndiNameResolver.resolveLocalBusinessDefaultJNDIName(sessionBean);
}
InvocationHandler invocationHandler = new SingletonBeanLocalInvocationHandler(containerRegistryKey, containerGUID, clientInterceptors);
Object proxy = proxyFactory.createProxy(
allLocalinterfaces.toArray(new Class<?>[allLocalinterfaces.size()]), invocationHandler);
JNDIBinderImpl jndiBinder = new JNDIBinderImpl(jndiCtx, jndiName, proxy);