use of javax.naming.NameNotFoundException in project jetty.project by eclipse.
the class NamingContext method createSubcontext.
/*------------------------------------------------*/
/**
* Create a context as a child of this one
*
* @param name a <code>Name</code> value
* @return a <code>Context</code> value
* @exception NamingException if an error occurs
*/
public Context createSubcontext(Name name) throws NamingException {
if (isLocked()) {
NamingException ne = new NamingException("This context is immutable");
ne.setRemainingName(name);
throw ne;
}
Name cname = toCanonicalName(name);
if (cname == null)
throw new NamingException("Name is null");
if (cname.size() == 0)
throw new NamingException("Name is empty");
if (cname.size() == 1) {
//not permitted to bind if something already bound at that name
Binding binding = getBinding(cname);
if (binding != null)
throw new NameAlreadyBoundException(cname.toString());
Context ctx = new NamingContext((Hashtable) _env.clone(), cname.get(0), this, _parser);
addBinding(cname, ctx);
return ctx;
}
//If the name has multiple subcontexts, walk the hierarchy by
//fetching the first one. All intermediate subcontexts in the
//name must already exist.
String firstComponent = cname.get(0);
Object ctx = null;
if (firstComponent.equals(""))
ctx = this;
else {
Binding binding = getBinding(firstComponent);
if (binding == null)
throw new NameNotFoundException(firstComponent + " is not bound");
ctx = binding.getObject();
if (ctx instanceof Reference) {
//deference the object
if (__log.isDebugEnabled())
__log.debug("Object bound at " + firstComponent + " is a Reference");
try {
ctx = NamingManager.getObjectInstance(ctx, getNameParser("").parse(firstComponent), this, _env);
} catch (NamingException e) {
throw e;
} catch (Exception e) {
__log.warn("", e);
throw new NamingException(e.getMessage());
}
}
}
if (ctx instanceof Context) {
return ((Context) ctx).createSubcontext(cname.getSuffix(1));
} else
throw new NotContextException(firstComponent + " is not a Context");
}
use of javax.naming.NameNotFoundException in project jetty.project by eclipse.
the class NamingContext method list.
/*------------------------------------------------*/
/**
* List all names bound at Context named by Name
*
* @param name a <code>Name</code> value
* @return a <code>NamingEnumeration</code> value
* @exception NamingException if an error occurs
*/
public NamingEnumeration list(Name name) throws NamingException {
if (__log.isDebugEnabled())
__log.debug("list() on Context=" + getName() + " for name=" + name);
Name cname = toCanonicalName(name);
if (cname == null) {
return new NameEnumeration(__empty.iterator());
}
if (cname.size() == 0) {
return new NameEnumeration(_bindings.values().iterator());
}
//multipart name
String firstComponent = cname.get(0);
Object ctx = null;
if (firstComponent.equals(""))
ctx = this;
else {
Binding binding = getBinding(firstComponent);
if (binding == null)
throw new NameNotFoundException();
ctx = binding.getObject();
if (ctx instanceof Reference) {
//deference the object
if (__log.isDebugEnabled())
__log.debug("Dereferencing Reference for " + name.get(0));
try {
ctx = NamingManager.getObjectInstance(ctx, getNameParser("").parse(firstComponent), this, _env);
} catch (NamingException e) {
throw e;
} catch (Exception e) {
__log.warn("", e);
throw new NamingException(e.getMessage());
}
}
}
if (!(ctx instanceof Context))
throw new NotContextException();
return ((Context) ctx).list(cname.getSuffix(1));
}
use of javax.naming.NameNotFoundException in project jetty.project by eclipse.
the class NamingContext method lookupLink.
/*------------------------------------------------*/
/**
* Lookup link bound to name
*
* @param name name of link binding
* @return LinkRef or plain object bound at name
* @exception NamingException if an error occurs
*/
public Object lookupLink(Name name) throws NamingException {
Name cname = toCanonicalName(name);
if (cname == null) {
NamingContext ctx = new NamingContext(_env, _name, _parent, _parser);
ctx._bindings = _bindings;
return ctx;
}
if (cname.size() == 0)
throw new NamingException("Name is empty");
if (cname.size() == 1) {
Binding binding = getBinding(cname);
if (binding == null)
throw new NameNotFoundException();
Object o = binding.getObject();
//handle links by looking up the link
if (o instanceof Reference) {
//deference the object
try {
return NamingManager.getObjectInstance(o, cname.getPrefix(1), this, _env);
} catch (NamingException e) {
throw e;
} catch (Exception e) {
__log.warn("", e);
throw new NamingException(e.getMessage());
}
} else {
//or a plain object in which case spec says we return it
return o;
}
}
//it is a multipart name, recurse to the first subcontext
String firstComponent = cname.get(0);
Object ctx = null;
if (firstComponent.equals(""))
ctx = this;
else {
Binding binding = getBinding(firstComponent);
if (binding == null)
throw new NameNotFoundException();
ctx = binding.getObject();
if (ctx instanceof Reference) {
//deference the object
try {
ctx = NamingManager.getObjectInstance(ctx, getNameParser("").parse(firstComponent), this, _env);
} catch (NamingException e) {
throw e;
} catch (Exception e) {
__log.warn("", e);
throw new NamingException(e.getMessage());
}
}
}
if (!(ctx instanceof Context))
throw new NotContextException();
return ((Context) ctx).lookup(cname.getSuffix(1));
}
use of javax.naming.NameNotFoundException in project jetty.project by eclipse.
the class localContextRoot method lookupLink.
/**
*
*
* @see javax.naming.Context#lookupLink(javax.naming.Name)
*/
public Object lookupLink(Name name) throws NamingException {
synchronized (__root) {
//return __root.lookupLink(getSuffix(name));
Name cname = __root.toCanonicalName(name);
if (cname == null) {
//If no name create copy of this context with same bindings, but with copy of the environment so it can be modified
NamingContext ctx = new NamingContext(_env, null, null, __root.getNameParser(""));
ctx.setBindings(__root.getBindings());
return ctx;
}
if (cname.size() == 0)
throw new NamingException("Name is empty");
if (cname.size() == 1) {
Binding binding = __root.getBinding(cname);
if (binding == null)
throw new NameNotFoundException();
Object o = binding.getObject();
//handle links by looking up the link
if (o instanceof Reference) {
//deference the object
try {
return NamingManager.getObjectInstance(o, cname.getPrefix(1), __root, _env);
} catch (NamingException e) {
throw e;
} catch (Exception e) {
__log.warn("", e);
throw new NamingException(e.getMessage());
}
} else {
//or a plain object in which case spec says we return it
return o;
}
}
//it is a multipart name, recurse to the first subcontext
String firstComponent = cname.get(0);
Object ctx = null;
if (firstComponent.equals(""))
ctx = this;
else {
Binding binding = __root.getBinding(firstComponent);
if (binding == null)
throw new NameNotFoundException();
ctx = binding.getObject();
if (ctx instanceof Reference) {
//deference the object
try {
ctx = NamingManager.getObjectInstance(ctx, getNameParser("").parse(firstComponent), __root, _env);
} catch (NamingException e) {
throw e;
} catch (Exception e) {
__log.warn("", e);
throw new NamingException(e.getMessage());
}
}
}
if (!(ctx instanceof Context))
throw new NotContextException();
return ((Context) ctx).lookup(cname.getSuffix(1));
}
}
use of javax.naming.NameNotFoundException in project jetty.project by eclipse.
the class NamingContext method listBindings.
/*------------------------------------------------*/
/**
* List all Bindings present at Context named by Name
*
* @param name a <code>Name</code> value
* @return a <code>NamingEnumeration</code> value
* @exception NamingException if an error occurs
*/
public NamingEnumeration listBindings(Name name) throws NamingException {
Name cname = toCanonicalName(name);
if (cname == null) {
return new BindingEnumeration(__empty.iterator());
}
if (cname.size() == 0) {
return new BindingEnumeration(_bindings.values().iterator());
}
//multipart name
String firstComponent = cname.get(0);
Object ctx = null;
//at this level in the tree
if (firstComponent.equals(""))
ctx = this;
else {
//it is a non-empty name component
Binding binding = getBinding(firstComponent);
if (binding == null)
throw new NameNotFoundException();
ctx = binding.getObject();
if (ctx instanceof Reference) {
//deference the object
try {
ctx = NamingManager.getObjectInstance(ctx, getNameParser("").parse(firstComponent), this, _env);
} catch (NamingException e) {
throw e;
} catch (Exception e) {
__log.warn("", e);
throw new NamingException(e.getMessage());
}
}
}
if (!(ctx instanceof Context))
throw new NotContextException();
return ((Context) ctx).listBindings(cname.getSuffix(1));
}
Aggregations