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);
}
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;
}
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;
}
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));
}
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;
}
Aggregations