/* (non-Javadoc)
   * @see j2meunit.framework.TestCase#setUp()
   */
  protected void setUp() throws Exception {
    super.setUp();

    question = new QuestionDef();

    for (int i = 0; i < 4; i++) {
      question.addSelectChoice(new SelectChoice("", "Selection" + i, "Selection " + i, false));
    }

    one = new Selection("Selection 1");
    one.attachChoice(question);
    two = new Selection("Selection 2");
    two.attachChoice(question);
    three = new Selection("Selection 3");
    three.attachChoice(question);

    firstTwo = new Vector();
    firstTwo.addElement(one);
    firstTwo.addElement(two);

    lastTwo = new Vector();
    lastTwo.addElement(two);
    lastTwo.addElement(three);

    invalid = new Vector();
    invalid.addElement(three);
    invalid.addElement(new Integer(12));
    invalid.addElement(one);
  }
Exemple #2
0
  private void attachControlsToInstanceData(TreeElement node) {
    for (int i = 0; i < node.getNumChildren(); i++) {
      attachControlsToInstanceData(node.getChildAt(i));
    }

    IAnswerData val = node.getValue();
    Vector selections = null;
    if (val instanceof SelectOneData) {
      selections = new Vector();
      selections.addElement(val.getValue());
    } else if (val instanceof SelectMultiData) {
      selections = (Vector) val.getValue();
    }

    if (selections != null) {
      QuestionDef q = findQuestionByRef(node.getRef(), this);
      if (q == null) {
        throw new RuntimeException(
            "FormDef.attachControlsToInstanceData: can't find question to link");
      }

      if (q.getDynamicChoices() != null) {
        // droos: i think we should do something like initializing the itemset here, so that default
        // answers
        // can be linked to the selectchoices. however, there are complications. for example, the
        // itemset might
        // not be ready to be evaluated at form initialization; it may require certain questions to
        // be answered
        // first. e.g., if we evaluate an itemset and it has no choices, the xform engine will throw
        // an error
        // itemset TODO
      }

      for (int i = 0; i < selections.size(); i++) {
        Selection s = (Selection) selections.elementAt(i);
        s.attachChoice(q);
      }
    }
  }