/** * Destroys subcontext with name name. The subcontext must be empty otherwise * ContextNotEmptyException is thrown. Once a context is destroyed, the * instance should not be used. * * @param name subcontext to destroy * @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 ContextNotEmptyException if Context name is not empty. * @throws NameNotFoundException if subcontext with name name can not be * found. * @throws NotContextException if name is not bound to instance of * ContextImpl. * */ public void destroySubcontext(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(subContextName); if (boundObject == null) { throw new NameNotFoundException(LocalizedStrings.ContextImpl_NAME_0_NOT_FOUND_IN_THE_CONTEXT.toLocalizedString(subContextName)); } if (!(boundObject instanceof ContextImpl)) { throw new NotContextException(); } ContextImpl contextToDestroy = (ContextImpl) boundObject; if (parsedName.size() == 1) { // Check if the Context to be destroyed is empty. Can not destroy // non-empty Context. if (contextToDestroy.ctxMaps.size() == 0) { ctxMaps.remove(subContextName); contextToDestroy.destroyInternal(); } else { throw new ContextNotEmptyException(LocalizedStrings.ContextImpl_CAN_NOT_DESTROY_NONEMPTY_CONTEXT.toLocalizedString()); } } else { // Let the subcontext destroy the context ((ContextImpl) boundObject).destroySubcontext(parsedName.getSuffix(1)); } }
/** * Destroys subcontext with name name. The subcontext must be empty otherwise * ContextNotEmptyException is thrown. Once a context is destroyed, the instance should not be * used. * * @param name subcontext to destroy * @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 ContextNotEmptyException if Context name is not empty. * @throws NameNotFoundException if subcontext with name name can not be found. * @throws NotContextException if name is not bound to instance of ContextImpl. * */ public void destroySubcontext(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(subContextName); if (boundObject == null) { throw new NameNotFoundException(LocalizedStrings.ContextImpl_NAME_0_NOT_FOUND_IN_THE_CONTEXT .toLocalizedString(subContextName)); } if (!(boundObject instanceof ContextImpl)) { throw new NotContextException(); } ContextImpl contextToDestroy = (ContextImpl) boundObject; if (parsedName.size() == 1) { // Check if the Context to be destroyed is empty. Can not destroy // non-empty Context. if (contextToDestroy.ctxMaps.size() == 0) { ctxMaps.remove(subContextName); contextToDestroy.destroyInternal(); } else { throw new ContextNotEmptyException( LocalizedStrings.ContextImpl_CAN_NOT_DESTROY_NONEMPTY_CONTEXT.toLocalizedString()); } } else { // Let the subcontext destroy the context ((ContextImpl) boundObject).destroySubcontext(parsedName.getSuffix(1)); } }