use of javax.naming.NotContextException in project geode by apache.
the class ContextImpl method unbind.
/**
* Removes name and its associated object from the context.
*
* @param name name to remove
* @throws NoPermissionException if this context has been destroyed.
* @throws InvalidNameException if name is empty or is CompositeName that spans more than one
* naming system
* @throws NameNotFoundException if intermediate context can not be found
* @throws NotContextException if name has more than one atomic name and intermediate context is
* not found.
* @throws NamingException if any other naming exception occurs
*
*/
public void unbind(Name name) throws NamingException {
checkIsDestroyed();
Name parsedName = getParsedName(name);
if (parsedName.size() == 0 || parsedName.get(0).length() == 0) {
throw new InvalidNameException(LocalizedStrings.ContextImpl_NAME_CAN_NOT_BE_EMPTY.toLocalizedString());
}
String nameToRemove = parsedName.get(0);
// remove a and its associated object
if (parsedName.size() == 1) {
ctxMaps.remove(nameToRemove);
} else {
// scenerio unbind a/b or a/b/c
// remove b and its associated object
Object boundObject = ctxMaps.get(nameToRemove);
if (boundObject instanceof Context) {
// remove b and its associated object
((Context) boundObject).unbind(parsedName.getSuffix(1));
} else {
// if the name is not found then throw exception
if (!ctxMaps.containsKey(nameToRemove)) {
throw new NameNotFoundException(LocalizedStrings.ContextImpl_CAN_NOT_FIND_0.toLocalizedString(name));
}
throw new NotContextException(LocalizedStrings.ContextImpl_EXPECTED_CONTEXT_BUT_FOUND_0.toLocalizedString(boundObject));
}
}
}
use of javax.naming.NotContextException in project geode by apache.
the class ContextImpl method rebind.
/**
* Rebinds object obj to name name . If there is existing binding it will be overwritten.
*
* @param name name of the object to rebind.
* @param obj object to add. Can be null.
* @throws NoPermissionException if this context has been destroyed
* @throws InvalidNameException if name is empty or is CompositeName that spans more than one
* naming system
* @throws NotContextException if name has more than one atomic name and intermediate context is
* not found
* @throws NamingException if any other naming error occurs
*
*/
public void rebind(Name name, Object obj) throws NamingException {
checkIsDestroyed();
Name parsedName = getParsedName(name);
if (parsedName.size() == 0 || parsedName.get(0).length() == 0) {
throw new InvalidNameException(LocalizedStrings.ContextImpl_NAME_CAN_NOT_BE_EMPTY.toLocalizedString());
}
String nameToBind = parsedName.get(0);
if (parsedName.size() == 1) {
ctxMaps.put(nameToBind, obj);
} else {
Object boundObject = ctxMaps.get(nameToBind);
if (boundObject instanceof Context) {
/*
* Let the subcontext bind the object.
*/
((Context) boundObject).bind(parsedName.getSuffix(1), obj);
} else {
if (boundObject == null) {
// Create new subcontext and let it do the binding
Context sub = createSubcontext(nameToBind);
sub.bind(parsedName.getSuffix(1), obj);
} else {
throw new NotContextException(LocalizedStrings.ContextImpl_EXPECTED_CONTEXT_BUT_FOUND_0.toLocalizedString(boundObject));
}
}
}
}
use of javax.naming.NotContextException in project geode by apache.
the class ContextImpl method createSubcontext.
/**
* Creates subcontext with name, relative to this Context.
*
* @param name subcontext name.
* @return new subcontext named name relative to this context.
* @throws NoPermissionException if this context has been destroyed.
* @throws InvalidNameException if name is empty or is CompositeName that spans more than one
* naming system.
* @throws NameAlreadyBoundException if name is already bound in this Context
* @throws NotContextException if any intermediate name from name is not bound to instance of
* javax.naming.Context.
*
*/
public Context createSubcontext(Name name) throws NamingException {
checkIsDestroyed();
Name parsedName = getParsedName(name);
if (parsedName.size() == 0 || parsedName.get(0).length() == 0) {
throw new InvalidNameException(LocalizedStrings.ContextImpl_NAME_CAN_NOT_BE_EMPTY.toLocalizedString());
}
String subContextName = parsedName.get(0);
Object boundObject = ctxMaps.get(parsedName.get(0));
if (parsedName.size() == 1) {
// Check if name is already in use
if (boundObject == null) {
Context subContext = new ContextImpl(this, subContextName);
ctxMaps.put(subContextName, subContext);
return subContext;
} else {
throw new NameAlreadyBoundException(LocalizedStrings.ContextImpl_NAME_0_IS_ALREADY_BOUND.toLocalizedString(subContextName));
}
} else {
if (boundObject instanceof Context) {
// an exception will be thrown in that case.
return ((Context) boundObject).createSubcontext(parsedName.getSuffix(1));
} else {
throw new NotContextException(LocalizedStrings.ContextImpl_EXPECTED_CONTEXT_BUT_FOUND_0.toLocalizedString(boundObject));
}
}
}
use of javax.naming.NotContextException in project wildfly by wildfly.
the class CNCtx method callBindOrRebind.
/**
* Performs bind or rebind in the context depending on whether the
* flag rebind is set. The only objects allowed to be bound are of
* types org.omg.CORBA.Object, org.omg.CosNaming.NamingContext.
* You can use a state factory to turn other objects (such as
* Remote) into these acceptable forms.
* <p/>
* Uses the COS Naming apis bind/rebind or
* bind_context/rebind_context.
*
* @param pth NameComponent[] object
* @param obj Object to be bound.
* @param rebind perform rebind ? if true performs a rebind.
* @throws NotFound No objects under the name.
* @throws org.omg.CosNaming.NamingContextPackage.CannotProceed Unable to obtain a continuation context
* @throws org.omg.CosNaming.NamingContextPackage.AlreadyBound An object is already bound to this name.
*/
private void callBindOrRebind(NameComponent[] pth, Name name, java.lang.Object obj, boolean rebind) throws NamingException {
if (_nc == null)
throw IIOPLogger.ROOT_LOGGER.notANamingContext(name.toString());
try {
// Call state factories to convert
obj = NamingManager.getStateToBind(obj, name, this, _env);
if (obj instanceof CNCtx) {
// Use naming context object reference
obj = ((CNCtx) obj)._nc;
}
if (obj instanceof org.omg.CosNaming.NamingContext) {
NamingContext nobj = NamingContextHelper.narrow((org.omg.CORBA.Object) obj);
if (rebind)
_nc.rebind_context(pth, nobj);
else
_nc.bind_context(pth, nobj);
} else if (obj instanceof org.omg.CORBA.Object) {
if (rebind)
_nc.rebind(pth, (org.omg.CORBA.Object) obj);
else
_nc.bind(pth, (org.omg.CORBA.Object) obj);
} else
throw IIOPLogger.ROOT_LOGGER.notACorbaObject();
} catch (BAD_PARAM e) {
// probably narrow() failed?
NamingException ne = new NotContextException(name.toString());
ne.setRootCause(e);
throw ne;
} catch (Exception e) {
throw org.wildfly.iiop.openjdk.naming.jndi.ExceptionMapper.mapException(e, this, pth);
}
}
use of javax.naming.NotContextException in project tomcat by apache.
the class NamingContext method destroySubcontext.
/**
* Destroys the named context and removes it from the namespace. Any
* attributes associated with the name are also removed. Intermediate
* contexts are not destroyed.
* <p>
* This method is idempotent. It succeeds even if the terminal atomic
* name is not bound in the target context, but throws
* NameNotFoundException if any of the intermediate contexts do not exist.
*
* In a federated naming system, a context from one naming system may be
* bound to a name in another. One can subsequently look up and perform
* operations on the foreign context using a composite name. However, an
* attempt destroy the context using this composite name will fail with
* NotContextException, because the foreign context is not a "subcontext"
* of the context in which it is bound. Instead, use unbind() to remove
* the binding of the foreign context. Destroying the foreign context
* requires that the destroySubcontext() be performed on a context from
* the foreign context's "native" naming system.
*
* @param name the name of the context to be destroyed; may not be empty
* @exception NameNotFoundException if an intermediate context does not
* exist
* @exception NotContextException if the name is bound but does not name
* a context, or does not name a context of the appropriate type
*/
@Override
public void destroySubcontext(Name name) throws NamingException {
if (!checkWritable()) {
return;
}
while ((!name.isEmpty()) && (name.get(0).length() == 0)) name = name.getSuffix(1);
if (name.isEmpty())
throw new NamingException(sm.getString("namingContext.invalidName"));
NamingEntry entry = bindings.get(name.get(0));
if (entry == null) {
throw new NameNotFoundException(sm.getString("namingContext.nameNotBound", name, name.get(0)));
}
if (name.size() > 1) {
if (entry.type == NamingEntry.CONTEXT) {
((Context) entry.value).destroySubcontext(name.getSuffix(1));
} else {
throw new NamingException(sm.getString("namingContext.contextExpected"));
}
} else {
if (entry.type == NamingEntry.CONTEXT) {
((Context) entry.value).close();
bindings.remove(name.get(0));
} else {
throw new NotContextException(sm.getString("namingContext.contextExpected"));
}
}
}
Aggregations