use of javax.naming.Name in project wildfly by wildfly.
the class InMemoryNamingStoreTestCase method testBindAndLookupResolveResult.
@Test
public void testBindAndLookupResolveResult() throws Exception {
final Name name = new CompositeName("test");
final Reference reference = new Reference(Context.class.getName());
nameStore.bind(name, reference, Context.class);
final Object result = nameStore.lookup(new CompositeName("test/value"));
assertTrue(result instanceof ResolveResult);
}
use of javax.naming.Name in project wildfly by wildfly.
the class NamingContext method bind.
/** {@inheritDoc} */
public void bind(final Name name, final Object object) throws NamingException {
check(name, JndiPermission.ACTION_BIND);
if (namingStore instanceof WritableNamingStore) {
final Name absoluteName = getAbsoluteName(name);
final Object value;
if (object instanceof Referenceable) {
value = ((Referenceable) object).getReference();
} else {
value = object;
}
if (System.getSecurityManager() == null) {
getWritableNamingStore().bind(absoluteName, value);
} else {
// The permissions check has already happened for the binding further permissions should be allowed
final NamingException e = AccessController.doPrivileged(new PrivilegedAction<NamingException>() {
@Override
public NamingException run() {
try {
getWritableNamingStore().bind(absoluteName, value);
} catch (NamingException e) {
return e;
}
return null;
}
});
// Check that a NamingException wasn't thrown during the bind
if (e != null) {
throw e;
}
}
} else {
throw NamingLogger.ROOT_LOGGER.readOnlyNamingContext();
}
}
use of javax.naming.Name in project wildfly by wildfly.
the class NamingEventCoordinator method fireEvent.
/**
* Fire a naming event. An event will be created with the provided information and sent to each listener that matches
* the target and scope information.
*
* @param context The event context generating the event.
* @param name The target name the event represents
* @param existingBinding The existing binding at the provided name
* @param newBinding The new binding at the provided name
* @param type The event type
* @param changeInfo The change info for the event
* @param scopes The scopes this event should be fired against
*/
void fireEvent(final EventContext context, final Name name, final Binding existingBinding, final Binding newBinding, int type, final String changeInfo, final Integer... scopes) {
final String target = name.toString();
final Set<Integer> scopeSet = new HashSet<Integer>(Arrays.asList(scopes));
final NamingEvent event = new NamingEvent(context, type, newBinding, existingBinding, changeInfo);
final Set<ListenerHolder> holdersToFire = new HashSet<ListenerHolder>();
// Check for OBJECT_SCOPE based listeners
if (scopeSet.contains(EventContext.OBJECT_SCOPE)) {
final TargetScope targetScope = new TargetScope(target, EventContext.OBJECT_SCOPE);
final List<ListenerHolder> holders = holdersByTarget.get(targetScope);
if (holders != null) {
for (ListenerHolder holder : holders) {
holdersToFire.add(holder);
}
}
}
// Check for ONELEVEL_SCOPE based listeners
if (scopeSet.contains(EventContext.ONELEVEL_SCOPE) && !name.isEmpty()) {
final TargetScope targetScope = new TargetScope(name.getPrefix(name.size() - 1).toString(), EventContext.ONELEVEL_SCOPE);
final List<ListenerHolder> holders = holdersByTarget.get(targetScope);
if (holders != null) {
for (ListenerHolder holder : holders) {
holdersToFire.add(holder);
}
}
}
// Check for SUBTREE_SCOPE based listeners
if (scopeSet.contains(EventContext.SUBTREE_SCOPE) && !name.isEmpty()) {
for (int i = 1; i < name.size(); i++) {
final Name parentName = name.getPrefix(i);
final TargetScope targetScope = new TargetScope(parentName.toString(), EventContext.SUBTREE_SCOPE);
final List<ListenerHolder> holders = holdersByTarget.get(targetScope);
if (holders != null) {
for (ListenerHolder holder : holders) {
holdersToFire.add(holder);
}
}
}
}
executor.execute(new FireEventTask(holdersToFire, event));
}
use of javax.naming.Name in project wildfly by wildfly.
the class NamingContext method unbind.
/** {@inheritDoc} */
public void unbind(final Name name) throws NamingException {
check(name, JndiPermission.ACTION_UNBIND);
if (namingStore instanceof WritableNamingStore) {
final Name absoluteName = getAbsoluteName(name);
getWritableNamingStore().unbind(absoluteName);
} else {
throw NamingLogger.ROOT_LOGGER.readOnlyNamingContext();
}
}
use of javax.naming.Name in project wildfly by wildfly.
the class CNBindingEnumeration method mapBinding.
/**
* Constructs a JNDI Binding object from the COS Naming binding
* object.
*
* @throws org.omg.CosNaming.NamingContextPackage.CannotProceed Unable to obtain a continuation context
* @throws org.omg.CosNaming.NamingContextPackage.InvalidNameCNCtx Name not understood.
* @throws NamingException One of the above.
*/
private javax.naming.Binding mapBinding(org.omg.CosNaming.Binding bndg) throws NamingException {
java.lang.Object obj = _ctx.callResolve(bndg.binding_name);
Name cname = org.wildfly.iiop.openjdk.naming.jndi.CNNameParser.cosNameToName(bndg.binding_name);
try {
obj = NamingManager.getObjectInstance(obj, cname, _ctx, _env);
} catch (NamingException e) {
throw e;
} catch (Exception e) {
NamingException ne = IIOPLogger.ROOT_LOGGER.errorGeneratingObjectViaFactory();
ne.setRootCause(e);
throw ne;
}
// Use cname.toString() instead of bindingName because the name
// in the binding should be a composite name
String cnameStr = cname.toString();
javax.naming.Binding jbndg = new javax.naming.Binding(cnameStr, obj);
NameComponent[] comps = _ctx.makeFullName(bndg.binding_name);
String fullName = org.wildfly.iiop.openjdk.naming.jndi.CNNameParser.cosNameToInsString(comps);
jbndg.setNameInNamespace(fullName);
return jbndg;
}
Aggregations