Ejemplo n.º 1
0
  public org.omg.CORBA.Object resolve(NameComponent[] nc)
      throws NotFound, CannotProceed, InvalidName {
    if (this.destroyed) throw new CannotProceed();

    if (nc == null || nc.length == 0) throw new InvalidName();

    Name n = new Name(nc[0]);
    if (nc.length > 1) {
      org.omg.CORBA.Object next_context = (org.omg.CORBA.Object) this.contexts.get(n);
      if ((next_context == null) || (isDead(next_context)))
        throw new NotFound(NotFoundReason.missing_node, nc);

      NameComponent[] nc_prime = new NameComponent[nc.length - 1];
      System.arraycopy(nc, 1, nc_prime, 0, nc_prime.length);

      // try first to call the context implementation object directly.
      String contextOID = this.getObjectOID(next_context);
      JBossNamingContext jbossContext = (contextOID == null ? null : contextImpls.get(contextOID));
      if (jbossContext != null) return jbossContext.resolve(nc_prime);
      else return NamingContextExtHelper.narrow(next_context).resolve(nc_prime);
    } else {
      org.omg.CORBA.Object result = (org.omg.CORBA.Object) this.contexts.get(n);

      if (result == null) result = (org.omg.CORBA.Object) this.names.get(n);

      if (result == null) throw new NotFound(NotFoundReason.missing_node, n.components());

      if (!noPing && isDead(result))
        throw new NotFound(NotFoundReason.missing_node, n.components());

      return result;
    }
  }
Ejemplo n.º 2
0
 public NamingContext new_context() {
   try {
     // create and initialize a new context.
     JBossNamingContext newContextImpl = new JBossNamingContext();
     newContextImpl.init(this.poa, this.doPurge, this.noPing);
     // create the oid for the new context and activate it with the naming service POA.
     String oid = new String(this.poa.servant_to_id(this)) + "/ctx" + (++this.childCount);
     this.poa.activate_object_with_id(oid.getBytes(), newContextImpl);
     // add the newly-created context to the cache.
     contextImpls.put(oid, newContextImpl);
     return NamingContextExtHelper.narrow(
         this.poa.create_reference_with_id(
             oid.getBytes(), "IDL:omg.org/CosNaming/NamingContextExt:1.0"));
   } catch (Exception e) {
     log.error("Cannot create CORBA naming context", e);
     return null;
   }
 }
Ejemplo n.º 3
0
  public void bind(NameComponent[] nc, org.omg.CORBA.Object obj)
      throws NotFound, CannotProceed, InvalidName, AlreadyBound {
    if (this.destroyed) throw new CannotProceed();

    if (nc == null || nc.length == 0) throw new InvalidName();

    if (obj == null) throw new org.omg.CORBA.BAD_PARAM();

    Name n = new Name(nc);
    Name ctx = n.ctxName();
    NameComponent nb = n.baseNameComponent();

    if (ctx == null) {
      if (this.names.containsKey(n)) {
        // if the name is still in use, try to ping the object
        org.omg.CORBA.Object ref = (org.omg.CORBA.Object) this.names.get(n);
        if (isDead(ref)) {
          rebind(n.components(), obj);
          return;
        }
        throw new AlreadyBound();
      } else if (this.contexts.containsKey(n)) {
        // if the name is still in use, try to ping the object
        org.omg.CORBA.Object ref = (org.omg.CORBA.Object) this.contexts.get(n);
        if (isDead(ref)) unbind(n.components());
        throw new AlreadyBound();
      }

      if ((this.names.put(n, obj)) != null) throw new CannotProceed(_this(), n.components());

      log.debugf("Bound name: " + n.toString());
    } else {
      NameComponent[] ncx = new NameComponent[] {nb};
      org.omg.CORBA.Object context = this.resolve(ctx.components());

      // try first to call the context implementation object directly.
      String contextOID = this.getObjectOID(context);
      JBossNamingContext jbossContext = (contextOID == null ? null : contextImpls.get(contextOID));
      if (jbossContext != null) jbossContext.bind(ncx, obj);
      else NamingContextExtHelper.narrow(context).bind(ncx, obj);
    }
  }
Ejemplo n.º 4
0
  public void rebind_context(NameComponent[] nc, NamingContext obj)
      throws NotFound, CannotProceed, InvalidName {
    if (this.destroyed) throw new CannotProceed();

    if (nc == null || nc.length == 0) throw new InvalidName();

    if (obj == null) throw new org.omg.CORBA.BAD_PARAM();

    Name n = new Name(nc);
    Name ctx = n.ctxName();
    NameComponent nb = n.baseNameComponent();

    if (ctx == null) {
      // the name is bound, but it is bound to an object - the client should have been using
      // rebind().
      if (this.names.containsKey(n))
        throw new NotFound(NotFoundReason.not_context, new NameComponent[] {nb});

      // try to remove an existing context binding.
      org.omg.CORBA.Object ref = (org.omg.CORBA.Object) this.contexts.remove(n);
      if (ref != null) {
        ref._release();
        // remove the old context from the implementation cache.
        String oid = this.getObjectOID(ref);
        if (oid != null) contextImpls.remove(oid);
      }

      this.contexts.put(n, obj);
      log.debugf("Re-Bound context: " + n.baseNameComponent().id);
    } else {
      // rebind in the correct context
      NameComponent[] ncx = new NameComponent[] {nb};
      org.omg.CORBA.Object context = this.resolve(ctx.components());

      // try first to call the context implementation object directly.
      String contextOID = this.getObjectOID(context);
      JBossNamingContext jbossContext = (contextOID == null ? null : contextImpls.get(contextOID));
      if (jbossContext != null) jbossContext.rebind_context(ncx, obj);
      else NamingContextExtHelper.narrow(context).rebind_context(ncx, obj);
    }
  }
Ejemplo n.º 5
0
  public void unbind(NameComponent[] nc) throws NotFound, CannotProceed, InvalidName {
    if (this.destroyed) throw new CannotProceed();

    if (nc == null || nc.length == 0) throw new InvalidName();

    Name n = new Name(nc);
    Name ctx = n.ctxName();
    NameComponent nb = n.baseNameComponent();

    if (ctx == null) {
      if (this.names.containsKey(n)) {
        org.omg.CORBA.Object ref = (org.omg.CORBA.Object) this.names.remove(n);
        ref._release();
        log.debugf("Unbound: " + n.toString());
      } else if (this.contexts.containsKey(n)) {
        org.omg.CORBA.Object ref = (org.omg.CORBA.Object) this.contexts.remove(n);
        ref._release();
        // remove the context from the implementation cache.
        String oid = this.getObjectOID(ref);
        if (oid != null) contextImpls.remove(oid);

        log.debugf("Unbound: " + n.toString());
      } else {
        if (log.isEnabled(Level.WARN)) log.warnf("Unbind failed for " + n.toString());
        throw new NotFound(NotFoundReason.not_context, n.components());
      }
    } else {
      NameComponent[] ncx = new NameComponent[] {nb};
      org.omg.CORBA.Object context = this.resolve(ctx.components());

      // try first to call the context implementation object directly.
      String contextOID = this.getObjectOID(context);
      JBossNamingContext jbossContext = (contextOID == null ? null : contextImpls.get(contextOID));
      if (jbossContext != null) jbossContext.unbind(ncx);
      else NamingContextExtHelper.narrow(context).unbind(ncx);
    }
  }