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