Search in sources :

Example 71 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 72 with Reference

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

the class TestContext method lookup.

@Override
public Object lookup(String name) throws NamingException {
    if (name.length() == 0) {
        return this;
    }
    Object result = treeBindings.get(name);
    if (result == null) {
        result = bindings.get(name);
    }
    if (result == null) {
        int pos = name.indexOf(':');
        if (pos > 0) {
            String scheme = name.substring(0, pos);
            Context ctx = NamingManager.getURLContext(scheme, environment);
            if (ctx == null) {
                throw new NamingException("scheme " + scheme + " not recognized");
            }
            return ctx.lookup(name);
        } else {
            // Split out the first name of the path
            // and look for it in the bindings map.
            CompositeName path = new CompositeName(name);
            if (path.size() == 0) {
                return this;
            } else {
                String first = path.get(0);
                Object obj = bindings.get(first);
                if (obj == null) {
                    throw new NameNotFoundException(name);
                } else if (obj instanceof Context && path.size() > 1) {
                    Context subContext = (Context) obj;
                    obj = subContext.lookup(path.getSuffix(1));
                }
                return obj;
            }
        }
    }
    if (result instanceof LinkRef) {
        LinkRef ref = (LinkRef) result;
        result = lookup(ref.getLinkName());
    }
    if (result instanceof Reference) {
        try {
            result = NamingManager.getObjectInstance(result, null, null, this.environment);
        } catch (NamingException e) {
            throw e;
        } catch (Exception e) {
            throw (NamingException) new NamingException("could not look up : " + name).initCause(e);
        }
    }
    if (result instanceof TestContext) {
        String prefix = getNameInNamespace();
        if (prefix.length() > 0) {
            prefix = prefix + SEPARATOR;
        }
        result = new TestContext((TestContext) result, environment, prefix + name);
    }
    return result;
}
Also used : Context(javax.naming.Context) NameNotFoundException(javax.naming.NameNotFoundException) Reference(javax.naming.Reference) CompositeName(javax.naming.CompositeName) NamingException(javax.naming.NamingException) NotContextException(javax.naming.NotContextException) NamingException(javax.naming.NamingException) OperationNotSupportedException(javax.naming.OperationNotSupportedException) NameNotFoundException(javax.naming.NameNotFoundException) LinkRef(javax.naming.LinkRef)

Example 73 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 74 with Reference

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

the class ReferenceableTest method testReferenceCF.

@Test
public void testReferenceCF() throws Exception {
    Reference cfRef = ((Referenceable) cf).getReference();
    String factoryName = cfRef.getFactoryClassName();
    Class<?> factoryClass = Class.forName(factoryName);
    ObjectFactory factory = (ObjectFactory) factoryClass.newInstance();
    Object instance = factory.getObjectInstance(cfRef, null, null, null);
    ProxyAssertSupport.assertTrue(instance instanceof ActiveMQConnectionFactory);
    ActiveMQJMSConnectionFactory cf2 = (ActiveMQJMSConnectionFactory) instance;
    simpleSendReceive(cf2, queue1);
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) Referenceable(javax.naming.Referenceable) ObjectFactory(javax.naming.spi.ObjectFactory) Reference(javax.naming.Reference) ActiveMQJMSConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory) Test(org.junit.Test)

Example 75 with Reference

use of javax.naming.Reference in project tomcat70 by apache.

the class GenericNamingResourcesFactory method getObjectInstance.

@Override
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
    if ((obj == null) || !(obj instanceof Reference)) {
        return null;
    }
    Reference ref = (Reference) obj;
    Enumeration<RefAddr> refs = ref.getAll();
    String type = ref.getClassName();
    Object o = Class.forName(type).newInstance();
    while (refs.hasMoreElements()) {
        RefAddr addr = refs.nextElement();
        String param = addr.getType();
        String value = null;
        if (addr.getContent() != null) {
            value = addr.getContent().toString();
        }
        if (setProperty(o, param, value, false)) {
        } else {
            log.debug("Property not configured[" + param + "]. No setter found on[" + o + "].");
        }
    }
    return o;
}
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