@Test public void testLookup() throws Exception { try (CloseableNamingContext context = closeableContext()) { context.bind("hello", new Object()); assertNotNull(context.lookup("")); assertNotNull(context.lookupLink("hello")); try { assertNotNull(context.lookup("adapter:/comp/env/object")); } catch (NameNotFoundException expected) { } try { context.lookup("zzzz:/comp/env/object"); } catch (NamingException expected) { } } }
@Override public Object lookup(Name lookupName) throws NamingException { log.debug("NamingContext lookup (" + lookupName.toString() + ")"); Name name = this.stripEmptyPrefix(lookupName); if (name.size() == 0) { return this; } Object result = bindings.get(name.get(0)); if (result == null) { int pos = name.get(0).indexOf(':'); if (pos > 0) { String scheme = name.get(0).substring(0, pos); Context ctx = NamingManager.getURLContext(scheme, environment); if (ctx == null) { throw new NamingException("scheme " + scheme + " not recognized"); } return ctx.lookup(new CompositeName(name.get(0).substring(pos + 1) + "/" + name.getSuffix(1).toString())); } else { if (name.size() == 0) { return this; } else { String first = name.get(0); Object obj = bindings.get(first); if (obj == null) { throw new NameNotFoundException("Name not found exception: " + name.toString()); } else if (obj instanceof Context && name.size() > 1) { Context subContext = (Context) obj; obj = subContext.lookup(name.getSuffix(1)); } return obj; } } } result = ((NamingEntry) result).getObject(); if (result instanceof LinkRef) { LinkRef ref = (LinkRef) result; result = lookup(ref.getLinkName()); } if (result instanceof Reference) { try { result = NamingManager.getObjectInstance(result, null, null, this.environment); } catch (NamingException e) { throw e; } catch (Exception e) { throw (NamingException) new NamingException("could not look up : " + name).initCause(e); } } if (result instanceof NamingContext && name.size() > 1) { return ((NamingContext) result).lookup(name.getSuffix(1)); } return result; }
NamingContext implements Context, Serializable { @Override public Object lookup(Name lookupName) throws NamingException { log.debug("NamingContext lookup (" + lookupName.toString() + ")"); Name name = this.stripEmptyPrefix(lookupName); if (name.size() == 0) { return this; } Object result = bindings.get(name.get(0)); if (result == null) { int pos = name.get(0).indexOf(':'); if (pos > 0) { String scheme = name.get(0).substring(0, pos); Context ctx = NamingManager.getURLContext(scheme, environment); if (ctx == null) { throw new NamingException("scheme " + scheme + " not recognized"); } return ctx.lookup(new CompositeName(name.get(0).substring(pos + 1) + "/" + name.getSuffix(1).toString())); } else { if (name.size() == 0) { return this; } else { String first = name.get(0); Object obj = bindings.get(first); if (obj == null) { throw new NameNotFoundException("Name not found exception: " + name.toString()); } else if (obj instanceof Context && name.size() > 1) { Context subContext = (Context) obj; obj = subContext.lookup(name.getSuffix(1)); } return obj; } } } result = ((NamingEntry) result).getObject(); if (result instanceof LinkRef) { LinkRef ref = (LinkRef) result; result = lookup(ref.getLinkName()); } if (result instanceof Reference) { try { result = NamingManager.getObjectInstance(result, null, null, this.environment); } catch (NamingException e) { throw e; } catch (Exception e) { throw (NamingException) new NamingException("could not look up : " + name).initCause(e); } } if (result instanceof NamingContext && name.size() > 1) { return ((NamingContext) result).lookup(name.getSuffix(1)); } return result; } }
NamingContext implements Context, Serializable { @Override public Object lookup(Name lookupName) throws NamingException { log.debug("NamingContext lookup (" + lookupName.toString() + ")"); Name name = this.stripEmptyPrefix(lookupName); if (name.size() == 0) { return this; } Object result = bindings.get(name.get(0)); if (result == null) { int pos = name.get(0).indexOf(':'); if (pos > 0) { String scheme = name.get(0).substring(0, pos); Context ctx = NamingManager.getURLContext(scheme, environment); if (ctx == null) { throw new NamingException("scheme " + scheme + " not recognized"); } return ctx.lookup(new CompositeName(name.get(0).substring(pos + 1) + "/" + name.getSuffix(1).toString())); } else { if (name.size() == 0) { return this; } else { String first = name.get(0); Object obj = bindings.get(first); if (obj == null) { throw new NameNotFoundException("Name not found exception: " + name.toString()); } else if (obj instanceof Context && name.size() > 1) { Context subContext = (Context) obj; obj = subContext.lookup(name.getSuffix(1)); } return obj; } } } result = ((NamingEntry) result).getObject(); if (result instanceof LinkRef) { LinkRef ref = (LinkRef) result; result = lookup(ref.getLinkName()); } if (result instanceof Reference) { try { result = NamingManager.getObjectInstance(result, null, null, this.environment); } catch (NamingException e) { throw e; } catch (Exception e) { throw (NamingException) new NamingException("could not look up : " + name).initCause(e); } } if (result instanceof NamingContext && name.size() > 1) { return ((NamingContext) result).lookup(name.getSuffix(1)); } return result; } NamingContext();  NamingContext(Hashtable<String, Object> environment);  NamingContext(Hashtable<String, Object> environment, Map<String, Object> objects);  NamingContext(Hashtable<String, Object> environment, String nameInNamespace); }
NamingContext implements Context, Serializable { @Override public Object lookup(Name lookupName) throws NamingException { log.debug("NamingContext lookup (" + lookupName.toString() + ")"); Name name = this.stripEmptyPrefix(lookupName); if (name.size() == 0) { return this; } Object result = bindings.get(name.get(0)); if (result == null) { int pos = name.get(0).indexOf(':'); if (pos > 0) { String scheme = name.get(0).substring(0, pos); Context ctx = NamingManager.getURLContext(scheme, environment); if (ctx == null) { throw new NamingException("scheme " + scheme + " not recognized"); } return ctx.lookup(new CompositeName(name.get(0).substring(pos + 1) + "/" + name.getSuffix(1).toString())); } else { if (name.size() == 0) { return this; } else { String first = name.get(0); Object obj = bindings.get(first); if (obj == null) { throw new NameNotFoundException("Name not found exception: " + name.toString()); } else if (obj instanceof Context && name.size() > 1) { Context subContext = (Context) obj; obj = subContext.lookup(name.getSuffix(1)); } return obj; } } } result = ((NamingEntry) result).getObject(); if (result instanceof LinkRef) { LinkRef ref = (LinkRef) result; result = lookup(ref.getLinkName()); } if (result instanceof Reference) { try { result = NamingManager.getObjectInstance(result, null, null, this.environment); } catch (NamingException e) { throw e; } catch (Exception e) { throw (NamingException) new NamingException("could not look up : " + name).initCause(e); } } if (result instanceof NamingContext && name.size() > 1) { return ((NamingContext) result).lookup(name.getSuffix(1)); } return result; } NamingContext();  NamingContext(Hashtable<String, Object> environment);  NamingContext(Hashtable<String, Object> environment, Map<String, Object> objects);  NamingContext(Hashtable<String, Object> environment, String nameInNamespace); @Override void bind(Name name, Object object); void bind(Name bindName, Object object, boolean rebind); @Override Name composeName(Name name, Name prefix); @Override String composeName(String name, String prefix); @Override Context createSubcontext(Name name); @Override void destroySubcontext(Name contextToDestroy); @Override String getNameInNamespace(); @Override NameParser getNameParser(Name name); @Override NameParser getNameParser(String name); @Override NamingEnumeration list(Name name); @Override NamingEnumeration list(String name); @Override NamingEnumeration<Binding> listBindings(Name name); @Override NamingEnumeration<Binding> listBindings(String name); @Override Object lookup(Name lookupName); @Override Object lookupLink(Name name); @Override void rebind(Name name, Object object); @Override void rename(Name oldName, Name newName); @Override void unbind(Name toUnbind); @Override Object lookup(String name); @Override Object lookupLink(String name); @Override void unbind(String name); @Override void rebind(String name, Object object); @Override Object removeFromEnvironment(String propertyName); @Override Object addToEnvironment(String propertyName, Object propertyVal); @Override Hashtable<?, ?> getEnvironment(); @Override void bind(String name, Object object); @Override void close(); @Override Context createSubcontext(String name); @Override void destroySubcontext(String name); @Override void rename(String oldName, String newName); }
NamingContext implements Context, Serializable { @Override public Object lookup(Name lookupName) throws NamingException { log.debug("NamingContext lookup (" + lookupName.toString() + ")"); Name name = this.stripEmptyPrefix(lookupName); if (name.size() == 0) { return this; } Object result = bindings.get(name.get(0)); if (result == null) { int pos = name.get(0).indexOf(':'); if (pos > 0) { String scheme = name.get(0).substring(0, pos); Context ctx = NamingManager.getURLContext(scheme, environment); if (ctx == null) { throw new NamingException("scheme " + scheme + " not recognized"); } return ctx.lookup(new CompositeName(name.get(0).substring(pos + 1) + "/" + name.getSuffix(1).toString())); } else { if (name.size() == 0) { return this; } else { String first = name.get(0); Object obj = bindings.get(first); if (obj == null) { throw new NameNotFoundException("Name not found exception: " + name.toString()); } else if (obj instanceof Context && name.size() > 1) { Context subContext = (Context) obj; obj = subContext.lookup(name.getSuffix(1)); } return obj; } } } result = ((NamingEntry) result).getObject(); if (result instanceof LinkRef) { LinkRef ref = (LinkRef) result; result = lookup(ref.getLinkName()); } if (result instanceof Reference) { try { result = NamingManager.getObjectInstance(result, null, null, this.environment); } catch (NamingException e) { throw e; } catch (Exception e) { throw (NamingException) new NamingException("could not look up : " + name).initCause(e); } } if (result instanceof NamingContext && name.size() > 1) { return ((NamingContext) result).lookup(name.getSuffix(1)); } return result; } NamingContext();  NamingContext(Hashtable<String, Object> environment);  NamingContext(Hashtable<String, Object> environment, Map<String, Object> objects);  NamingContext(Hashtable<String, Object> environment, String nameInNamespace); @Override void bind(Name name, Object object); void bind(Name bindName, Object object, boolean rebind); @Override Name composeName(Name name, Name prefix); @Override String composeName(String name, String prefix); @Override Context createSubcontext(Name name); @Override void destroySubcontext(Name contextToDestroy); @Override String getNameInNamespace(); @Override NameParser getNameParser(Name name); @Override NameParser getNameParser(String name); @Override NamingEnumeration list(Name name); @Override NamingEnumeration list(String name); @Override NamingEnumeration<Binding> listBindings(Name name); @Override NamingEnumeration<Binding> listBindings(String name); @Override Object lookup(Name lookupName); @Override Object lookupLink(Name name); @Override void rebind(Name name, Object object); @Override void rename(Name oldName, Name newName); @Override void unbind(Name toUnbind); @Override Object lookup(String name); @Override Object lookupLink(String name); @Override void unbind(String name); @Override void rebind(String name, Object object); @Override Object removeFromEnvironment(String propertyName); @Override Object addToEnvironment(String propertyName, Object propertyVal); @Override Hashtable<?, ?> getEnvironment(); @Override void bind(String name, Object object); @Override void close(); @Override Context createSubcontext(String name); @Override void destroySubcontext(String name); @Override void rename(String oldName, String newName);  }