use of javax.naming.NotContextException in project jetty.project by eclipse.
the class NamingContext method rebind.
/*------------------------------------------------*/
/**
* Overwrite or create a binding
*
* @param name a <code>Name</code> value
* @param obj an <code>Object</code> value
* @exception NamingException if an error occurs
*/
public void rebind(Name name, Object obj) throws NamingException {
if (isLocked())
throw new NamingException("This context is immutable");
Name cname = toCanonicalName(name);
if (cname == null)
throw new NamingException("Name is null");
if (cname.size() == 0)
throw new NamingException("Name is empty");
//if no subcontexts, just bind it
if (cname.size() == 1) {
//check if it is a Referenceable
Object objToBind = NamingManager.getStateToBind(obj, name, this, _env);
if (objToBind instanceof Referenceable) {
objToBind = ((Referenceable) objToBind).getReference();
}
removeBinding(cname);
addBinding(cname, objToBind);
} else {
//walk down the subcontext hierarchy
if (__log.isDebugEnabled())
__log.debug("Checking for existing binding for name=" + cname + " for first element of name=" + cname.get(0));
String firstComponent = cname.get(0);
Object ctx = null;
if (firstComponent.equals(""))
ctx = this;
else {
Binding binding = getBinding(name.get(0));
if (binding == null)
throw new NameNotFoundException(name.get(0) + " is not bound");
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) {
((Context) ctx).rebind(cname.getSuffix(1), obj);
} else
throw new NotContextException("Object bound at " + firstComponent + " is not a Context");
}
}
use of javax.naming.NotContextException in project jetty.project by eclipse.
the class localContextRoot method lookup.
/**
*
*
* @see javax.naming.Context#lookup(javax.naming.Name)
*/
public Object lookup(Name name) throws NamingException {
synchronized (__root) {
if (__log.isDebugEnabled())
__log.debug("Looking up name=\"" + name + "\"");
Name cname = __root.toCanonicalName(name);
if ((cname == null) || (cname.size() == 0)) {
__log.debug("Null or empty name, returning copy of this context");
NamingContext ctx = new NamingContext(_env, null, null, __root.getNameParser(""));
ctx.setBindings(__root.getBindings());
return ctx;
}
if (cname.size() == 1) {
Binding binding = __root.getBinding(cname);
if (binding == null) {
NameNotFoundException nnfe = new NameNotFoundException();
nnfe.setRemainingName(cname);
throw nnfe;
}
Object o = binding.getObject();
//handle links by looking up the link
if (o instanceof LinkRef) {
//if link name starts with ./ it is relative to current context
String linkName = ((LinkRef) o).getLinkName();
if (linkName.startsWith("./"))
return lookup(linkName.substring(2));
else {
//link name is absolute
InitialContext ictx = new InitialContext();
return ictx.lookup(linkName);
}
} else if (o instanceof Reference) {
//deference the object
try {
return NamingManager.getObjectInstance(o, cname, __root, _env);
} catch (NamingException e) {
throw e;
} catch (final Exception e) {
throw new NamingException(e.getMessage()) {
{
initCause(e);
}
};
}
} else
return o;
}
//it is a multipart name, get 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) {
NameNotFoundException nnfe = new NameNotFoundException();
nnfe.setRemainingName(cname);
throw nnfe;
}
//as we have bound a reference to an object factory
//for the component specific contexts
//at "comp" we need to resolve the reference
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.NotContextException in project wildfly by wildfly.
the class CNCtx method destroySubcontext.
/**
* Uses the callDestroy function to destroy the context. Destroys
* the current context if name is empty.
*
* @param name JNDI Name
* @throws javax.naming.OperationNotSupportedException when list is invoked
* with a non-null argument
*/
public void destroySubcontext(Name name) throws NamingException {
if (_nc == null)
throw IIOPLogger.ROOT_LOGGER.notANamingContext(name.toString());
NamingContext the_nc = _nc;
NameComponent[] path = org.wildfly.iiop.openjdk.naming.jndi.CNNameParser.nameToCosName(name);
if (name.size() > 0) {
try {
javax.naming.Context ctx = (javax.naming.Context) callResolve(path);
CNCtx cnc = (CNCtx) ctx;
the_nc = cnc._nc;
//remove the reference to the context
cnc.close();
} catch (ClassCastException e) {
throw new NotContextException(name.toString());
} catch (CannotProceedException e) {
javax.naming.Context cctx = getContinuationContext(e);
cctx.destroySubcontext(e.getRemainingName());
return;
} catch (NameNotFoundException e) {
if (e.getRootCause() instanceof NotFound && leafNotFound((NotFound) e.getRootCause(), path[path.length - 1])) {
// leaf missing OK
return;
}
throw e;
} catch (NamingException e) {
throw e;
}
}
callDestroy(the_nc);
callUnbind(path);
}
use of javax.naming.NotContextException in project geode by apache.
the class ContextImpl method listBindings.
/**
* Lists all bindings for Context with name name. If name is empty then this Context is assumed.
*
* @param name name of Context, relative to this Context
* @return NamingEnumeration of all name-object pairs. Each element from the enumeration is
* instance of Binding.
* @throws NoPermissionException if this context has been destroyed
* @throws InvalidNameException if name is CompositeName that spans more than one naming system
* @throws NameNotFoundException if name can not be found
* @throws NotContextException component of name is not bound to instance of ContextImpl, when
* name is not an atomic name
* @throws NamingException if any other naming error occurs
*
*/
public NamingEnumeration listBindings(Name name) throws NamingException {
checkIsDestroyed();
Name parsedName = getParsedName(name);
if (parsedName.size() == 0) {
Vector bindings = new Vector();
Iterator iterat = ctxMaps.keySet().iterator();
while (iterat.hasNext()) {
String bindingName = (String) iterat.next();
bindings.addElement(new Binding(bindingName, ctxMaps.get(bindingName)));
}
return new NamingEnumerationImpl(bindings);
} else {
Object subContext = ctxMaps.get(parsedName.get(0));
if (subContext instanceof Context) {
Name nextLayer = nameParser.parse("");
// getSuffix(1) only apply to name with size() > 1
if (parsedName.size() > 1) {
nextLayer = parsedName.getSuffix(1);
}
return ((Context) subContext).list(nextLayer);
}
if (subContext == null && !ctxMaps.containsKey(parsedName.get(0))) {
throw new NameNotFoundException(LocalizedStrings.ContextImpl_NAME_0_NOT_FOUND.toLocalizedString(name));
} else {
throw new NotContextException(LocalizedStrings.ContextImpl_EXPECTED_CONTEXT_BUT_FOUND_0.toLocalizedString(subContext));
}
}
}
use of javax.naming.NotContextException in project geode by apache.
the class ContextImpl method lookup.
/**
* Looks up object with binding name name in this context.
*
* @param name name to look up
* @return object reference bound to name name.
* @throws NoPermissionException if this context has been destroyed.
* @throws InvalidNameException if name is CompositeName that spans more than one naming system
* @throws NameNotFoundException if name can not be found.
* @throws NotContextException component of name is not bound to instance of ContextImpl, when
* name is not atomic name.
* @throws NamingException if any other naming error occurs
*
*/
public Object lookup(Name name) throws NamingException {
checkIsDestroyed();
try {
Name parsedName = getParsedName(name);
String nameComponent = parsedName.get(0);
Object res = ctxMaps.get(nameComponent);
if (res instanceof UserTransactionImpl) {
res = new UserTransactionImpl();
}
// if not found
if (!ctxMaps.containsKey(nameComponent)) {
throw new NameNotFoundException(LocalizedStrings.ContextImpl_NAME_0_NOT_FOUND.toLocalizedString(name));
} else // if this is a compound name
if (parsedName.size() > 1) {
if (res instanceof ContextImpl) {
res = ((ContextImpl) res).lookup(parsedName.getSuffix(1));
} else {
throw new NotContextException(LocalizedStrings.ContextImpl_EXPECTED_CONTEXTIMPL_BUT_FOUND_0.toLocalizedString(res));
}
}
return res;
} catch (NameNotFoundException e) {
LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
if (writer.infoEnabled())
writer.info(LocalizedStrings.ContextImpl_CONTEXTIMPL_LOOKUP_ERROR_WHILE_LOOKING_UP_0, name, e);
throw new NameNotFoundException(LocalizedStrings.ContextImpl_NAME_0_NOT_FOUND.toLocalizedString(new Object[] { name }));
} catch (SystemException se) {
LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
if (writer.severeEnabled())
writer.info(LocalizedStrings.ContextImpl_CONTEXTIMPL_LOOKUP_ERROR_WHILE_CREATING_USERTRANSACTION_OBJECT, se);
throw new NameNotFoundException(LocalizedStrings.ContextImpl_CONTEXTIMPL_LOOKUP_ERROR_WHILE_CREATING_USERTRANSACTION_OBJECT.toLocalizedString());
}
}
Aggregations