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;
}
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;
}
}
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());
}
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);
}
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);
}
Aggregations