use of javax.naming.Binding in project wildfly by wildfly.
the class ServiceBasedNamingStoreTestCase method testListBindings.
@Test
public void testListBindings() throws Exception {
final Object value = new Object();
bindObject(ServiceName.JBOSS.append("TestBean"), value);
bindObject(ServiceName.JBOSS.append("foo", "TestBean"), value);
bindObject(ServiceName.JBOSS.append("foo", "bar", "TestBean"), value);
bindObject(ServiceName.JBOSS.append("foo", "bar", "baz", "TestBean"), value);
store.add(ServiceName.JBOSS.append("foos", "bar"));
store.add(ServiceName.JBOSS.append("fo", "bar"));
store.add(ServiceName.JBOSS.append("foo", "ba", "baz"));
store.add(ServiceName.JBOSS.append("foo", "bart", "baz"));
store.add(ServiceName.JBOSS.append("foo", "bar", "ba"));
store.add(ServiceName.JBOSS.append("foo", "bar", "bazt"));
store.add(ServiceName.JBOSS.append("foo", "bar", "art"));
store.add(ServiceName.JBOSS.append("other", "one"));
List<Binding> list = store.listBindings(new CompositeName(""));
assertEquals(5, list.size());
assertContains(list, "TestBean", Object.class);
assertContains(list, "foo", NamingContext.class);
assertContains(list, "fo", NamingContext.class);
assertContains(list, "foos", NamingContext.class);
assertContains(list, "other", NamingContext.class);
list = store.listBindings(new CompositeName("foo"));
assertEquals(4, list.size());
assertContains(list, "TestBean", Object.class);
assertContains(list, "ba", NamingContext.class);
assertContains(list, "bart", NamingContext.class);
assertContains(list, "bar", NamingContext.class);
for (Binding binding : list) {
if (binding.getName().equals("bar")) {
final Object bean = Context.class.cast(binding.getObject()).lookup("TestBean");
assertNotNull(bean);
assertEquals(value, bean);
}
}
}
use of javax.naming.Binding in project wildfly by wildfly.
the class InMemoryNamingStoreTestCase method testListBindings.
@Test
public void testListBindings() throws Exception {
final Name name = new CompositeName("test");
final Object object = new Object();
nameStore.bind(name, object);
final Name nameTwo = new CompositeName("testTwo");
final Object objectTwo = new Object();
nameStore.bind(nameTwo, objectTwo);
final Name nameThree = new CompositeName("testThree");
final Object objectThree = new Object();
nameStore.bind(nameThree, objectThree);
nameStore.bind(new CompositeName("testContext/test"), "test");
final List<Binding> results = nameStore.listBindings(new CompositeName());
assertEquals(4, results.size());
final Set<String> expected = new HashSet<String>(Arrays.asList("test", "testTwo", "testThree", "testContext"));
for (Binding result : results) {
final String resultName = result.getName();
if ("test".equals(resultName)) {
assertEquals(Object.class.getName(), result.getClassName());
assertEquals(object, result.getObject());
} else if ("testTwo".equals(resultName)) {
assertEquals(Object.class.getName(), result.getClassName());
assertEquals(objectTwo, result.getObject());
} else if ("testThree".equals(resultName)) {
assertEquals(Object.class.getName(), result.getClassName());
assertEquals(objectThree, result.getObject());
} else if ("testContext".equals(resultName)) {
assertEquals(Context.class.getName(), result.getClassName());
} else {
fail("Unknown result name: " + resultName);
}
expected.remove(resultName);
}
assertTrue("Not all expected results were returned", expected.isEmpty());
}
use of javax.naming.Binding in project wildfly by wildfly.
the class NamingContextTestCase method testListBindingsWithContinuation.
@Test
@SuppressWarnings("unchecked")
public void testListBindingsWithContinuation() throws Exception {
bindListWithContinuations();
NamingEnumeration<Binding> results = namingContext.listBindings(new CompositeName("comp"));
checkListWithContinuationsResults(results);
// the same with security permissions
results = (NamingEnumeration<Binding>) testActionPermission(JndiPermission.ACTION_LIST_BINDINGS, Arrays.asList(new JndiPermission("test", "listBindings")), namingContext, "comp");
checkListWithContinuationsResults(results);
}
use of javax.naming.Binding in project tomee by apache.
the class Debug method contextToMap.
public static void contextToMap(final Context context, final String baseName, final Map<String, Object> results) throws NamingException {
final NamingEnumeration<Binding> namingEnumeration = context.listBindings("");
while (namingEnumeration.hasMoreElements()) {
final Binding binding = namingEnumeration.nextElement();
final String name = binding.getName();
final String fullName = baseName + name;
final Object object = binding.getObject();
results.put(fullName, object);
if (object instanceof Context) {
contextToMap((Context) object, fullName + "/", results);
}
}
}
use of javax.naming.Binding in project tomee by apache.
the class Assembler method destroyResourceTree.
private Collection<DestroyingResource> destroyResourceTree(final String base, final NamingEnumeration<Binding> namingEnumeration) {
final List<DestroyingResource> resources = new LinkedList<>();
while (namingEnumeration != null && namingEnumeration.hasMoreElements()) {
final Binding binding = namingEnumeration.nextElement();
final Object object = binding.getObject();
if (Context.class.isInstance(object)) {
try {
resources.addAll(destroyResourceTree(IvmContext.class.isInstance(object) ? IvmContext.class.cast(object).mynode.getAtomicName() : "", Context.class.cast(object).listBindings("")));
} catch (final Exception ignored) {
// no-op
}
} else {
resources.add(new DestroyingResource((base == null || base.isEmpty() ? "" : (base + '/')) + binding.getName(), binding.getClassName(), object));
}
}
resources.sort(new // end by destroying RA after having closed CF pool (for jms for instance)
Comparator<DestroyingResource>() {
@Override
public int compare(final DestroyingResource o1, final DestroyingResource o2) {
final boolean ra1 = isRa(o1.instance);
final boolean ra2 = isRa(o2.instance);
if (ra2 && !ra1) {
return -1;
}
if (ra1 && !ra2) {
return 1;
}
// TODO: handle dependencies there too
return o1.name.compareTo(o2.name);
}
private boolean isRa(final Object instance) {
return ResourceAdapter.class.isInstance(instance) || ResourceAdapterReference.class.isInstance(instance);
}
});
for (final DestroyingResource resource : resources) {
try {
destroyResource(resource.name, resource.clazz, resource.instance);
} catch (final Throwable th) {
logger.debug(th.getMessage(), th);
}
}
return resources;
}
Aggregations