public IFormElement getChild(FormIndex index) { IFormElement element = this; while (index != null && index.isInForm()) { element = element.getChild(index.getLocalIndex()); index = index.getNextLevel(); } return element; }
public void collapseIndex( FormIndex index, Vector indexes, Vector multiplicities, Vector elements) { if (!index.isInForm()) { return; } IFormElement element = this; while (index != null) { int i = index.getLocalIndex(); element = element.getChild(i); indexes.addElement(new Integer(i)); multiplicities.addElement( new Integer(index.getInstanceIndex() == -1 ? 0 : index.getInstanceIndex())); elements.addElement(element); index = index.getNextLevel(); } }
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()); }