use of javax.naming.spi.ObjectFactory in project aries by apache.
the class ServiceRegistryContextTest method testJNDIRegistration.
/**
* This test checks that we correctly register and deregister the url context
* object factory in the service registry.
*/
@Test
public void testJNDIRegistration() {
ServiceReference ref = bc.getServiceReference(ObjectFactory.class.getName());
assertNotNull("The aries url context object factory was not registered", ref);
ObjectFactory factory = (ObjectFactory) bc.getService(ref);
assertNotNull("The aries url context object factory was null", factory);
}
use of javax.naming.spi.ObjectFactory in project aries by apache.
the class ObjectFactoryHelper method getObjectInstanceUsingObjectFactoryBuilders.
private Object getObjectInstanceUsingObjectFactoryBuilders(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment, Attributes attrs) throws Exception {
ObjectFactory factory = null;
for (ObjectFactoryBuilder ofb : Activator.getServices(callerContext, ObjectFactoryBuilder.class)) {
try {
factory = ofb.createObjectFactory(obj, environment);
} catch (NamingException e) {
// TODO: log it
}
if (factory != null) {
break;
}
}
Object result = null;
if (factory != null) {
result = getObjectFromFactory(obj, name, nameCtx, environment, attrs, factory);
}
return (result == null) ? obj : result;
}
use of javax.naming.spi.ObjectFactory in project aries by apache.
the class ObjectFactoryTest method testSpecifiedFactoryWithRegisteredButNotMatchingFactory.
@Test
public void testSpecifiedFactoryWithRegisteredButNotMatchingFactory() throws Exception {
String testObject = "Test object";
ObjectFactory factory = Skeleton.newMock(ObjectFactory.class);
Skeleton.getSkeleton(factory).setReturnValue(new MethodCall(ObjectFactory.class, "getObjectInstance", Object.class, Name.class, Context.class, Hashtable.class), testObject);
Reference ref = new Reference("dummy.class.name", "dummy.factory.class.name", "");
bc.registerService(new String[] { ObjectFactory.class.getName(), factory.getClass().getName() }, factory, null);
Object obj = NamingManager.getObjectInstance(ref, null, null, env);
assertSame("The naming manager should have returned the reference object", ref, obj);
}
use of javax.naming.spi.ObjectFactory in project aries by apache.
the class ObjectFactoryTest method testFactoriesThatDoUnsafeCastsAreIgnored.
@Test
public void testFactoriesThatDoUnsafeCastsAreIgnored() throws Exception {
Hashtable<String, Object> props = new Hashtable<String, Object>();
props.put("aries.object.factory.requires.reference", Boolean.TRUE);
bc.registerService(ObjectFactory.class.getName(), new ObjectFactory() {
public Object getObjectInstance(Object arg0, Name arg1, Context arg2, Hashtable<?, ?> arg3) throws Exception {
return (Reference) arg0;
}
}, props);
NamingManager.getObjectInstance("Some dummy data", null, null, env);
}
use of javax.naming.spi.ObjectFactory in project aries by apache.
the class ObjectFactoryTest method testReferenceWithNoClassName.
@Test
public void testReferenceWithNoClassName() throws Exception {
String testObject = "Test object";
ObjectFactory factory = Skeleton.newMock(ObjectFactory.class);
Skeleton.getSkeleton(factory).setReturnValue(new MethodCall(ObjectFactory.class, "getObjectInstance", Object.class, Name.class, Context.class, Hashtable.class), testObject);
bc.registerService(ObjectFactory.class.getName(), factory, null);
Reference ref = new Reference(null);
Object obj = NamingManager.getObjectInstance(ref, null, null, env);
assertEquals("The naming manager should have returned the test object", testObject, obj);
}
Aggregations