Search in sources :

Example 36 with ObjectFactory

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);
}
Also used : ObjectFactory(javax.naming.spi.ObjectFactory) Reference(javax.naming.Reference) ActiveMQDestination(org.apache.activemq.artemis.jms.client.ActiveMQDestination) Test(org.junit.Test)

Example 37 with ObjectFactory

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);
}
Also used : Referenceable(javax.naming.Referenceable) ObjectFactory(javax.naming.spi.ObjectFactory) Reference(javax.naming.Reference) ActiveMQQueue(org.apache.activemq.artemis.jms.client.ActiveMQQueue) ActiveMQDestination(org.apache.activemq.artemis.jms.client.ActiveMQDestination) Test(org.junit.Test)

Example 38 with ObjectFactory

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);
}
Also used : ActiveMQTopic(org.apache.activemq.artemis.jms.client.ActiveMQTopic) Referenceable(javax.naming.Referenceable) ObjectFactory(javax.naming.spi.ObjectFactory) Reference(javax.naming.Reference) ActiveMQDestination(org.apache.activemq.artemis.jms.client.ActiveMQDestination) Test(org.junit.Test)

Example 39 with ObjectFactory

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());
}
Also used : JdbcDataSourceFactory(org.h2.jdbcx.JdbcDataSourceFactory) ObjectFactory(javax.naming.spi.ObjectFactory) StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference) JdbcDataSource(org.h2.jdbcx.JdbcDataSource)

Example 40 with ObjectFactory

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();
}
Also used : ExternalContextBinderService(org.jboss.as.naming.service.ExternalContextBinderService) BinderService(org.jboss.as.naming.service.BinderService) ObjectFactory(javax.naming.spi.ObjectFactory) ExternalContextObjectFactory(org.jboss.as.naming.ExternalContextObjectFactory) ServiceBasedNamingStore(org.jboss.as.naming.ServiceBasedNamingStore) ServiceTarget(org.jboss.msc.service.ServiceTarget) ContextListAndJndiViewManagedReferenceFactory(org.jboss.as.naming.ContextListAndJndiViewManagedReferenceFactory) ContextNames(org.jboss.as.naming.deployment.ContextNames)

Aggregations

ObjectFactory (javax.naming.spi.ObjectFactory)59 Reference (javax.naming.Reference)22 NamingException (javax.naming.NamingException)21 Test (org.junit.Test)16 DirObjectFactory (javax.naming.spi.DirObjectFactory)14 RefAddr (javax.naming.RefAddr)12 Hashtable (java.util.Hashtable)10 BundleContext (org.osgi.framework.BundleContext)9 Context (javax.naming.Context)7 MethodCall (org.apache.aries.unittest.mocks.MethodCall)6 ServiceAwareObjectFactory (org.jboss.as.naming.ServiceAwareObjectFactory)6 Name (javax.naming.Name)5 Referenceable (javax.naming.Referenceable)5 ServiceReference (org.osgi.framework.ServiceReference)5 InitialContext (javax.naming.InitialContext)4 StringRefAddr (javax.naming.StringRefAddr)4 InitialLdapContext (javax.naming.ldap.InitialLdapContext)4 LdapContext (javax.naming.ldap.LdapContext)4 Properties (java.util.Properties)3 ObjectFactoryBuilder (javax.naming.spi.ObjectFactoryBuilder)3