use of javax.naming.Name in project wildfly by wildfly.
the class NamingContext method lookupLink.
/** {@inheritDoc} */
public Object lookupLink(Name name) throws NamingException {
check(name, JndiPermission.ACTION_LOOKUP);
if (name.isEmpty()) {
return lookup(name);
}
try {
final Name absoluteName = getAbsoluteName(name);
Object link = namingStore.lookup(absoluteName);
if (!(link instanceof LinkRef) && link instanceof Reference) {
link = getObjectInstance(link, name, null);
}
return link;
} catch (Exception e) {
throw namingException(NamingLogger.ROOT_LOGGER.cannotLookupLink(), e, name);
}
}
use of javax.naming.Name in project wildfly by wildfly.
the class NamingContext method rebind.
/** {@inheritDoc} */
public void rebind(final Name name, Object object) throws NamingException {
check(name, JndiPermission.ACTION_REBIND);
if (namingStore instanceof WritableNamingStore) {
final Name absoluteName = getAbsoluteName(name);
if (object instanceof Referenceable) {
object = ((Referenceable) object).getReference();
}
getWritableNamingStore().rebind(absoluteName, object);
} else {
throw NamingLogger.ROOT_LOGGER.readOnlyNamingContext();
}
}
use of javax.naming.Name in project wildfly by wildfly.
the class NamingUtils method unbind.
/**
* Unbinds a name from ctx, and removes parents if they are empty
*
* @param ctx the parent JNDI Context under which the name will be unbound
* @param name The name to unbind
* @throws NamingException for any error
*/
public static void unbind(Context ctx, Name name) throws NamingException {
//unbind the end node in the name
ctx.unbind(name);
int sz = name.size();
// walk the tree backwards, stopping at the domain
while (--sz > 0) {
Name pname = name.getPrefix(sz);
try {
ctx.destroySubcontext(pname);
} catch (NamingException e) {
//log.trace("Unable to remove context " + pname, e);
break;
}
}
}
use of javax.naming.Name in project wildfly by wildfly.
the class NamingUtils method rebind.
/**
* Rebind val to name in ctx, and make sure that all intermediate contexts exist
*
* @param ctx the parent JNDI Context under which value will be bound
* @param name the name relative to ctx where value will be bound
* @param value the value to bind.
* @throws NamingException for any error
*/
public static void rebind(final Context ctx, final String name, final Object value) throws NamingException {
final Name n = ctx.getNameParser("").parse(name);
rebind(ctx, n, value);
}
use of javax.naming.Name in project wildfly by wildfly.
the class InMemoryNamingStoreTestCase method testList.
@Test
public void testList() throws Exception {
final Name name = new CompositeName("test");
final Object object = new Object();
nameStore.bind(name, object, Object.class);
final Name nameTwo = new CompositeName("testTwo");
final Object objectTwo = new Object();
nameStore.bind(nameTwo, objectTwo, Object.class);
final Name nameThree = new CompositeName("testThree");
final Object objectThree = new Object();
nameStore.bind(nameThree, objectThree, Object.class);
nameStore.bind(new CompositeName("testContext/test"), "test");
final List<NameClassPair> results = nameStore.list(new CompositeName());
assertEquals(4, results.size());
final Set<String> expected = new HashSet<String>(Arrays.asList("test", "testTwo", "testThree", "testContext"));
for (NameClassPair result : results) {
final String resultName = result.getName();
if ("test".equals(resultName) || "testTwo".equals(resultName) || "testThree".equals(resultName)) {
assertEquals(Object.class.getName(), result.getClassName());
} 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());
}
Aggregations