bind(name, value, false);
}
protected void bind(Name name, Object value, boolean allowOverwrites)
throws NamingException {
Name bindName = validateName(name);
// If null, it means we don't know how to handle this -> throw to the
// parent
if (bindName == null)
this.parent.bind(name, value, allowOverwrites);
// If empty name, complain - we should have a child name here
else if (bindName.isEmpty())
throw new NamingException(ContainerJNDIManager.JNDI_RESOURCES.getString(
"WinstoneContext.AlreadyExists", name.toString()));
else if (bindName.size() > 1) {
Object ctx = lookup(bindName.get(0));
if (!(ctx instanceof Context))
throw new NotContextException(ContainerJNDIManager.JNDI_RESOURCES.getString(
"WinstoneContext.NotContext", new String[] {
bindName.get(0), ctx.getClass().getName() }));
else if (ctx == null)
throw new NameNotFoundException(ContainerJNDIManager.JNDI_RESOURCES.getString(
"WinstoneContext.NameNotFound", bindName.get(0)));
else
try {
if (allowOverwrites)
((Context) ctx).rebind(bindName.getSuffix(1), value);
else
((Context) ctx).bind(bindName.getSuffix(1), value);
} finally {
((Context) ctx).close();
}
} else if ((!allowOverwrites) && this.bindings.get(name.get(0)) != null)
throw new NamingException(ContainerJNDIManager.JNDI_RESOURCES.getString(
"WinstoneContext.AlreadyExists", name.toString()));
else {
value = NamingManager.getStateToBind(value, new CompositeName()
.add(bindName.get(0)), this, this.environment);
synchronized (this.contextLock) {
this.bindings.put(bindName.get(0), value);
}
}
}