Search in sources :

Example 11 with RefAddr

use of javax.naming.RefAddr in project HikariCP by brettwooldridge.

the class HikariJNDIFactory method getObjectInstance.

@Override
public synchronized Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
    // We only know how to deal with <code>javax.naming.Reference</code> that specify a class name of "javax.sql.DataSource"
    if (!(obj instanceof Reference)) {
        return null;
    }
    Reference ref = (Reference) obj;
    if (!"javax.sql.DataSource".equals(ref.getClassName())) {
        throw new NamingException(ref.getClassName() + " is not a valid class name/type for this JNDI factory.");
    }
    Set<String> hikariPropSet = PropertyElf.getPropertyNames(HikariConfig.class);
    Properties properties = new Properties();
    Enumeration<RefAddr> enumeration = ref.getAll();
    while (enumeration.hasMoreElements()) {
        RefAddr element = enumeration.nextElement();
        String type = element.getType();
        if (type.startsWith("dataSource.") || hikariPropSet.contains(type)) {
            properties.setProperty(type, element.getContent().toString());
        }
    }
    return createDataSource(properties, nameCtx);
}
Also used : RefAddr(javax.naming.RefAddr) Reference(javax.naming.Reference) NamingException(javax.naming.NamingException) Properties(java.util.Properties)

Example 12 with RefAddr

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

the class ObjectFactoryHelper method getObjectInstanceUsingRefAddress.

private Object getObjectInstanceUsingRefAddress(Enumeration<RefAddr> addresses, Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
    Object result = null;
    while (addresses.hasMoreElements()) {
        RefAddr address = addresses.nextElement();
        if (address instanceof StringRefAddr && "URL".equals(address.getType())) {
            String urlScheme = getUrlScheme((String) address.getContent());
            ServicePair<ObjectFactory> factoryService = ContextHelper.getURLObjectFactory(callerContext, urlScheme, environment);
            if (factoryService != null) {
                ObjectFactory factory = factoryService.get();
                String value = (String) address.getContent();
                try {
                    result = factory.getObjectInstance(value, name, nameCtx, environment);
                } finally {
                    factoryService.unget();
                }
                // loop we are in.
                if (result != null && result != obj) {
                    break;
                }
            }
        }
    }
    return (result == null) ? obj : result;
}
Also used : RefAddr(javax.naming.RefAddr) StringRefAddr(javax.naming.StringRefAddr) DirObjectFactory(javax.naming.spi.DirObjectFactory) ObjectFactory(javax.naming.spi.ObjectFactory) StringRefAddr(javax.naming.StringRefAddr)

Example 13 with RefAddr

use of javax.naming.RefAddr in project wildfly by wildfly.

the class ObjectFactoryBuilder method lookForURLs.

static ObjectFactory lookForURLs(Reference ref, Hashtable environment) throws NamingException {
    for (int i = 0; i < ref.size(); i++) {
        RefAddr addr = ref.get(i);
        if (addr instanceof StringRefAddr && addr.getType().equalsIgnoreCase("URL")) {
            String url = (String) addr.getContent();
            ObjectFactory answer = processURL(url, environment);
            if (answer != null) {
                return answer;
            }
        }
    }
    return null;
}
Also used : RefAddr(javax.naming.RefAddr) StringRefAddr(javax.naming.StringRefAddr) DirObjectFactory(javax.naming.spi.DirObjectFactory) ServiceAwareObjectFactory(org.jboss.as.naming.ServiceAwareObjectFactory) ObjectFactory(javax.naming.spi.ObjectFactory) StringRefAddr(javax.naming.StringRefAddr)

Example 14 with RefAddr

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

the class NamingUtil method isPropertyTrue.

public static boolean isPropertyTrue(final Reference ref, final String name) {
    final RefAddr addr = ref.get(name);
    if (addr == null) {
        return false;
    }
    final Object value = addr.getContent();
    return Boolean.parseBoolean(String.valueOf(value));
}
Also used : RefAddr(javax.naming.RefAddr)

Example 15 with RefAddr

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

the class GenericNamingResourcesFactory method getObjectInstance.

@Override
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
    if ((obj == null) || !(obj instanceof Reference)) {
        return null;
    }
    Reference ref = (Reference) obj;
    Enumeration<RefAddr> refs = ref.getAll();
    String type = ref.getClassName();
    Object o = ClassLoaderUtil.loadClass(type, GenericNamingResourcesFactory.class.getClassLoader(), Thread.currentThread().getContextClassLoader()).newInstance();
    while (refs.hasMoreElements()) {
        RefAddr addr = refs.nextElement();
        String param = addr.getType();
        String value = null;
        if (addr.getContent() != null) {
            value = addr.getContent().toString();
        }
        if (setProperty(o, param, value)) {
        } else {
            log.debug("Property not configured[" + param + "]. No setter found on[" + o + "].");
        }
    }
    return o;
}
Also used : RefAddr(javax.naming.RefAddr) Reference(javax.naming.Reference)

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