Search in sources :

Example 66 with Reference

use of javax.naming.Reference in project activemq-artemis by apache.

the class JNDIReferenceFactory method getObjectInstance.

/**
 * This will be called by a JNDIprovider when a Reference is retrieved from
 * a JNDI store - and generates the original instance
 *
 * @param object
 *      the Reference object
 * @param name
 *      the JNDI name
 * @param nameCtx
 *      the context
 * @param environment
 *      the environment settings used by JNDI
 *
 * @return the instance built from the Reference object
 *
 * @throws Exception
 *       if building the instance from Reference fails (usually class not found)
 */
@Override
public Object getObjectInstance(Object object, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
    Object result = null;
    if (object instanceof Reference) {
        Reference reference = (Reference) object;
        Class<?> theClass = loadClass(this, reference.getClassName());
        if (JNDIStorable.class.isAssignableFrom(theClass)) {
            JNDIStorable store = (JNDIStorable) theClass.newInstance();
            store.setProperties(getProperties(reference));
            result = store;
        }
    } else {
        throw new RuntimeException("Object " + object + " is not a reference");
    }
    return result;
}
Also used : Reference(javax.naming.Reference)

Example 67 with Reference

use of javax.naming.Reference in project activemq-artemis by apache.

the class InVMContext method lookup.

@Override
public Object lookup(String name) throws NamingException {
    name = trimSlashes(name);
    int i = name.indexOf("/");
    String tok = i == -1 ? name : name.substring(0, i);
    Object value = map.get(tok);
    if (value == null) {
        throw new NameNotFoundException("Name not found: " + tok);
    }
    if (value instanceof InVMContext && i != -1) {
        return ((InVMContext) value).lookup(name.substring(i));
    }
    if (value instanceof Reference) {
        Reference ref = (Reference) value;
        RefAddr refAddr = ref.get("nns");
        // we only deal with references create by NonSerializableFactory
        String key = (String) refAddr.getContent();
        return NonSerializableFactory.lookup(key);
    } else {
        return value;
    }
}
Also used : RefAddr(javax.naming.RefAddr) NameNotFoundException(javax.naming.NameNotFoundException) Reference(javax.naming.Reference)

Example 68 with Reference

use of javax.naming.Reference in project activemq-artemis by apache.

the class StringRefAddrReferenceTest method testActiveMQQueueFromPropertiesJNDI.

@Test(timeout = 10000)
public void testActiveMQQueueFromPropertiesJNDI() throws Exception {
    Properties properties = new Properties();
    properties.setProperty(TYPE, ActiveMQQueue.class.getName());
    properties.setProperty(FACTORY, JNDIReferenceFactory.class.getName());
    String address = "foo.bar.queue";
    properties.setProperty("address", address);
    Reference reference = from(properties);
    ActiveMQQueue object = getObject(reference, ActiveMQQueue.class);
    assertEquals(address, object.getAddress());
}
Also used : Reference(javax.naming.Reference) ActiveMQQueue(org.apache.activemq.artemis.jms.client.ActiveMQQueue) JNDIReferenceFactory(org.apache.activemq.artemis.jndi.JNDIReferenceFactory) Properties(java.util.Properties) Test(org.junit.Test)

Example 69 with Reference

use of javax.naming.Reference in project activemq-artemis by apache.

the class NonSerializableFactory method getObjectInstance.

@Override
public Object getObjectInstance(final Object obj, final Name name, final Context nameCtx, final Hashtable<?, ?> env) throws Exception {
    Reference ref = (Reference) obj;
    RefAddr addr = ref.get("nns");
    String key = (String) addr.getContent();
    return NonSerializableFactory.getWrapperMap().get(key);
}
Also used : RefAddr(javax.naming.RefAddr) Reference(javax.naming.Reference)

Example 70 with Reference

use of javax.naming.Reference in project activemq-artemis by apache.

the class NonSerializableFactory method getObjectInstance.

@Override
public Object getObjectInstance(final Object obj, final Name name, final Context nameCtx, final Hashtable<?, ?> env) throws Exception {
    Reference ref = (Reference) obj;
    RefAddr addr = ref.get("nns");
    String key = (String) addr.getContent();
    return NonSerializableFactory.getWrapperMap().get(key);
}
Also used : RefAddr(javax.naming.RefAddr) Reference(javax.naming.Reference)

Aggregations

Reference (javax.naming.Reference)226 NamingException (javax.naming.NamingException)79 RefAddr (javax.naming.RefAddr)59 StringRefAddr (javax.naming.StringRefAddr)54 Context (javax.naming.Context)41 NameNotFoundException (javax.naming.NameNotFoundException)40 InitialContext (javax.naming.InitialContext)37 Test (org.junit.Test)33 Name (javax.naming.Name)30 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)28 Properties (java.util.Properties)26 OperationNotSupportedException (javax.naming.OperationNotSupportedException)25 NotContextException (javax.naming.NotContextException)24 ObjectFactory (javax.naming.spi.ObjectFactory)23 CompositeName (javax.naming.CompositeName)21 Referenceable (javax.naming.Referenceable)18 Binding (javax.naming.Binding)17 CompoundName (javax.naming.CompoundName)16 LinkRef (javax.naming.LinkRef)15 Hashtable (java.util.Hashtable)12