예제 #1
0
  public void list(int how_many, BindingListHolder bl, BindingIteratorHolder bi) {
    if (this.destroyed) return;

    Binding[] result;
    this.cleanup();

    int size = how_many();

    Iterator<Name> names = this.names.keySet().iterator();
    Iterator<Name> contexts = this.contexts.keySet().iterator();

    if (how_many < size) {
      // counter for copies
      int how_many_ctr = how_many;

      // set up an array with "how_many" bindings
      result = new Binding[how_many];
      for (; names.hasNext() && how_many_ctr > 0; how_many_ctr--)
        result[how_many_ctr - 1] = new Binding((names.next()).components(), BindingType.nobject);

      for (; contexts.hasNext() && how_many_ctr > 0; how_many_ctr--)
        result[how_many_ctr - 1] =
            new Binding((contexts.next()).components(), BindingType.ncontext);

      // create a new BindingIterator for the remaining arrays
      size -= how_many;
      Binding[] rest = new Binding[size];
      for (; names.hasNext() && size > 0; size--)
        rest[size - 1] = new Binding((names.next()).components(), BindingType.nobject);

      for (; contexts.hasNext() && size > 0; size--)
        rest[size - 1] = new Binding((contexts.next()).components(), BindingType.ncontext);

      org.omg.CORBA.Object o;
      try {
        // Iterators are activated with the RootPOA (transient)
        byte[] oid = rootPoa.activate_object(new BindingIteratorImpl(rest));
        o = rootPoa.id_to_reference(oid);
      } catch (Exception e) {
        log.error("unexpected exception", e);
        throw new INTERNAL(e.toString());
      }

      bi.value = BindingIteratorHelper.narrow(o);
    } else {
      result = new Binding[size];
      for (; names.hasNext() && size > 0; size--)
        result[size - 1] = new Binding((names.next()).components(), BindingType.nobject);

      for (; contexts.hasNext() && size > 0; size--)
        result[size - 1] = new Binding((contexts.next()).components(), BindingType.ncontext);
    }

    bl.value = result;
  }