Search in sources :

Example 6 with RefAddr

use of javax.naming.RefAddr 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 RefAddr

use of javax.naming.RefAddr in project tomcat by apache.

the class DataSourceFactory method getObjectInstance.

// -------------------------------------------------- ObjectFactory Methods
/**
     * <p>Create and return a new <code>BasicDataSource</code> instance.  If no
     * instance can be created, return <code>null</code> instead.</p>
     *
     * @param obj The possibly null object containing location or
     *  reference information that can be used in creating an object
     * @param name The name of this object relative to <code>nameCtx</code>
     * @param nameCtx The context relative to which the <code>name</code>
     *  parameter is specified, or <code>null</code> if <code>name</code>
     *  is relative to the default initial context
     * @param environment The possibly null environment that is used in
     *  creating this object
     *
     * @exception Exception if an exception occurs creating the instance
     */
@Override
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
    // that specify a class name of "javax.sql.DataSource"
    if ((obj == null) || !(obj instanceof Reference)) {
        return null;
    }
    Reference ref = (Reference) obj;
    boolean XA = false;
    boolean ok = false;
    if ("javax.sql.DataSource".equals(ref.getClassName())) {
        ok = true;
    }
    if ("javax.sql.XADataSource".equals(ref.getClassName())) {
        ok = true;
        XA = true;
    }
    if (org.apache.tomcat.jdbc.pool.DataSource.class.getName().equals(ref.getClassName())) {
        ok = true;
    }
    if (!ok) {
        log.warn(ref.getClassName() + " is not a valid class name/type for this JNDI factory.");
        return null;
    }
    Properties properties = new Properties();
    for (int i = 0; i < ALL_PROPERTIES.length; i++) {
        String propertyName = ALL_PROPERTIES[i];
        RefAddr ra = ref.get(propertyName);
        if (ra != null) {
            String propertyValue = ra.getContent().toString();
            properties.setProperty(propertyName, propertyValue);
        }
    }
    return createDataSource(properties, nameCtx, XA);
}
Also used : RefAddr(javax.naming.RefAddr) Reference(javax.naming.Reference) Properties(java.util.Properties) DataSource(javax.sql.DataSource)

Example 8 with RefAddr

use of javax.naming.RefAddr in project tomcat by apache.

the class AbstractRef method toString.

/**
     * Return a String rendering of this object.
     */
@Override
public final String toString() {
    StringBuilder sb = new StringBuilder(this.getClass().getSimpleName());
    sb.append("[className=");
    sb.append(getClassName());
    sb.append(",factoryClassLocation=");
    sb.append(getFactoryClassLocation());
    sb.append(",factoryClassName=");
    sb.append(getFactoryClassName());
    Enumeration<RefAddr> refAddrs = getAll();
    while (refAddrs.hasMoreElements()) {
        RefAddr refAddr = refAddrs.nextElement();
        sb.append(",{type=");
        sb.append(refAddr.getType());
        sb.append(",content=");
        sb.append(refAddr.getContent());
        sb.append("}");
    }
    sb.append("]");
    return sb.toString();
}
Also used : RefAddr(javax.naming.RefAddr)

Example 9 with RefAddr

use of javax.naming.RefAddr in project jetty.project by eclipse.

the class MailSessionReference method getObjectInstance.

/**
     * Create a javax.mail.Session instance based on the information passed in the Reference
     * @see javax.naming.spi.ObjectFactory#getObjectInstance(java.lang.Object, javax.naming.Name, javax.naming.Context, java.util.Hashtable)
     * @param ref the Reference
     * @param arg1 not used
     * @param arg2 not used
     * @param arg3 not used
     * @return the object found
     * @throws Exception if unable to get object instance
     */
public Object getObjectInstance(Object ref, Name arg1, Context arg2, Hashtable arg3) throws Exception {
    if (ref == null)
        return null;
    Reference reference = (Reference) ref;
    Properties props = new Properties();
    String user = null;
    String password = null;
    Enumeration refs = reference.getAll();
    while (refs.hasMoreElements()) {
        RefAddr refAddr = (RefAddr) refs.nextElement();
        String name = refAddr.getType();
        String value = (String) refAddr.getContent();
        if (name.equalsIgnoreCase("user"))
            user = value;
        else if (name.equalsIgnoreCase("pwd"))
            password = value;
        else
            props.put(name, value);
    }
    if (password == null)
        return Session.getInstance(props);
    else
        return Session.getInstance(props, new PasswordAuthenticator(user, password));
}
Also used : RefAddr(javax.naming.RefAddr) StringRefAddr(javax.naming.StringRefAddr) Enumeration(java.util.Enumeration) Reference(javax.naming.Reference) Properties(java.util.Properties)

Example 10 with RefAddr

use of javax.naming.RefAddr in project druid by alibaba.

the class DruidDataSourceFactory method getObjectInstance.

@Override
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
    // that specify a class name of "javax.sql.DataSource"
    if ((obj == null) || !(obj instanceof Reference)) {
        return null;
    }
    Reference ref = (Reference) obj;
    if (//
    (!"javax.sql.DataSource".equals(ref.getClassName())) && //
    (!"com.alibaba.druid.pool.DruidDataSource".equals(ref.getClassName()))) {
        return null;
    }
    Properties properties = new Properties();
    for (int i = 0; i < ALL_PROPERTIES.length; i++) {
        String propertyName = ALL_PROPERTIES[i];
        RefAddr ra = ref.get(propertyName);
        if (ra != null) {
            String propertyValue = ra.getContent().toString();
            properties.setProperty(propertyName, propertyValue);
        }
    }
    return createDataSourceInternal(properties);
}
Also used : RefAddr(javax.naming.RefAddr) Reference(javax.naming.Reference) Properties(java.util.Properties)

Aggregations

RefAddr (javax.naming.RefAddr)33 Reference (javax.naming.Reference)22 Properties (java.util.Properties)8 NamingException (javax.naming.NamingException)6 StringRefAddr (javax.naming.StringRefAddr)6 InitialContext (javax.naming.InitialContext)4 ObjectFactory (javax.naming.spi.ObjectFactory)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 MalformedURLException (java.net.MalformedURLException)2 ArrayList (java.util.ArrayList)2 Enumeration (java.util.Enumeration)2 NameNotFoundException (javax.naming.NameNotFoundException)2 DirObjectFactory (javax.naming.spi.DirObjectFactory)2 DruidDataSourceFactory (com.alibaba.druid.pool.DruidDataSourceFactory)1 MongoClient (com.mongodb.MongoClient)1 MongoClientURI (com.mongodb.MongoClientURI)1 MongoException (com.mongodb.MongoException)1 BeanInfo (java.beans.BeanInfo)1 PropertyDescriptor (java.beans.PropertyDescriptor)1