use of javax.naming.spi.ObjectFactory in project activemq-artemis by apache.
the class DestinationObjectFactoryTest method testReference.
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
@Test
public void testReference() throws Exception {
ActiveMQDestination queue = (ActiveMQDestination) ActiveMQJMSClient.createQueue(RandomUtil.randomString());
Reference reference = queue.getReference();
String factoryName = reference.getFactoryClassName();
Class<?> factoryClass = Class.forName(factoryName);
ObjectFactory factory = (ObjectFactory) factoryClass.newInstance();
Object object = factory.getObjectInstance(reference, null, null, null);
Assert.assertNotNull(object);
Assert.assertTrue(object instanceof ActiveMQDestination);
Assert.assertEquals(queue, object);
}
use of javax.naming.spi.ObjectFactory in project activemq-artemis by apache.
the class ReferenceableTest method testReferenceQueue.
@Test
public void testReferenceQueue() throws Exception {
Reference queueRef = ((Referenceable) queue1).getReference();
String factoryName = queueRef.getFactoryClassName();
Class<?> factoryClass = Class.forName(factoryName);
ObjectFactory factory = (ObjectFactory) factoryClass.newInstance();
Object instance = factory.getObjectInstance(queueRef, null, null, null);
ProxyAssertSupport.assertTrue(instance instanceof ActiveMQDestination);
ActiveMQQueue queue2 = (ActiveMQQueue) instance;
ProxyAssertSupport.assertEquals(queue1.getQueueName(), queue2.getQueueName());
simpleSendReceive(cf, queue2);
}
use of javax.naming.spi.ObjectFactory in project activemq-artemis by apache.
the class ReferenceableTest method testReferenceTopic.
@Test
public void testReferenceTopic() throws Exception {
Reference topicRef = ((Referenceable) ActiveMQServerTestCase.topic1).getReference();
String factoryName = topicRef.getFactoryClassName();
Class factoryClass = Class.forName(factoryName);
ObjectFactory factory = (ObjectFactory) factoryClass.newInstance();
Object instance = factory.getObjectInstance(topicRef, null, null, null);
ProxyAssertSupport.assertTrue(instance instanceof ActiveMQDestination);
ActiveMQTopic topic2 = (ActiveMQTopic) instance;
ProxyAssertSupport.assertEquals(ActiveMQServerTestCase.topic1.getTopicName(), topic2.getTopicName());
simpleSendReceive(cf, topic2);
}
use of javax.naming.spi.ObjectFactory in project h2database by h2database.
the class TestDataSource method testDataSourceFactory.
private void testDataSourceFactory() throws Exception {
ObjectFactory factory = new JdbcDataSourceFactory();
assertTrue(null == factory.getObjectInstance("test", null, null, null));
Reference ref = new Reference("java.lang.String");
assertTrue(null == factory.getObjectInstance(ref, null, null, null));
ref = new Reference(JdbcDataSource.class.getName());
ref.add(new StringRefAddr("url", "jdbc:h2:mem:"));
ref.add(new StringRefAddr("user", "u"));
ref.add(new StringRefAddr("password", "p"));
ref.add(new StringRefAddr("loginTimeout", "1"));
ref.add(new StringRefAddr("description", "test"));
JdbcDataSource ds = (JdbcDataSource) factory.getObjectInstance(ref, null, null, null);
assertEquals(1, ds.getLoginTimeout());
assertEquals("test", ds.getDescription());
assertEquals("jdbc:h2:mem:", ds.getURL());
assertEquals("u", ds.getUser());
assertEquals("p", ds.getPassword());
Reference ref2 = ds.getReference();
assertEquals(ref.size(), ref2.size());
assertEquals(ref.get("url").getContent().toString(), ref2.get("url").getContent().toString());
assertEquals(ref.get("user").getContent().toString(), ref2.get("user").getContent().toString());
assertEquals(ref.get("password").getContent().toString(), ref2.get("password").getContent().toString());
assertEquals(ref.get("loginTimeout").getContent().toString(), ref2.get("loginTimeout").getContent().toString());
assertEquals(ref.get("description").getContent().toString(), ref2.get("description").getContent().toString());
ds.setPasswordChars("abc".toCharArray());
assertEquals("abc", ds.getPassword());
}
use of javax.naming.spi.ObjectFactory in project wildfly by wildfly.
the class NamingBindingAdd method installObjectFactory.
void installObjectFactory(final OperationContext context, final String name, final ModelNode model) throws OperationFailedException {
final ObjectFactory objectFactoryClassInstance = createObjectFactory(context, model);
final Hashtable<String, String> environment = getObjectFactoryEnvironment(context, model);
ContextListAndJndiViewManagedReferenceFactory factory = new ObjectFactoryManagedReference(objectFactoryClassInstance, name, environment);
final ServiceTarget serviceTarget = context.getServiceTarget();
final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(name);
final BinderService binderService = new BinderService(name, objectFactoryClassInstance);
binderService.getManagedObjectInjector().inject(new MutableManagedReferenceFactory(factory));
serviceTarget.addService(bindInfo.getBinderServiceName(), binderService).addDependency(bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector()).install();
}
Aggregations