Search in sources :

Example 1 with BusinessRemoteReference

use of org.apache.openejb.core.ivm.naming.BusinessRemoteReference in project tomee by apache.

the class JndiBuilder method bind.

public void bind(final EjbJarInfo ejbJarInfo, final BeanContext bean, final EnterpriseBeanInfo beanInfo, final JndiNameStrategy strategy) {
    // and we shouldn't need it
    if (BeanContext.Comp.class.equals(bean.getBeanClass())) {
        return;
    }
    final Bindings bindings = new Bindings();
    bean.set(Bindings.class, bindings);
    Reference simpleNameRef = null;
    final Object id = bean.getDeploymentID();
    try {
        if (bean.isLocalbean()) {
            final Class beanClass = bean.getBeanClass();
            final BeanContext.BusinessLocalBeanHome home = bean.getBusinessLocalBeanHome();
            final BusinessLocalBeanReference ref = new BusinessLocalBeanReference(home);
            optionalBind(bindings, ref, "openejb/Deployment/" + format(id, beanClass.getName(), InterfaceType.LOCALBEAN));
            // if the user inject the EJB using a parent class
            if (!bean.getBeanClass().isInterface()) {
                for (Class<?> clazz = bean.getBeanClass().getSuperclass(); !clazz.equals(Object.class); clazz = clazz.getSuperclass()) {
                    optionalBind(bindings, ref, "openejb/Deployment/" + format(id, clazz.getName(), InterfaceType.LOCALBEAN));
                }
            }
            final String internalName = "openejb/Deployment/" + format(id, beanClass.getName(), InterfaceType.BUSINESS_LOCALBEAN_HOME);
            bind(internalName, ref, bindings, beanInfo, beanClass);
            final String name = strategy.getName(beanClass, DEFAULT_NAME_KEY, JndiNameStrategy.Interface.LOCALBEAN);
            bind("openejb/local/" + name, ref, bindings, beanInfo, beanClass);
            bindJava(bean, beanClass, ref, bindings, beanInfo);
            if (USE_OLD_JNDI_NAMES) {
                bean.getModuleContext().getAppContext().getBindings().put(name, ref);
            }
            simpleNameRef = ref;
        }
    } catch (final NamingException e) {
        throw new OpenEJBRuntimeException("Unable to bind business remote deployment in jndi.", e);
    }
    try {
        for (final Class interfce : bean.getBusinessLocalInterfaces()) {
            final BeanContext.BusinessLocalHome home = bean.getBusinessLocalHome(interfce);
            final BusinessLocalReference ref = new BusinessLocalReference(home);
            optionalBind(bindings, ref, "openejb/Deployment/" + format(id, interfce.getName()));
            final String internalName = "openejb/Deployment/" + format(id, interfce.getName(), InterfaceType.BUSINESS_LOCAL);
            bind(internalName, ref, bindings, beanInfo, interfce);
            final String name = strategy.getName(interfce, DEFAULT_NAME_KEY, JndiNameStrategy.Interface.BUSINESS_LOCAL);
            final String externalName = "openejb/local/" + name;
            bind(externalName, ref, bindings, beanInfo, interfce);
            bindJava(bean, interfce, ref, bindings, beanInfo);
            if (USE_OLD_JNDI_NAMES) {
                bean.getModuleContext().getAppContext().getBindings().put(name, ref);
            }
            if (simpleNameRef == null) {
                simpleNameRef = ref;
            }
        }
    } catch (final NamingException e) {
        throw new OpenEJBRuntimeException("Unable to bind business local interface for deployment " + id, e);
    }
    try {
        for (final Class interfce : bean.getBusinessRemoteInterfaces()) {
            final BeanContext.BusinessRemoteHome home = bean.getBusinessRemoteHome(interfce);
            final BusinessRemoteReference ref = new BusinessRemoteReference(home);
            optionalBind(bindings, ref, "openejb/Deployment/" + format(id, interfce.getName(), null));
            final String internalName = "openejb/Deployment/" + format(id, interfce.getName(), InterfaceType.BUSINESS_REMOTE);
            bind(internalName, ref, bindings, beanInfo, interfce);
            final String name = strategy.getName(interfce, DEFAULT_NAME_KEY, JndiNameStrategy.Interface.BUSINESS_REMOTE);
            bind("openejb/local/" + name, ref, bindings, beanInfo, interfce);
            bind("openejb/remote/" + name, ref, bindings, beanInfo, interfce);
            bind("openejb/remote/" + computeGlobalName(bean, interfce), ref, bindings, beanInfo, interfce);
            bindJava(bean, interfce, ref, bindings, beanInfo);
            if (USE_OLD_JNDI_NAMES) {
                bean.getModuleContext().getAppContext().getBindings().put(name, ref);
            }
            if (simpleNameRef == null) {
                simpleNameRef = ref;
            }
        }
    } catch (final NamingException e) {
        throw new OpenEJBRuntimeException("Unable to bind business remote deployment in jndi.", e);
    }
    try {
        final Class localHomeInterface = bean.getLocalHomeInterface();
        if (localHomeInterface != null) {
            final ObjectReference ref = new ObjectReference(bean.getEJBLocalHome());
            String name = strategy.getName(bean.getLocalHomeInterface(), DEFAULT_NAME_KEY, JndiNameStrategy.Interface.LOCAL_HOME);
            bind("openejb/local/" + name, ref, bindings, beanInfo, localHomeInterface);
            optionalBind(bindings, ref, "openejb/Deployment/" + format(id, localHomeInterface.getName(), InterfaceType.EJB_LOCAL_HOME));
            name = "openejb/Deployment/" + format(id, bean.getLocalInterface().getName());
            bind(name, ref, bindings, beanInfo, localHomeInterface);
            name = "openejb/Deployment/" + format(id, bean.getLocalInterface().getName(), InterfaceType.EJB_LOCAL);
            bind(name, ref, bindings, beanInfo, localHomeInterface);
            bindJava(bean, localHomeInterface, ref, bindings, beanInfo);
            if (simpleNameRef == null) {
                simpleNameRef = ref;
            }
        }
    } catch (final NamingException e) {
        throw new OpenEJBRuntimeException("Unable to bind local home interface for deployment " + id, e);
    }
    try {
        final Class homeInterface = bean.getHomeInterface();
        if (homeInterface != null) {
            final ObjectReference ref = new ObjectReference(bean.getEJBHome());
            String name = strategy.getName(homeInterface, DEFAULT_NAME_KEY, JndiNameStrategy.Interface.REMOTE_HOME);
            bind("openejb/local/" + name, ref, bindings, beanInfo, homeInterface);
            bind("openejb/remote/" + name, ref, bindings, beanInfo, homeInterface);
            optionalBind(bindings, ref, "openejb/Deployment/" + format(id, homeInterface.getName(), InterfaceType.EJB_HOME));
            name = "openejb/Deployment/" + format(id, bean.getRemoteInterface().getName());
            bind(name, ref, bindings, beanInfo, homeInterface);
            name = "openejb/Deployment/" + format(id, bean.getRemoteInterface().getName(), InterfaceType.EJB_OBJECT);
            bind(name, ref, bindings, beanInfo, homeInterface);
            bindJava(bean, homeInterface, ref, bindings, beanInfo);
            if (simpleNameRef == null) {
                simpleNameRef = ref;
            }
        }
    } catch (final NamingException e) {
        throw new OpenEJBRuntimeException("Unable to bind remote home interface for deployment " + id, e);
    }
    try {
        if (simpleNameRef != null) {
            bindJava(bean, null, simpleNameRef, bindings, beanInfo);
        }
    } catch (final NamingException e) {
        throw new OpenEJBRuntimeException("Unable to bind simple java:global name in jndi", e);
    }
    try {
        if (MessageListener.class.equals(bean.getMdbInterface())) {
            final String destinationId = bean.getDestinationId();
            final String jndiName = "openejb/Resource/" + destinationId;
            final Reference reference = new IntraVmJndiReference(jndiName);
            final String deploymentId = id.toString();
            bind("openejb/local/" + deploymentId, reference, bindings, beanInfo, MessageListener.class);
            bind("openejb/remote/" + deploymentId, reference, bindings, beanInfo, MessageListener.class);
        }
    } catch (final NamingException e) {
        throw new OpenEJBRuntimeException("Unable to bind mdb destination in jndi.", e);
    } catch (final NoClassDefFoundError ncdfe) {
    // no-op: no jms API
    }
}
Also used : IntraVmJndiReference(org.apache.openejb.core.ivm.naming.IntraVmJndiReference) ObjectReference(org.apache.openejb.core.ivm.naming.ObjectReference) BusinessRemoteReference(org.apache.openejb.core.ivm.naming.BusinessRemoteReference) BusinessLocalBeanReference(org.apache.openejb.core.ivm.naming.BusinessLocalBeanReference) Reference(javax.naming.Reference) BusinessLocalReference(org.apache.openejb.core.ivm.naming.BusinessLocalReference) BusinessLocalReference(org.apache.openejb.core.ivm.naming.BusinessLocalReference) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) BeanContext(org.apache.openejb.BeanContext) IntraVmJndiReference(org.apache.openejb.core.ivm.naming.IntraVmJndiReference) ObjectReference(org.apache.openejb.core.ivm.naming.ObjectReference) BusinessLocalBeanReference(org.apache.openejb.core.ivm.naming.BusinessLocalBeanReference) NamingException(javax.naming.NamingException) BusinessRemoteReference(org.apache.openejb.core.ivm.naming.BusinessRemoteReference)

Aggregations

NamingException (javax.naming.NamingException)1 Reference (javax.naming.Reference)1 BeanContext (org.apache.openejb.BeanContext)1 OpenEJBRuntimeException (org.apache.openejb.OpenEJBRuntimeException)1 BusinessLocalBeanReference (org.apache.openejb.core.ivm.naming.BusinessLocalBeanReference)1 BusinessLocalReference (org.apache.openejb.core.ivm.naming.BusinessLocalReference)1 BusinessRemoteReference (org.apache.openejb.core.ivm.naming.BusinessRemoteReference)1 IntraVmJndiReference (org.apache.openejb.core.ivm.naming.IntraVmJndiReference)1 ObjectReference (org.apache.openejb.core.ivm.naming.ObjectReference)1