use of org.apache.aries.jndi.urls.URLObjectFactoryFinder in project aries by apache.
the class ContextHelper method getURLObjectFactory.
public static final ServicePair<ObjectFactory> getURLObjectFactory(final BundleContext ctx, String urlScheme, Hashtable<?, ?> environment) throws NamingException {
ServicePair<ObjectFactory> result = null;
ServiceReference ref = ServiceTrackerCustomizers.URL_FACTORY_CACHE.find(urlScheme);
if (ref == null) {
ServiceReference[] refs = AccessController.doPrivileged(new PrivilegedAction<ServiceReference[]>() {
public ServiceReference[] run() {
return Activator.getURLObectFactoryFinderServices();
}
});
if (refs != null) {
for (final ServiceReference finderRef : refs) {
URLObjectFactoryFinder finder = (URLObjectFactoryFinder) Utils.getServicePrivileged(ctx, finderRef);
if (finder != null) {
ObjectFactory f = finder.findFactory(urlScheme, environment);
if (f != null) {
result = new ServicePair<ObjectFactory>(ctx, finderRef, f);
break;
} else {
ctx.ungetService(finderRef);
}
}
}
}
} else {
result = new ServicePair<ObjectFactory>(ctx, ref);
}
return result;
}
use of org.apache.aries.jndi.urls.URLObjectFactoryFinder in project aries by apache.
the class ObjectFactoryTest method testURLReferenceUsingURLObjectFactoryFinder.
@Test
public void testURLReferenceUsingURLObjectFactoryFinder() throws Exception {
String testObject = "Test object";
URLObjectFactoryFinder factory = Skeleton.newMock(URLObjectFactoryFinder.class);
Skeleton.getSkeleton(factory).setReturnValue(new MethodCall(ObjectFactory.class, "getObjectInstance", Object.class, Name.class, Context.class, Hashtable.class), testObject);
bc.registerService(URLObjectFactoryFinder.class.getName(), factory, (Dictionary) new Properties());
Reference ref = new Reference(null);
ref.add(new StringRefAddr("URL", "wibble"));
Object obj = NamingManager.getObjectInstance(ref, null, null, env);
assertEquals("The naming manager should have returned the test object", testObject, obj);
}
Aggregations