Search in sources :

Example 16 with Binding

use of javax.naming.Binding in project geronimo-xbean by apache.

the class ContextFederation method getFederatedBindings.

public Map<String, Object> getFederatedBindings(String name) throws NamingException {
    Map<String, Object> bindings = new HashMap<String, Object>();
    for (Context context : getFederatedContexts()) {
        // list federated context
        try {
            NamingEnumeration namingEnumeration = context.listBindings(name);
            // add to bindings
            while (namingEnumeration.hasMoreElements()) {
                Binding binding = (Binding) namingEnumeration.nextElement();
                String bindingName = binding.getName();
                // don't overwrite existing bindings
                if (!bindings.containsKey(bindingName)) {
                    try {
                        bindings.put(bindingName, binding.getObject());
                    } catch (RuntimeException e) {
                        // if this is a wrapped NamingException, unwrap and throw the original
                        Throwable cause = e.getCause();
                        if (cause != null && cause instanceof NamingException) {
                            throw (NamingException) cause;
                        }
                        // Wrap this into a RuntimeException.
                        throw (NamingException) new NamingException("Could retrieve bound instance " + name).initCause(e);
                    }
                }
            }
        } catch (NotContextException e) {
        // this context does not include the supplied name
        }
    }
    return bindings;
}
Also used : Context(javax.naming.Context) Binding(javax.naming.Binding) NotContextException(javax.naming.NotContextException) HashMap(java.util.HashMap) NamingEnumeration(javax.naming.NamingEnumeration) NamingException(javax.naming.NamingException)

Example 17 with Binding

use of javax.naming.Binding in project geronimo-xbean by apache.

the class ContextUtil method listBindingsToMap.

public static Map<String, Object> listBindingsToMap(NamingEnumeration enumeration) {
    Map<String, Object> result = new HashMap<String, Object>();
    while (enumeration.hasMoreElements()) {
        Binding binding = (Binding) enumeration.nextElement();
        String name = binding.getName();
        result.put(name, binding.getObject());
    }
    return result;
}
Also used : Binding(javax.naming.Binding) HashMap(java.util.HashMap)

Example 18 with Binding

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

the class JNDIUtil method tearDownRecursively.

public static void tearDownRecursively(final Context c) throws Exception {
    for (NamingEnumeration<Binding> ne = c.listBindings(""); ne.hasMore(); ) {
        Binding b = ne.next();
        String name = b.getName();
        Object object = b.getObject();
        if (object instanceof Context) {
            JNDIUtil.tearDownRecursively((Context) object);
        }
        c.unbind(name);
    }
}
Also used : Binding(javax.naming.Binding) Context(javax.naming.Context)

Example 19 with Binding

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

the class InVMNamingContext method listBindings.

@Override
public NamingEnumeration<Binding> listBindings(String contextName) throws NamingException {
    contextName = trimSlashes(contextName);
    if (!"".equals(contextName) && !".".equals(contextName)) {
        try {
            return ((InVMNamingContext) lookup(contextName)).listBindings("");
        } catch (Throwable t) {
            throw new NamingException(t.getMessage());
        }
    }
    List<Binding> l = new ArrayList<>();
    for (Object element : map.keySet()) {
        String name = (String) element;
        Object object = map.get(name);
        l.add(new Binding(name, object));
    }
    return new NamingEnumerationImpl<>(l.iterator());
}
Also used : Binding(javax.naming.Binding) ArrayList(java.util.ArrayList) NamingException(javax.naming.NamingException)

Example 20 with Binding

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

the class JNDITestSupport method assertBinding.

protected void assertBinding(Binding binding) throws NamingException {
    Object object = binding.getObject();
    assertTrue("Should have got a child context but got: " + object, object instanceof Context);
    Context childContext = (Context) object;
    NamingEnumeration<Binding> iter = childContext.listBindings("");
    while (iter.hasMore()) {
        Binding destinationBinding = iter.next();
        LOG.info("Found destination: " + destinationBinding.getName());
        Object destination = destinationBinding.getObject();
        assertTrue("Should have a Destination but got: " + destination, destination instanceof Destination);
    }
}
Also used : Context(javax.naming.Context) Binding(javax.naming.Binding) Destination(javax.jms.Destination)

Aggregations

Binding (javax.naming.Binding)69 NamingException (javax.naming.NamingException)36 Context (javax.naming.Context)31 InitialContext (javax.naming.InitialContext)29 NameNotFoundException (javax.naming.NameNotFoundException)22 Name (javax.naming.Name)19 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)19 NotContextException (javax.naming.NotContextException)18 OperationNotSupportedException (javax.naming.OperationNotSupportedException)18 Reference (javax.naming.Reference)17 CompoundName (javax.naming.CompoundName)16 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)10 NamingContext (org.eclipse.jetty.jndi.NamingContext)9 CompositeName (javax.naming.CompositeName)8 Test (org.junit.Test)8 HashMap (java.util.HashMap)7 NamingEnumeration (javax.naming.NamingEnumeration)5 ServletContext (javax.servlet.ServletContext)5 MalformedURLException (java.net.MalformedURLException)4