Exemplo n.º 1
0
 /**
  * Add a java:comp/env binding for the object represented by this NamingEntry, but bind it as the
  * name supplied
  *
  * @throws NamingException
  */
 public void bindToENC(String localName) throws NamingException {
   // TODO - check on the whole overriding/non-overriding thing
   InitialContext ic = new InitialContext();
   Context env = (Context) ic.lookup("java:comp/env");
   __log.debug("Binding java:comp/env/" + localName + " to " + _objectNameString);
   NamingUtil.bind(env, localName, new LinkRef(_objectNameString));
 }
Exemplo n.º 2
0
  /**
   * Save the NamingEntry for later use.
   *
   * <p>Saving is done by binding the NamingEntry itself, and the value it represents into JNDI. In
   * this way, we can link to the value it represents later, but also still retrieve the NamingEntry
   * itself too.
   *
   * <p>The object is bound at the jndiName passed in. This NamingEntry is bound at __/jndiName.
   *
   * <p>eg
   *
   * <p>jdbc/foo : DataSource __/jdbc/foo : NamingEntry
   *
   * @throws NamingException
   */
  protected void save(Object object) throws NamingException {
    __log.debug("SAVE {} in {}", this, _scope);
    InitialContext ic = new InitialContext();
    NameParser parser = ic.getNameParser("");
    Name prefix = NamingEntryUtil.getNameForScope(_scope);

    // bind the NamingEntry into the context
    Name namingEntryName = NamingEntryUtil.makeNamingEntryName(parser, getJndiName());
    namingEntryName.addAll(0, prefix);
    _namingEntryNameString = namingEntryName.toString();
    NamingUtil.bind(ic, _namingEntryNameString, this);

    // bind the object as well
    Name objectName = parser.parse(getJndiName());
    objectName.addAll(0, prefix);
    _objectNameString = objectName.toString();
    NamingUtil.bind(ic, _objectNameString, object);
  }