use of javax.naming.CompositeName in project wildfly by wildfly.
the class NamingEventCoordinatorTestCase method testFireSubTreeEvent.
@Test
public void testFireSubTreeEvent() throws Exception {
final NamingEventCoordinator coordinator = new NamingEventCoordinator();
final CollectingListener objectListener = new CollectingListener(0);
coordinator.addListener("test/path", EventContext.OBJECT_SCOPE, objectListener);
final CollectingListener subtreeListener = new CollectingListener(1);
coordinator.addListener("test", EventContext.SUBTREE_SCOPE, subtreeListener);
final CollectingListener oneLevelListener = new CollectingListener(0);
coordinator.addListener("test", EventContext.ONELEVEL_SCOPE, oneLevelListener);
coordinator.fireEvent(context, new CompositeName("test/path"), null, null, NamingEvent.OBJECT_ADDED, "bind", EventContext.SUBTREE_SCOPE);
subtreeListener.latch.await(1, TimeUnit.SECONDS);
assertTrue(objectListener.capturedEvents.isEmpty());
assertTrue(oneLevelListener.capturedEvents.isEmpty());
assertEquals(1, subtreeListener.capturedEvents.size());
}
use of javax.naming.CompositeName in project wildfly by wildfly.
the class NamingEventCoordinatorTestCase method testFireAllEvent.
@Test
public void testFireAllEvent() throws Exception {
final NamingEventCoordinator coordinator = new NamingEventCoordinator();
final CollectingListener objectListener = new CollectingListener(1);
coordinator.addListener("test/path", EventContext.OBJECT_SCOPE, objectListener);
final CollectingListener subtreeListener = new CollectingListener(1);
coordinator.addListener("test", EventContext.SUBTREE_SCOPE, subtreeListener);
final CollectingListener oneLevelListener = new CollectingListener(1);
coordinator.addListener("test", EventContext.ONELEVEL_SCOPE, oneLevelListener);
coordinator.fireEvent(context, new CompositeName("test/path"), null, null, NamingEvent.OBJECT_ADDED, "bind", EventContext.OBJECT_SCOPE, EventContext.ONELEVEL_SCOPE, EventContext.SUBTREE_SCOPE);
objectListener.latch.await(1, TimeUnit.SECONDS);
oneLevelListener.latch.await(1, TimeUnit.SECONDS);
subtreeListener.latch.await(1, TimeUnit.SECONDS);
assertEquals(1, objectListener.capturedEvents.size());
assertEquals(1, subtreeListener.capturedEvents.size());
assertEquals(1, oneLevelListener.capturedEvents.size());
}
use of javax.naming.CompositeName in project wildfly by wildfly.
the class ObjectFactoryTestCase method testBindAndRetrieveObjectFactoryFromNamingContext.
@Test
public void testBindAndRetrieveObjectFactoryFromNamingContext() throws Exception {
final Reference reference = new Reference("java.util.String", TestObjectFactory.class.getName(), null);
namingStore.bind(new CompositeName("test"), reference);
final Object result = namingContext.lookup("test");
assertTrue(result instanceof String);
assertEquals("Test ParsedResult", result);
}
use of javax.naming.CompositeName in project wildfly by wildfly.
the class ExceptionMapper method tryFed.
private static NamingException tryFed(NotFound e, CNCtx ctx, NameComponent[] inputName) throws NamingException {
NameComponent[] rest = ((NotFound) e).rest_of_name;
if (debug) {
}
// If one of those is not found, you get "aa" as 'rest'.
if (rest.length == 1 && inputName != null) {
// Check that we're not talking to 1.2/1.3 Sun tnameserv
NameComponent lastIn = inputName[inputName.length - 1];
if (rest[0].id.equals(lastIn.id) && rest[0].kind != null && rest[0].kind.equals(lastIn.kind)) {
// Might be legit
} else {
// Due to 1.2/1.3 bug that always returns single-item 'rest'
NamingException ne = new NameNotFoundException();
ne.setRemainingName(org.wildfly.iiop.openjdk.naming.jndi.CNNameParser.cosNameToName(rest));
ne.setRootCause(e);
throw ne;
}
}
// Fixed in 1.4; perform calculations based on correct (1.4) behavior
// Calculate the components of the name that has been resolved
NameComponent[] resolvedName = null;
int len = 0;
if (inputName != null && (inputName.length >= rest.length)) {
if (e.why == NotFoundReason.not_context) {
// First component of rest is found but not a context; keep it
// as part of resolved name
len = inputName.length - (rest.length - 1);
// Remove resolved component from rest
if (rest.length == 1) {
// No more remaining
rest = null;
} else {
NameComponent[] tmp = new NameComponent[rest.length - 1];
System.arraycopy(rest, 1, tmp, 0, tmp.length);
rest = tmp;
}
} else {
len = inputName.length - rest.length;
}
if (len > 0) {
resolvedName = new NameComponent[len];
System.arraycopy(inputName, 0, resolvedName, 0, len);
}
}
// Create CPE and set common fields
CannotProceedException cpe = new CannotProceedException();
cpe.setRootCause(e);
if (rest != null && rest.length > 0) {
cpe.setRemainingName(org.wildfly.iiop.openjdk.naming.jndi.CNNameParser.cosNameToName(rest));
}
cpe.setEnvironment(ctx._env);
// Lookup resolved name to get resolved object
final java.lang.Object resolvedObj = (resolvedName != null) ? ctx.callResolve(resolvedName) : ctx;
if (resolvedObj instanceof javax.naming.Context) {
// obj is a context and child is not found
// try getting its nns dynamically by constructing
// a Reference containing obj.
RefAddr addr = new RefAddr("nns") {
public java.lang.Object getContent() {
return resolvedObj;
}
private static final long serialVersionUID = 669984699392133792L;
};
Reference ref = new Reference("java.lang.Object", addr);
// Resolved name has trailing slash to indicate nns
CompositeName cname = new CompositeName();
// add trailing slash
cname.add("");
cpe.setResolvedObj(ref);
cpe.setAltName(cname);
cpe.setAltNameCtx((javax.naming.Context) resolvedObj);
return cpe;
} else {
// Not a context, use object factory to transform object.
Name cname = org.wildfly.iiop.openjdk.naming.jndi.CNNameParser.cosNameToName(resolvedName);
java.lang.Object resolvedObj2;
try {
resolvedObj2 = NamingManager.getObjectInstance(resolvedObj, cname, ctx, ctx._env);
} catch (NamingException ge) {
throw ge;
} catch (Exception ge) {
NamingException ne = IIOPLogger.ROOT_LOGGER.errorGeneratingObjectViaFactory();
ne.setRootCause(ge);
throw ne;
}
// If a context, continue operation with context
if (resolvedObj2 instanceof javax.naming.Context) {
cpe.setResolvedObj(resolvedObj2);
} else {
// Add trailing slash
cname.add("");
cpe.setAltName(cname);
// Create nns reference
final java.lang.Object rf2 = resolvedObj2;
RefAddr addr = new RefAddr("nns") {
public java.lang.Object getContent() {
return rf2;
}
private static final long serialVersionUID = -785132553978269772L;
};
Reference ref = new Reference("java.lang.Object", addr);
cpe.setResolvedObj(ref);
cpe.setAltNameCtx(ctx);
}
return cpe;
}
}
use of javax.naming.CompositeName in project wildfly by wildfly.
the class NamingContext method composeName.
/** {@inheritDoc} */
public Name composeName(Name name, Name prefix) throws NamingException {
final Name result = (Name) prefix.clone();
if (name instanceof CompositeName) {
if (name.size() == 1) {
// name could be a nested name
final String firstComponent = name.get(0);
result.addAll(parseName(firstComponent));
} else {
result.addAll(name);
}
} else {
result.addAll(new CompositeName(name.toString()));
}
return result;
}
Aggregations