javax.naming.NameNotFoundException Java Examples
The following examples show how to use
javax.naming.NameNotFoundException.
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: InVMNamingContext.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Override public Object lookup(String name) throws NamingException { name = trimSlashes(name); int i = name.indexOf("/"); String tok = i == -1 ? name : name.substring(0, i); Object value = map.get(tok); if (value == null) { throw new NameNotFoundException("Name not found: " + tok); } if (value instanceof InVMNamingContext && i != -1) { return ((InVMNamingContext) value).lookup(name.substring(i)); } if (value instanceof Reference) { Reference ref = (Reference) value; RefAddr refAddr = ref.get("nns"); // we only deal with references create by NonSerializableFactory String key = (String) refAddr.getContent(); return NonSerializableFactory.lookup(key); } else { return value; } }
Example #2
Source File: InVMContext.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Override public void unbind(String name) throws NamingException { name = trimSlashes(name); int i = name.indexOf("/"); boolean terminal = i == -1; if (terminal) { map.remove(name); } else { String tok = name.substring(0, i); InVMContext c = (InVMContext) map.get(tok); if (c == null) { throw new NameNotFoundException("Context not found: " + tok); } c.unbind(name.substring(i)); } }
Example #3
Source File: LDAPConnection.java From pentaho-kettle with Apache License 2.0 | 6 votes |
public int add( String dn, String[] attributes, String[] values, String multValuedSeparator, boolean checkEntry ) throws KettleException { try { Attributes attrs = buildAttributes( dn, attributes, values, multValuedSeparator ); // We had all attributes getInitialContext().modifyAttributes( dn, DirContext.ADD_ATTRIBUTE, attrs ); return STATUS_ADDED; } catch ( NameNotFoundException n ) { // The entry is not found if ( checkEntry ) { throw new KettleException( BaseMessages.getString( PKG, "LDAPConnection.Error.Deleting.NameNotFound", dn ), n ); } return STATUS_SKIPPED; } catch ( Exception e ) { throw new KettleException( BaseMessages.getString( PKG, "LDAPConnection.Error.Add", dn ), e ); } }
Example #4
Source File: SimpleNamingContext.java From spring-analysis-note with MIT License | 6 votes |
/** * Look up the object with the given name. * <p>Note: Not intended for direct use by applications. * Will be used by any standard InitialContext JNDI lookups. * @throws javax.naming.NameNotFoundException if the object could not be found */ @Override public Object lookup(String lookupName) throws NameNotFoundException { String name = this.root + lookupName; if (logger.isDebugEnabled()) { logger.debug("Static JNDI lookup: [" + name + "]"); } if ("".equals(name)) { return new SimpleNamingContext(this.root, this.boundObjects, this.environment); } Object found = this.boundObjects.get(name); if (found == null) { if (!name.endsWith("/")) { name = name + "/"; } for (String boundName : this.boundObjects.keySet()) { if (boundName.startsWith(name)) { return new SimpleNamingContext(name, this.boundObjects, this.environment); } } throw new NameNotFoundException( "Name [" + this.root + lookupName + "] not bound; " + this.boundObjects.size() + " bindings: [" + StringUtils.collectionToDelimitedString(this.boundObjects.keySet(), ",") + "]"); } return found; }
Example #5
Source File: JndiTemplateTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testLookupFails() throws Exception { NameNotFoundException ne = new NameNotFoundException(); String name = "foo"; final Context context = mock(Context.class); given(context.lookup(name)).willThrow(ne); JndiTemplate jt = new JndiTemplate() { @Override protected Context createInitialContext() { return context; } }; try { jt.lookup(name); fail("Should have thrown NamingException"); } catch (NameNotFoundException ex) { // Ok } verify(context).close(); }
Example #6
Source File: LdapConnection.java From hop with Apache License 2.0 | 6 votes |
public int delete( String dn, boolean checkEntry ) throws HopException { try { if ( checkEntry ) { // First Check entry getInitialContext().lookup( dn ); } // The entry exists getInitialContext().destroySubcontext( dn ); if ( log.isDebug() ) { log.logDebug( BaseMessages.getString( PKG, "LDAPinput.Exception.Deleted", dn ) ); } return STATUS_DELETED; } catch ( NameNotFoundException n ) { // The entry is not found if ( checkEntry ) { throw new HopException( BaseMessages.getString( PKG, "LdapConnection.Error.Deleting.NameNotFound", dn ), n ); } return STATUS_SKIPPED; } catch ( Exception e ) { throw new HopException( BaseMessages.getString( PKG, "LdapConnection.Error.Delete", dn ), e ); } }
Example #7
Source File: JndiTemplateTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testLookupFails() throws Exception { NameNotFoundException ne = new NameNotFoundException(); String name = "foo"; final Context context = mock(Context.class); given(context.lookup(name)).willThrow(ne); JndiTemplate jt = new JndiTemplate() { @Override protected Context createInitialContext() { return context; } }; try { jt.lookup(name); fail("Should have thrown NamingException"); } catch (NameNotFoundException ex) { // Ok } verify(context).close(); }
Example #8
Source File: SimpleNamingContext.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Look up the object with the given name. * <p>Note: Not intended for direct use by applications. * Will be used by any standard InitialContext JNDI lookups. * @throws javax.naming.NameNotFoundException if the object could not be found */ @Override public Object lookup(String lookupName) throws NameNotFoundException { String name = this.root + lookupName; if (logger.isDebugEnabled()) { logger.debug("Static JNDI lookup: [" + name + "]"); } if ("".equals(name)) { return new SimpleNamingContext(this.root, this.boundObjects, this.environment); } Object found = this.boundObjects.get(name); if (found == null) { if (!name.endsWith("/")) { name = name + "/"; } for (String boundName : this.boundObjects.keySet()) { if (boundName.startsWith(name)) { return new SimpleNamingContext(name, this.boundObjects, this.environment); } } throw new NameNotFoundException( "Name [" + this.root + lookupName + "] not bound; " + this.boundObjects.size() + " bindings: [" + StringUtils.collectionToDelimitedString(this.boundObjects.keySet(), ",") + "]"); } return found; }
Example #9
Source File: InVMNamingContext.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Override public void unbind(String name) throws NamingException { name = trimSlashes(name); int i = name.indexOf("/"); boolean terminal = i == -1; if (terminal) { map.remove(name); } else { String tok = name.substring(0, i); InVMNamingContext c = (InVMNamingContext) map.get(tok); if (c == null) { throw new NameNotFoundException("Context not found: " + tok); } c.unbind(name.substring(i)); } }
Example #10
Source File: TestDNS.java From hadoop with Apache License 2.0 | 6 votes |
/** * TestCase: get our local address and reverse look it up */ @Test public void testRDNS() throws Exception { InetAddress localhost = getLocalIPAddr(); try { String s = DNS.reverseDns(localhost, null); LOG.info("Local revers DNS hostname is " + s); } catch (NameNotFoundException e) { if (!localhost.isLinkLocalAddress() || localhost.isLoopbackAddress()) { //these addresses probably won't work with rDNS anyway, unless someone //has unusual entries in their DNS server mapping 1.0.0.127 to localhost LOG.info("Reverse DNS failing as due to incomplete networking", e); LOG.info("Address is " + localhost + " Loopback=" + localhost.isLoopbackAddress() + " Linklocal=" + localhost.isLinkLocalAddress()); } } }
Example #11
Source File: JndiTemplateTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testLookupFails() throws Exception { NameNotFoundException ne = new NameNotFoundException(); String name = "foo"; final Context context = mock(Context.class); given(context.lookup(name)).willThrow(ne); JndiTemplate jt = new JndiTemplate() { @Override protected Context createInitialContext() { return context; } }; try { jt.lookup(name); fail("Should have thrown NamingException"); } catch (NameNotFoundException ex) { // Ok } verify(context).close(); }
Example #12
Source File: NamingContext.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * Enumerates the names bound in the named context, along with the class * names of objects bound to them. The contents of any subcontexts are * not included. * <p> * If a binding is added to or removed from this context, its effect on * an enumeration previously returned is undefined. * * @param name the name of the context to list * @return an enumeration of the names and class names of the bindings in * this context. Each element of the enumeration is of type NameClassPair. * @exception NamingException if a naming exception is encountered */ @Override public NamingEnumeration<NameClassPair> list(Name name) throws NamingException { // Removing empty parts while ((!name.isEmpty()) && (name.get(0).length() == 0)) name = name.getSuffix(1); if (name.isEmpty()) { return new NamingContextEnumeration(bindings.values().iterator()); } NamingEntry entry = bindings.get(name.get(0)); if (entry == null) { throw new NameNotFoundException (sm.getString("namingContext.nameNotBound", name, name.get(0))); } if (entry.type != NamingEntry.CONTEXT) { throw new NamingException (sm.getString("namingContext.contextExpected")); } return ((Context) entry.value).list(name.getSuffix(1)); }
Example #13
Source File: SimpleNamingContext.java From java-technology-stack with MIT License | 6 votes |
/** * Look up the object with the given name. * <p>Note: Not intended for direct use by applications. * Will be used by any standard InitialContext JNDI lookups. * @throws javax.naming.NameNotFoundException if the object could not be found */ @Override public Object lookup(String lookupName) throws NameNotFoundException { String name = this.root + lookupName; if (logger.isDebugEnabled()) { logger.debug("Static JNDI lookup: [" + name + "]"); } if ("".equals(name)) { return new SimpleNamingContext(this.root, this.boundObjects, this.environment); } Object found = this.boundObjects.get(name); if (found == null) { if (!name.endsWith("/")) { name = name + "/"; } for (String boundName : this.boundObjects.keySet()) { if (boundName.startsWith(name)) { return new SimpleNamingContext(name, this.boundObjects, this.environment); } } throw new NameNotFoundException( "Name [" + this.root + lookupName + "] not bound; " + this.boundObjects.size() + " bindings: [" + StringUtils.collectionToDelimitedString(this.boundObjects.keySet(), ",") + "]"); } return found; }
Example #14
Source File: NamingContext.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * Enumerates the names bound in the named context, along with the * objects bound to them. The contents of any subcontexts are not * included. * <p> * If a binding is added to or removed from this context, its effect on * an enumeration previously returned is undefined. * * @param name the name of the context to list * @return an enumeration of the bindings in this context. * Each element of the enumeration is of type Binding. * @exception NamingException if a naming exception is encountered */ @Override public NamingEnumeration<Binding> listBindings(Name name) throws NamingException { // Removing empty parts while ((!name.isEmpty()) && (name.get(0).length() == 0)) name = name.getSuffix(1); if (name.isEmpty()) { return new NamingContextBindingsEnumeration(bindings.values().iterator(), this); } NamingEntry entry = bindings.get(name.get(0)); if (entry == null) { throw new NameNotFoundException (sm.getString("namingContext.nameNotBound", name, name.get(0))); } if (entry.type != NamingEntry.CONTEXT) { throw new NamingException (sm.getString("namingContext.contextExpected")); } return ((Context) entry.value).listBindings(name.getSuffix(1)); }
Example #15
Source File: InVMContext.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Override public Object lookup(String name) throws NamingException { name = trimSlashes(name); int i = name.indexOf("/"); String tok = i == -1 ? name : name.substring(0, i); Object value = map.get(tok); if (value == null) { throw new NameNotFoundException("Name not found: " + tok); } if (value instanceof InVMContext && i != -1) { return ((InVMContext) value).lookup(name.substring(i)); } if (value instanceof Reference) { Reference ref = (Reference) value; RefAddr refAddr = ref.get("nns"); // we only deal with references create by NonSerializableFactory String key = (String) refAddr.getContent(); return NonSerializableFactory.lookup(key); } else { return value; } }
Example #16
Source File: FileDirContext.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
/** * Binds a new name to the object bound to an old name, and unbinds the * old name. Both names are relative to this context. Any attributes * associated with the old name become associated with the new name. * Intermediate contexts of the old name are not changed. * * @param oldName the name of the existing binding; may not be empty * @param newName the name of the new binding; may not be empty * @exception NameAlreadyBoundException if newName is already bound * @exception NamingException if a naming exception is encountered */ @Override public void rename(String oldName, String newName) throws NamingException { File file = file(oldName); if (file == null) throw new NameNotFoundException (sm.getString("resources.notFound", oldName)); File newFile = new File(base, newName); if (!file.renameTo(newFile)) { throw new NamingException(sm.getString("resources.renameFail", oldName, newName)); } }
Example #17
Source File: DirContextAdapter.java From spring-ldap with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public Attributes getAttributes(String name, String[] attrIds) throws NamingException { if (StringUtils.hasLength(name)) { throw new NameNotFoundException(); } Attributes a = new NameAwareAttributes(); Attribute target; for (String attrId : attrIds) { target = originalAttrs.get(attrId); if (target != null) { a.put(target); } } return a; }
Example #18
Source File: LookupFactory.java From tomee with Apache License 2.0 | 6 votes |
@Override public Object getObjectInstance(final Object object, final Name name, final Context context, final Hashtable environment) throws Exception { if (!(object instanceof Reference)) { return null; } final Reference reference = ((Reference) object); final String jndiName = NamingUtil.getProperty(reference, NamingUtil.JNDI_NAME); if (jndiName == null) { return null; } try { return context.lookup(jndiName.replaceFirst("^java:", "")); } catch (final NameNotFoundException e) { return new InitialContext().lookup(jndiName); } }
Example #19
Source File: ContextImpl.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * 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); // scenerio unbind a // 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)); } } }
Example #20
Source File: DefaultInitialContext.java From piranha with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Bind the object to the given name. * * @param name the name. * @param object the object. * @throws NamingException when an naming error occurs. */ @Override public void bind(String name, Object object) throws NamingException { checkClosed(); if (name.contains("/")) { String[] names = name.split("/"); DefaultInitialContext contextMap = this; for (int i = 0; i < names.length - 1; i++) { try { contextMap = (DefaultInitialContext) contextMap.lookup(names[i]); } catch (NameNotFoundException ne) { contextMap = (DefaultInitialContext) contextMap.createSubcontext(names[i]); } } contextMap.bind(names[names.length - 1], object); } else if (!bindings.containsKey(name)) { bindings.put(name, object); } else { throw new NameAlreadyBoundException("Name '" + name + "' already bound"); } }
Example #21
Source File: LDAPConnection.java From pentaho-kettle with Apache License 2.0 | 6 votes |
public int delete( String dn, boolean checkEntry ) throws KettleException { try { if ( checkEntry ) { // First Check entry getInitialContext().lookup( dn ); } // The entry exists getInitialContext().destroySubcontext( dn ); if ( log.isDebug() ) { log.logDebug( BaseMessages.getString( PKG, "LDAPinput.Exception.Deleted", dn ) ); } return STATUS_DELETED; } catch ( NameNotFoundException n ) { // The entry is not found if ( checkEntry ) { throw new KettleException( BaseMessages.getString( PKG, "LDAPConnection.Error.Deleting.NameNotFound", dn ), n ); } return STATUS_SKIPPED; } catch ( Exception e ) { throw new KettleException( BaseMessages.getString( PKG, "LDAPConnection.Error.Delete", dn ), e ); } }
Example #22
Source File: FileDirContext.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * Unbinds the named object. Removes the terminal atomic name in name * from the target context--that named by all but the terminal atomic * part of name. * <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. * * @param name the name to bind; may not be empty * @exception NameNotFoundException if an intermediate context does not * exist * @exception NamingException if a naming exception is encountered */ @Override public void unbind(String name) throws NamingException { File file = file(name); if (file == null) throw new NameNotFoundException( sm.getString("resources.notFound", name)); if (!file.delete()) throw new NamingException (sm.getString("resources.unbindFailed", name)); }
Example #23
Source File: NamingContext.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
/** * Enumerates the names bound in the named context, along with the class * names of objects bound to them. The contents of any subcontexts are * not included. * <p> * If a binding is added to or removed from this context, its effect on * an enumeration previously returned is undefined. * * @param name the name of the context to list * @return an enumeration of the names and class names of the bindings in * this context. Each element of the enumeration is of type NameClassPair. * @exception NamingException if a naming exception is encountered */ @Override public NamingEnumeration<NameClassPair> list(Name name) throws NamingException { // Removing empty parts while ((!name.isEmpty()) && (name.get(0).length() == 0)) name = name.getSuffix(1); if (name.isEmpty()) { return new NamingContextEnumeration(bindings.values().iterator()); } NamingEntry entry = bindings.get(name.get(0)); if (entry == null) { throw new NameNotFoundException (sm.getString("namingContext.nameNotBound", name, name.get(0))); } if (entry.type != NamingEntry.CONTEXT) { throw new NamingException (sm.getString("namingContext.contextExpected")); } return ((Context) entry.value).list(name.getSuffix(1)); }
Example #24
Source File: SimpleNamingContext.java From java-technology-stack with MIT License | 6 votes |
/** * Look up the object with the given name. * <p>Note: Not intended for direct use by applications. * Will be used by any standard InitialContext JNDI lookups. * @throws javax.naming.NameNotFoundException if the object could not be found */ @Override public Object lookup(String lookupName) throws NameNotFoundException { String name = this.root + lookupName; if (logger.isDebugEnabled()) { logger.debug("Static JNDI lookup: [" + name + "]"); } if ("".equals(name)) { return new SimpleNamingContext(this.root, this.boundObjects, this.environment); } Object found = this.boundObjects.get(name); if (found == null) { if (!name.endsWith("/")) { name = name + "/"; } for (String boundName : this.boundObjects.keySet()) { if (boundName.startsWith(name)) { return new SimpleNamingContext(name, this.boundObjects, this.environment); } } throw new NameNotFoundException( "Name [" + this.root + lookupName + "] not bound; " + this.boundObjects.size() + " bindings: [" + StringUtils.collectionToDelimitedString(this.boundObjects.keySet(), ",") + "]"); } return found; }
Example #25
Source File: ContextImpl.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * 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); // scenerio unbind a // 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)); } } }
Example #26
Source File: ldapEntry.java From openbd-core with GNU General Public License v3.0 | 5 votes |
public Attributes getAttributes(String _name, String[] _ids) throws NamingException { if (!_name.equals("")) { throw new NameNotFoundException(); } Attributes answer = new BasicAttributes(true); Attribute target; for (int i = 0; i < _ids.length; i++) { target = attributes.get(_ids[i]); if (target != null) { answer.put(target); } } return answer; }
Example #27
Source File: LdapOrganizationalUnitDao.java From projectforge-webapp with GNU General Public License v3.0 | 5 votes |
public boolean doesExist(final String ou, final String... organizationalUnits) { return (Boolean) new LdapTemplate(ldapConnector) { @Override protected Object call() throws NameNotFoundException, Exception { return doesExist(ctx, ou, organizationalUnits); } }.excecute(); }
Example #28
Source File: DefaultInitialContextTest.java From piranha with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Test unbind method. * * @throws Exception when an error occurs. */ @Test public void testUnbind5() throws Exception { DefaultInitialContext context = new DefaultInitialContext(); context.bind("composite/name", "test"); assertThrows(NameNotFoundException.class, () -> context.unbind("composite2/name")); }
Example #29
Source File: NamingContext.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * 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")); } } }
Example #30
Source File: DefaultInitialContextTest.java From piranha with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Test unbind method. * * @throws Exception when an error occurs. */ @Test public void testUnbind4() throws Exception { DefaultInitialContext context = new DefaultInitialContext(); context.bind("composite/name", "test"); context.unbind("composite/name"); assertThrows(NameNotFoundException.class, () -> context.lookup("composite/name")); }