public Context createSubcontext(Name name) throws NamingException { if (name.size() == 0) throw new NamingException(L.l("can't create root subcontext")); 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) { return ((Context) value).createSubcontext(name.getSuffix(i + 1)); } 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); model = model.createSubcontext(first); return create(getFullPath(name), model, _env); }
/** Creates a subcontext for the current model. */ public Context createSubcontext(String name) throws NamingException { String tail = name; AbstractModel model = _model; while (true) { String first = parseFirst(tail); String rest = parseRest(tail); if (first == null) throw new NamingException(L.l("can't create root subcontext")); if (rest == null) { model = model.createSubcontext(first); return create(getFullPath(name), model, _env); } Object value = model.lookup(first); if (value instanceof AbstractModel) { model = (AbstractModel) value; tail = rest; continue; } value = dereference(value, null, model); if (value instanceof Context) return ((Context) value).createSubcontext(rest); else if (value != null) throw new NotContextException( L.l("{0}: expected intermediate context at `{1}'", getFullPath(name), value)); else throw new NameNotFoundException(getFullPath(name)); } }