javax.naming.ContextNotEmptyException Java Examples
The following examples show how to use
javax.naming.ContextNotEmptyException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ContextImpl.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * 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)); } }
Example #2
Source File: ContextImpl.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * 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)); } }
Example #3
Source File: DefaultInitialContext.java From piranha with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Destroy the sub context. * * @param name the name. * @throws NamingException when a naming error occurs. */ @Override public void destroySubcontext(String name) throws NamingException { if (name.contains("/")) { String[] names = name.split("/"); DefaultInitialContext contextMap = this; try { for (int i = 0; i < names.length - 1; i++) { contextMap = (DefaultInitialContext) contextMap.lookup(names[i]); } contextMap.destroySubcontext(names[names.length - 1]); } catch (NameNotFoundException nnfe) { throw nnfe; } } else if (bindings.containsKey(name)) { if (bindings.get(name) instanceof DefaultInitialContext) { DefaultInitialContext subContext = (DefaultInitialContext) bindings.get(name); if (subContext.bindings.isEmpty()) { bindings.remove(name); } else { throw new ContextNotEmptyException("Context not empty: " + name); } } else { throw new NotContextException("Not a context: " + name); } } else { throw new NameNotFoundException("Unable to find name: " + name); } }
Example #4
Source File: DefaultInitialContextTest.java From piranha with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Test destroySubcontext method. * * @throws Exception when an error occurs. */ @Test public void testDestroySubcontext2() throws Exception { DefaultInitialContext context = new DefaultInitialContext(); context.createSubcontext(new CompositeName("context")); context.bind("context/name", 12); assertThrows(ContextNotEmptyException.class, () -> context.destroySubcontext("context")); }