// // boolean nodeset = forceNodeset; // if (!nodeset) { // //is this a nodeset? it is if the ref contains any unbound multiplicities AND the unbound nodes are repeatable // //the way i'm calculating this sucks; there has got to be an easier way to find out if a node is repeatable // TreeReference repeatTestRef = TreeReference.rootRef(); // for (int i = 0; i < ref.size(); i++) { // repeatTestRef.add(ref.getName(i), ref.getMultiplicity(i)); // if (ref.getMultiplicity(i) == TreeReference.INDEX_UNBOUND) { // if (m.getTemplate(repeatTestRef) != null) { // nodeset = true; // break; // } // } // } // } public static Object getRefValue(FormInstance model, EvaluationContext ec, TreeReference ref_) { if (ec.isConstraint && ref_.Equals(ec.ContextRef)) { //ITEMSET TODO: need to update this; for itemset/copy constraints, need to simulate a whole xml sub-tree here return(unpackValue(ec.candidateValue)); } else { TreeElement node = model.resolveReference(ref_); if (node == null) { //shouldn't happen -- only existent nodes should be in nodeset throw new XPathTypeMismatchException("Node " + ref_.toString() + " does not exist!"); } return(unpackValue(node.isRelevant() ? node.getValue() : null)); } }
public override object eval(FormInstance m, EvaluationContext evalContext) { TreeReference genericRef = getReference(); if (genericRef.isAbsolute() && m.getTemplatePath(genericRef) == null) { throw new XPathTypeMismatchException("Node " + genericRef.toString() + " does not exist!"); } TreeReference ref_ = genericRef.contextualize(evalContext.ContextRef); List <TreeReference> nodesetRefs = m.expandReference(ref_); //to fix conditions based on non-relevant data, filter the nodeset by relevancy for (int i = 0; i < nodesetRefs.Count; i++) { if (!m.resolveReference((TreeReference)nodesetRefs[i]).isRelevant()) { nodesetRefs.RemoveAt(i); i--; } } return(new XPathNodeset(nodesetRefs, m, evalContext)); }
/** * recursively read in a node of the instance, by filling out the template instance * @param e * @param ref * @param in * @param pf * @throws IOException * @throws DeserializationException */ private void readTreeElement(TreeElement e, BinaryReader in_, PrototypeFactory pf) { TreeElement templ = instance.getTemplatePath(e.getRef()); Boolean isGroup = !templ.isLeaf(); if (isGroup) { ArrayList childTypes = new ArrayList(); for (int i = 0; i < templ.getNumChildren(); i++) { String childName = templ.getChildAt(i).getName(); if (!childTypes.Contains(childName)) { childTypes.Add(childName); } } for (int i = 0; i < childTypes.Count; i++) { String childName = (String)childTypes[i]; TreeReference childTemplRef = e.getRef().extendRef(childName, 0); TreeElement childTempl = instance.getTemplatePath(childTemplRef); Boolean repeatable = childTempl.repeatable; int n = ExtUtil.readInt(in_); Boolean relevant = (n > 0); if (!repeatable && n > 1) { throw new DeserializationException("Detected repeated instances of a non-repeatable node"); } if (repeatable) { int mult = e.getChildMultiplicity(childName); for (int j = mult - 1; j >= 0; j--) { e.removeChild(childName, j); } for (int j = 0; j < n; j++) { TreeReference dstRef = e.getRef().extendRef(childName, j); try { instance.copyNode(childTempl, dstRef); } catch (InvalidReferenceException ire) { //If there is an invalid reference, this is a malformed instance, //so we'll throw a Deserialization exception. TreeReference r = ire.InvalidReference; if (r == null) { throw new DeserializationException("Null Reference while attempting to deserialize! " + ire.Message); } else { throw new DeserializationException("Invalid Reference while attemtping to deserialize! Reference: " + r.toString(true) + " | " + ire.Message); } } TreeElement child = e.getChild(childName, j); child.setRelevant(true); readTreeElement(child, in_, pf); } } else { TreeElement child = e.getChild(childName, 0); child.setRelevant(relevant); if (relevant) { readTreeElement(child, in_, pf); } } } } else { e.setValue((IAnswerData)ExtUtil.read(in_, new ExtWrapAnswerData(e.dataType))); } }