use of javax.naming.NameAlreadyBoundException in project jetty.project by eclipse.
the class NamingContext method addBinding.
/*------------------------------------------------*/
/**
* Add a name to object binding to this Context.
*
* @param name a <code>Name</code> value
* @param obj an <code>Object</code> value
* @throws NameAlreadyBoundException if name already bound
*/
public void addBinding(Name name, Object obj) throws NameAlreadyBoundException {
String key = name.toString();
Binding binding = new Binding(key, obj);
Collection<Listener> list = findListeners();
for (Listener listener : list) {
binding = listener.bind(this, binding);
if (binding == null)
break;
}
if (__log.isDebugEnabled())
__log.debug("Adding binding with key=" + key + " obj=" + obj + " for context=" + _name + " as " + binding);
if (binding != null) {
if (_bindings.containsKey(key)) {
if (_supportDeepBinding) {
// jndi users like openejb.
return;
}
throw new NameAlreadyBoundException(name.toString());
}
_bindings.put(key, binding);
}
}
use of javax.naming.NameAlreadyBoundException in project wildfly by wildfly.
the class ExceptionMapper method mapException.
public static NamingException mapException(Exception e, CNCtx ctx, NameComponent[] inputName) throws NamingException {
if (e instanceof NamingException) {
return (NamingException) e;
}
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
NamingException ne;
if (e instanceof NotFound) {
if (ctx.federation) {
return tryFed((NotFound) e, ctx, inputName);
} else {
ne = new NameNotFoundException();
}
} else if (e instanceof CannotProceed) {
ne = new CannotProceedException();
NamingContext nc = ((CannotProceed) e).cxt;
NameComponent[] rest = ((CannotProceed) e).rest_of_name;
// NotFound doesn't set rest as expected. -RL
if (inputName != null && (inputName.length > rest.length)) {
NameComponent[] resolvedName = new NameComponent[inputName.length - rest.length];
System.arraycopy(inputName, 0, resolvedName, 0, resolvedName.length);
// Wrap resolved NamingContext inside a CNCtx
// Guess that its name (which is relative to ctx)
// is the part of inputName minus rest_of_name
ne.setResolvedObj(new CNCtx(ctx._orb, nc, ctx._env, ctx.makeFullName(resolvedName)));
} else {
ne.setResolvedObj(ctx);
}
ne.setRemainingName(org.wildfly.iiop.openjdk.naming.jndi.CNNameParser.cosNameToName(rest));
} else if (e instanceof InvalidName) {
ne = new InvalidNameException();
} else if (e instanceof AlreadyBound) {
ne = new NameAlreadyBoundException();
} else if (e instanceof NotEmpty) {
ne = new ContextNotEmptyException();
} else {
ne = new NamingException();
}
ne.setRootCause(e);
return ne;
}
use of javax.naming.NameAlreadyBoundException in project geronimo-xbean by apache.
the class AbstractContext method createSubcontext.
public Context createSubcontext(Name name) throws NamingException {
if (!modifiable)
throw new OperationNotSupportedException("Context is read only");
if (name == null)
throw new NullPointerException("name is null");
if (name.isEmpty()) {
throw new NameAlreadyBoundException("Cannot create a subcontext if the name is empty");
}
Context abstractContext = createNestedSubcontext(name.toString(), Collections.EMPTY_MAP);
addDeepBinding(name, abstractContext, false, false);
return abstractContext;
}
use of javax.naming.NameAlreadyBoundException in project geronimo-xbean by apache.
the class AbstractContext method rename.
public void rename(Name oldName, Name newName) throws NamingException {
if (!modifiable)
throw new OperationNotSupportedException("Context is read only");
if (oldName == null || newName == null) {
throw new NullPointerException("name is null");
} else if (oldName.isEmpty() || newName.isEmpty()) {
throw new NameAlreadyBoundException("Name cannot be empty");
}
this.bind(newName, this.lookup(oldName));
this.unbind(oldName);
}
use of javax.naming.NameAlreadyBoundException in project geronimo-xbean by apache.
the class WritableContext method addBinding.
protected void addBinding(AtomicReference<Map<String, Object>> bindingsRef, String name, String nameInNamespace, Object value, boolean rebind) throws NamingException {
if (supportReferenceable && value instanceof Referenceable) {
Reference ref = ((Referenceable) value).getReference();
if (ref != null) {
if (checkDereferenceDifferent) {
try {
Object o = NamingManager.getObjectInstance(ref, null, null, new Hashtable());
if (!value.equals(o)) {
value = ref;
}
} catch (Exception e) {
if (!assumeDereferenceBound) {
value = ref;
}
}
} else {
value = ref;
}
}
}
if (cacheReferences) {
value = CachingReference.wrapReference(name, value, this);
}
writeLock.lock();
try {
Map<String, Object> bindings = bindingsRef.get();
if (!rebind && bindings.containsKey(name)) {
throw new NameAlreadyBoundException(name);
}
Map<String, Object> newBindings = new HashMap<String, Object>(bindings);
newBindings.put(name, value);
bindingsRef.set(newBindings);
addToIndex(nameInNamespace, value);
} finally {
writeLock.unlock();
}
}
Aggregations