use of javax.naming.spi.ObjectFactory in project wildfly by wildfly.
the class ObjectFactoryBuilder method getObjectInstance.
/**
* Create an object instance.
*
* @param ref Object containing reference information
* @param name The name relative to nameCtx
* @param nameCtx The naming context
* @param environment The environment information
* @param attributes The directory attributes
* @return The object
* @throws Exception If any error occur
*/
public Object getObjectInstance(final Object ref, final Name name, final Context nameCtx, final Hashtable<?, ?> environment, final Attributes attributes) throws Exception {
final ClassLoader classLoader = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
if (classLoader == null) {
return ref;
}
final String factoriesProp = (String) environment.get(Context.OBJECT_FACTORIES);
if (factoriesProp != null) {
final String[] classes = factoriesProp.split(":");
for (String className : classes) {
try {
final Class<?> factoryClass = classLoader.loadClass(className);
final ObjectFactory objectFactory = ObjectFactory.class.cast(factoryClass.newInstance());
final Object result;
if (objectFactory instanceof DirObjectFactory) {
result = DirObjectFactory.class.cast(objectFactory).getObjectInstance(ref, name, nameCtx, environment, attributes);
} else {
result = objectFactory.getObjectInstance(ref, name, nameCtx, environment);
}
if (result != null) {
return result;
}
} catch (Throwable ignored) {
}
}
}
return ref;
}
use of javax.naming.spi.ObjectFactory 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.spi.ObjectFactory in project wildfly by wildfly.
the class ObjectFactoryBuilder method getObjectInstance.
/**
* Create an object instance.
*
* @param ref Object containing reference information
* @param name The name relative to nameCtx
* @param nameCtx The naming context
* @param environment The environment information
* @return The object
* @throws Exception If any error occur
*/
public Object getObjectInstance(final Object ref, final Name name, final Context nameCtx, final Hashtable<?, ?> environment) throws Exception {
final ClassLoader classLoader = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
if (classLoader == null) {
return ref;
}
final String factoriesProp = (String) environment.get(Context.OBJECT_FACTORIES);
if (factoriesProp != null) {
final String[] classes = factoriesProp.split(":");
for (String className : classes) {
try {
final Class<?> factoryClass = classLoader.loadClass(className);
final ObjectFactory objectFactory = ObjectFactory.class.cast(factoryClass.newInstance());
final Object result = objectFactory.getObjectInstance(ref, name, nameCtx, environment);
if (result != null) {
return result;
}
} catch (Throwable ignored) {
}
}
}
return ref;
}
use of javax.naming.spi.ObjectFactory in project tomee by apache.
the class IvmContext method getFederatedFactories.
public static ObjectFactory[] getFederatedFactories() throws NamingException {
if (federatedFactories == null) {
final Set<ObjectFactory> factories = new HashSet<>();
final String urlPackagePrefixes = getUrlPackagePrefixes();
if (urlPackagePrefixes == null) {
return new ObjectFactory[0];
}
for (final StringTokenizer tokenizer = new StringTokenizer(urlPackagePrefixes, ":"); tokenizer.hasMoreTokens(); ) {
final String urlPackagePrefix = tokenizer.nextToken();
final String className = urlPackagePrefix + ".java.javaURLContextFactory";
if (className.equals("org.apache.openejb.core.ivm.naming.java.javaURLContextFactory")) {
continue;
}
try {
final ClassLoader cl = ClassLoaderUtil.getContextClassLoader();
final Class factoryClass = Class.forName(className, true, cl);
final ObjectFactory factoryInstance = (ObjectFactory) factoryClass.newInstance();
factories.add(factoryInstance);
} catch (final ClassNotFoundException cnfe) {
// no-op
} catch (final Throwable e) {
final NamingException ne = new NamingException("Federation failed: Cannot instantiate " + className);
ne.setRootCause(e);
throw ne;
}
}
final Object[] temp = factories.toArray();
federatedFactories = new ObjectFactory[temp.length];
System.arraycopy(temp, 0, federatedFactories, 0, federatedFactories.length);
}
return federatedFactories;
}
use of javax.naming.spi.ObjectFactory in project tomee by apache.
the class IvmContext method federate.
protected Object federate(final String compositName) throws NamingException {
final ObjectFactory[] factories = getFederatedFactories();
for (final ObjectFactory factory : factories) {
try {
final CompositeName name = new CompositeName(compositName);
final Object obj = factory.getObjectInstance(null, name, null, null);
if (obj instanceof Context) {
return ((Context) obj).lookup(compositName);
} else if (obj != null) {
return obj;
}
} catch (final Exception doNothing) {
// no-op
}
}
throw new NameNotFoundException("Name \"" + compositName + "\" not found.");
}
Aggregations