Search in sources :

Example 6 with EjbRef

use of org.apache.naming.EjbRef in project tomcat by apache.

the class OpenEjbFactory method getObjectInstance.

// -------------------------------------------------- ObjectFactory Methods
/**
 * Create a new EJB instance using OpenEJB.
 *
 * @param obj The reference object describing the DataSource
 */
@Override
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
    Object beanObj = null;
    if (obj instanceof EjbRef) {
        Reference ref = (Reference) obj;
        String factory = DEFAULT_OPENEJB_FACTORY;
        RefAddr factoryRefAddr = ref.get("openejb.factory");
        if (factoryRefAddr != null) {
            // Retrieving the OpenEJB factory
            factory = factoryRefAddr.getContent().toString();
        }
        Properties env = new Properties();
        env.put(Context.INITIAL_CONTEXT_FACTORY, factory);
        RefAddr linkRefAddr = ref.get("openejb.link");
        if (linkRefAddr != null) {
            String ejbLink = linkRefAddr.getContent().toString();
            beanObj = (new InitialContext(env)).lookup(ejbLink);
        }
    }
    return beanObj;
}
Also used : RefAddr(javax.naming.RefAddr) Reference(javax.naming.Reference) EjbRef(org.apache.naming.EjbRef) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext)

Example 7 with EjbRef

use of org.apache.naming.EjbRef in project Payara by payara.

the class OpenEjbFactory method getObjectInstance.

// -------------------------------------------------- ObjectFactory Methods
/**
 * Crete a new EJB instance using OpenEJB.
 *
 * @param obj The reference object describing the DataSource
 */
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
    Object beanObj = null;
    if (obj instanceof EjbRef) {
        Reference ref = (Reference) obj;
        String factory = DEFAULT_OPENEJB_FACTORY;
        RefAddr factoryRefAddr = ref.get("openejb.factory");
        if (factoryRefAddr != null) {
            // Retrieving the OpenEJB factory
            factory = factoryRefAddr.getContent().toString();
        }
        Properties env = new Properties();
        env.put(Context.INITIAL_CONTEXT_FACTORY, factory);
        RefAddr linkRefAddr = ref.get("openejb.link");
        if (linkRefAddr != null) {
            String ejbLink = linkRefAddr.getContent().toString();
            beanObj = (new InitialContext(env)).lookup(ejbLink);
        }
    }
    return beanObj;
}
Also used : RefAddr(javax.naming.RefAddr) Reference(javax.naming.Reference) EjbRef(org.apache.naming.EjbRef) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext)

Aggregations

Reference (javax.naming.Reference)7 EjbRef (org.apache.naming.EjbRef)7 InitialContext (javax.naming.InitialContext)5 RefAddr (javax.naming.RefAddr)5 NamingException (javax.naming.NamingException)4 Properties (java.util.Properties)3 StringRefAddr (javax.naming.StringRefAddr)2 ObjectFactory (javax.naming.spi.ObjectFactory)2