public void rebind(Name name, Object obj) throws NamingException { if (name.size() == 0) throw new NamingException(L.l("can't bind root")); AbstractModel model = _model; int i = 0; for (; i + 1 < name.size(); i++) { String first = name.get(i); Object value = model.lookup(first); if (value instanceof AbstractModel) { model = (AbstractModel) value; continue; } value = dereference(value, null, model); if (value instanceof Context) { ((Context) value).bind(name.getSuffix(i + 1), obj); return; } else if (value != null) throw new NotContextException( L.l("{0}: expected intermediate context at `{1}'", getFullPath(name), value)); else throw new NameNotFoundException(getFullPath(name)); } String first = name.get(i); if (obj == null) obj = NullValue.NULL; model.bind(first, getReference(model, obj)); }
/** * Binds an object to the context, overriding any old value. * * @param name the name to bind * @param obj the object to bind */ @Override public void rebind(String name, Object obj) throws NamingException { if (log.isLoggable(Level.FINEST)) log.finest(L.l("JNDI rebind `{0}' value: {1}", name, obj)); String tail = name; AbstractModel model = _model; // env/0gde if (obj == null) obj = NullValue.NULL; while (true) { String first = parseFirst(tail); String rest = parseRest(tail); if (first == null) throw new NamingException(L.l("can't bind root")); if (rest == null) { model.bind(first, getReference(model, obj)); return; } Object value = model.lookup(first); if (value instanceof AbstractModel) { model = (AbstractModel) value; tail = rest; continue; } value = dereference(value, null, model); if (value instanceof Context) { ((Context) value).rebind(rest, obj); return; } else if (value != null) throw new NotContextException( L.l( "{0}: expected intermediate context at '{1}'\n {2}", getFullPath(name), value, Thread.currentThread().getContextClassLoader())); else throw new NameNotFoundException( L.l( "{0}: JNDI rebind requires the parent Context '{1}' to be created but it is null.\n {2}',", getFullPath(name), first, Thread.currentThread().getContextClassLoader())); } }
/** Binds an object to the context. */ public void bind(String name, Object obj) throws NamingException { String tail = name; AbstractModel model = _model; if (obj == null) obj = NullValue.NULL; while (true) { String first = parseFirst(tail); String rest = parseRest(tail); if (first == null) throw new NamingException(L.l("can't bind root")); if (rest == null) { Object value = model.lookup(first); if (value != null) throw new NamingException(L.l("`{0}' is already bound to `{1}'", name, value)); model.bind(first, getReference(model, obj)); return; } Object value = model.lookup(first); if (value instanceof AbstractModel) { model = (AbstractModel) value; tail = rest; continue; } value = dereference(value, null, model); if (value instanceof Context) { ((Context) value).bind(rest, obj); return; } else if (value != null) { throw new NotContextException( L.l("{0}: expected intermediate context at `{1}'", getFullPath(name), value)); } else { throw new NameNotFoundException(getFullPath(name)); } } }