Пример #1
0
  /**
   * @param elements
   * @param multiplicities
   * @return
   */
  public TreeReference getChildInstanceRef(Vector elements, Vector multiplicities) {
    if (elements.size() == 0) return null;

    // get reference for target element
    TreeReference ref =
        FormInstance.unpackReference(((IFormElement) elements.lastElement()).getBind()).clone();
    for (int i = 0; i < ref.size(); i++) {
      // There has to be a better way to encapsulate this
      if (ref.getMultiplicity(i) != TreeReference.INDEX_ATTRIBUTE) {
        ref.setMultiplicity(i, 0);
      }
    }

    // fill in multiplicities for repeats along the way
    for (int i = 0; i < elements.size(); i++) {
      IFormElement temp = (IFormElement) elements.elementAt(i);
      if (temp instanceof GroupDef && ((GroupDef) temp).getRepeat()) {
        TreeReference repRef = FormInstance.unpackReference(temp.getBind());
        if (repRef.isParentOf(ref, false)) {
          int repMult = ((Integer) multiplicities.elementAt(i)).intValue();
          ref.setMultiplicity(repRef.size() - 1, repMult);
        } else {
          return null; // question/repeat hierarchy is not consistent
          // with instance instance and bindings
        }
      }
    }

    return ref;
  }
Пример #2
0
  public static QuestionDef findQuestionByRef(TreeReference ref, IFormElement fe) {
    if (fe instanceof FormDef) {
      ref = ref.genericize();
    }

    if (fe instanceof QuestionDef) {
      QuestionDef q = (QuestionDef) fe;
      TreeReference bind = FormInstance.unpackReference(q.getBind());
      return (ref.equals(bind) ? q : null);
    } else {
      for (int i = 0; i < fe.getChildren().size(); i++) {
        QuestionDef ret = findQuestionByRef(ref, fe.getChild(i));
        if (ret != null) return ret;
      }
      return null;
    }
  }