contextimpl.java

来自「RESIN 3.2 最新源码」· Java 代码 · 共 1,189 行 · 第 1/2 页

JAVA
1,189
字号
    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).unbind(name.getSuffix(i + 1));        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);        model.unbind(first);  }  public void rename(String oldName, String newName)    throws NamingException  {    Object obj = lookup(oldName);    unbind(oldName);    bind(newName, obj);  }  public void rename(Name oldName, Name newName)    throws NamingException  {    Object obj = lookup(oldName);    unbind(oldName);    bind(newName, obj);  }  /**   * List the names for a context.   */  public NamingEnumeration list(String name)    throws NamingException  {    String tail = name;    AbstractModel model = _model;    while (true) {      String first = parseFirst(tail);      String rest = parseRest(tail);            if (first == null) {        return new QNameClassEnumeration(create(model, _env),                                         model.list());      }      Object value = model.lookup(first);      if (value instanceof AbstractModel) {        model = (AbstractModel) value;        tail = rest;        continue;      }      value = dereference(value, null, model);      if (value instanceof Context) {	if (rest == null)	  return ((Context) value).list("");	else	  return ((Context) value).list(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));    }  }  /**   * Lists the names for the context.   */  public NamingEnumeration list(Name name)    throws NamingException  {    AbstractModel model = _model;    if (name == null) {      return new QNameClassEnumeration(create(model, _env),                                       model.list());    }    for (int i = 0; i < 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).list(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));    }        return new QNameClassEnumeration(create(model, _env),                                     model.list());  }  /**   * List the bindings for a context.   */  public NamingEnumeration listBindings(String name)    throws NamingException  {    String tail = name;    AbstractModel model = _model;    while (true) {      String first = parseFirst(tail);      String rest = parseRest(tail);            if (first == null) {        return new QBindingEnumeration(create(model, _env),                                       model.list());      }      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).listBindings(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));    }  }  /**   * Lists the bindings for the given name.   */  public NamingEnumeration listBindings(Name name)    throws NamingException  {    AbstractModel model = _model;    for (int i = 0; name != null && i < 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).listBindings(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));    }        return new QBindingEnumeration(create(model, _env),                                   model.list());  }  /**   * 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));    }  }  public Context createSubcontext(Name name)    throws NamingException  {    if (name.size() == 0)      throw new NamingException(L.l("can't createSubcontext 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) {        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(model, _env);  }  /**   * Destroys the named subcontext.   */  public void destroySubcontext(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.unbind(first);        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).destroySubcontext(rest);        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));    }  }    public void destroySubcontext(Name name)    throws NamingException  {    if (name.size() == 0)      throw new NamingException(L.l("can't createSubcontext 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).destroySubcontext(name.getSuffix(i + 1));        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);        model.unbind(first);  }  public NameParser getNameParser(String name)    throws NamingException  {    String first = parseFirst(name);    String rest = parseRest(name);        if (first == null)      return new QNameParser(this);    Object obj = lookupSingleObject(first);    if (obj instanceof Context)      return ((Context) obj).getNameParser(rest == null ? "" : rest);    else      return new QNameParser(this);  }  public NameParser getNameParser(Name name)    throws NamingException  {    if (name.size() == 0)      return new QNameParser(this);          Object obj = lookupSingleObject(name.get(0));    if (obj instanceof Context)      return ((Context) obj).getNameParser(name.getSuffix(1));    else      return new QNameParser(this);  }  public String composeName(String suffix, String prefix)    throws NamingException  {    return prefix + "/" + suffix;  }  public Name composeName(Name suffix, Name prefix)    throws NamingException  {    return prefix.addAll(suffix);  }  public String getNameInNamespace()    throws NamingException  {    throw new OperationNotSupportedException();  }  /**   * Looks up the object and dereferences any proxy objects.   */  private Object lookupSingleObject(String name)    throws NamingException  {    Object obj = lookupSingle(name);    if (obj instanceof ObjectProxy)      return ((ObjectProxy) obj).createObject(_env);    else      return obj;  }  /**   * Returns the object named by the single name segment.   *   * @param name the name segment.   *   * @return the object bound to the context.   */  protected Object lookupSingle(String name)    throws NamingException  {    throw new UnsupportedOperationException();  }  protected void rebindSingle(String name, Object obj)    throws NamingException  {    throw new UnsupportedOperationException();  }  protected void unbindSingle(String name)    throws NamingException  {    throw new UnsupportedOperationException();  }  protected Context createSingleSubcontext(String name)    throws NamingException  {    throw new UnsupportedOperationException();  }    protected void destroySingleSubcontext(String name)    throws NamingException  {    unbindSingle(name);  }  protected Iterator listSingle()  {    throw new UnsupportedOperationException();  }  protected String parseFirst(String name)    throws NamingException  {    if (name == null || name.equals(""))      return null;        int p = name.indexOf(getSeparator());    if (p == 0)      return parseFirst(name.substring(1));    else if (p > 0)      return name.substring(0, p);    else      return name;  }      protected String parseRest(String name)    throws NamingException  {    if (name == null || name.equals(""))      return null;        int p = name.indexOf(getSeparator());    if (p == 0)      return parseRest(name.substring(1));    else if (p > 0)      return name.substring(p + 1);    else      return null;  }  protected char getSeparator()  {    return '/';  }  protected String getSeparatorString()  {    return "/";  }  /**   * Returns the full name for the context.   */  protected String getFullPath(String name)  {    if (_name == null || _name.equals(""))      return name;    else if (name == null)      return _name;    String sep = getSeparatorString();        while (name.endsWith(sep))      name = name.substring(0, name.length() - sep.length());            if (name.equals(""))      return _name;          else if (name.startsWith(sep))      return _name + name;    else      return _name + sep + name;  }  /**   * Returns the full name for the context.   */  protected String getFullPath(Name name)  {    if (_name == null || _name.equals(""))      return name.toString();    else if (name == null || name.size() == 0)      return _name;    String sep = getSeparatorString();    return _name + sep + name;  }  /**   * Adds a property to the context environment.   */  public Object addToEnvironment(String prop, Object value)    throws NamingException  {    Object old = _env.get(prop);    _env.put(prop, value);    return old;  }  /**   * Removes a property from the context environment.   */  public Object removeFromEnvironment(String prop)    throws NamingException  {    Object old = _env.get(prop);    _env.remove(prop);    return old;  }  /**   * Returns the context environment.   */  public Hashtable getEnvironment()    throws NamingException  {    return _env;  }  /**   * Close is intended to free any transient data, like a cached   * socket.  It does not affect the JNDI tree.   */  public void close()    throws NamingException  {  }  /**   * Returns a string value.   */  public String toString()  {    return "ContextImpl[" + _name + "]";  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?