Exemple #1
0
  /**
   * @param index
   * @return
   */
  public TreeReference getChildInstanceRef(FormIndex index) {
    Vector indexes = new Vector();
    Vector multiplicities = new Vector();
    Vector elements = new Vector();

    collapseIndex(index, indexes, multiplicities, elements);
    return getChildInstanceRef(elements, multiplicities);
  }
Exemple #2
0
  /**
   * Dereference the form index and return a Vector of all interstitial nodes (top-level parent
   * first; index target last)
   *
   * <p>Ignore 'new-repeat' node for now; just return/stop at ref to yet-to-be-created repeat node
   * (similar to repeats that already exist)
   *
   * @param index
   * @return
   */
  public Vector explodeIndex(FormIndex index) {
    Vector indexes = new Vector();
    Vector multiplicities = new Vector();
    Vector elements = new Vector();

    collapseIndex(index, indexes, multiplicities, elements);
    return elements;
  }
Exemple #3
0
  /**
   * Deletes the inner-most repeat that this node belongs to and returns the corresponding
   * FormIndex. Behavior is currently undefined if you call this method on a node that is not
   * contained within a repeat.
   *
   * @param index
   * @return
   */
  public FormIndex deleteRepeat(FormIndex index) {
    Vector indexes = new Vector();
    Vector multiplicities = new Vector();
    Vector elements = new Vector();
    collapseIndex(index, indexes, multiplicities, elements);

    // loop backwards through the elements, removing objects from each
    // vector, until we find a repeat
    // TODO: should probably check to make sure size > 0
    for (int i = elements.size() - 1; i >= 0; i--) {
      IFormElement e = (IFormElement) elements.elementAt(i);
      if (e instanceof GroupDef && ((GroupDef) e).getRepeat()) {
        break;
      } else {
        indexes.removeElementAt(i);
        multiplicities.removeElementAt(i);
        elements.removeElementAt(i);
      }
    }

    // build new formIndex which includes everything
    // up to the node we're going to remove
    FormIndex newIndex = buildIndex(indexes, multiplicities, elements);

    TreeReference deleteRef = getChildInstanceRef(newIndex);
    TreeElement deleteElement = instance.resolveReference(deleteRef);
    TreeReference parentRef = deleteRef.getParentRef();
    TreeElement parentElement = instance.resolveReference(parentRef);

    int childMult = deleteElement.getMult();
    parentElement.removeChild(deleteElement);

    // update multiplicities of other child nodes
    for (int i = 0; i < parentElement.getNumChildren(); i++) {
      TreeElement child = parentElement.getChildAt(i);
      if (child.getMult() > childMult) {
        child.setMult(child.getMult() - 1);
      }
    }

    triggerTriggerables(deleteRef);
    return newIndex;
  }
Exemple #4
0
  // repIndex == -1 => next repetition about to be created
  public FormIndex descendIntoRepeat(FormIndex index, int repIndex) {
    int numRepetitions = getNumRepetitions(index);

    Vector indexes = new Vector();
    Vector multiplicities = new Vector();
    Vector elements = new Vector();
    collapseIndex(index, indexes, multiplicities, elements);

    if (repIndex == -1) {
      repIndex = numRepetitions;
    } else {
      if (repIndex < 0 || repIndex >= numRepetitions) {
        throw new RuntimeException("selection exceeds current number of repetitions");
      }
    }

    multiplicities.setElementAt(new Integer(repIndex), multiplicities.size() - 1);

    return buildIndex(indexes, multiplicities, elements);
  }
Exemple #5
0
  public int getNumRepetitions(FormIndex index) {
    Vector indexes = new Vector();
    Vector multiplicities = new Vector();
    Vector elements = new Vector();

    if (!index.isInForm()) {
      throw new RuntimeException("not an in-form index");
    }

    collapseIndex(index, indexes, multiplicities, elements);

    if (!(elements.lastElement() instanceof GroupDef)
        || !((GroupDef) elements.lastElement()).getRepeat()) {
      throw new RuntimeException("current element not a repeat");
    }

    // so painful
    TreeElement templNode = instance.getTemplate(index.getReference());
    TreeReference parentPath = templNode.getParent().getRef().genericize();
    TreeElement parentNode =
        instance.resolveReference(parentPath.contextualize(index.getReference()));
    return parentNode.getChildMultiplicity(templNode.getName());
  }