public void setDestRef(QuestionDef q) { destRef = FormInstance.unpackReference(q.Bind).clone(); if (copyMode) { destRef.add(copyRef.getNameLast(), TreeReference.INDEX_UNBOUND); } }
/** * translate an xpath path reference into a TreeReference * TreeReferences only support a subset of true xpath paths; restrictions are: * simple child name tests 'child::name', '.', and '..' allowed only * no predicates * all '..' steps must come before anything else */ public TreeReference getReference(Boolean allowPredicates) { TreeReference ref_ = new TreeReference(); Boolean parentsAllowed; switch (init_context) { case XPathPathExpr.INIT_CONTEXT_ROOT: ref_.setRefLevel(TreeReference.REF_ABSOLUTE); parentsAllowed = false; break; case XPathPathExpr.INIT_CONTEXT_RELATIVE: ref_.setRefLevel(0); parentsAllowed = true; break; default: throw new XPathUnsupportedException("filter expression"); } for (int i = 0; i < steps.Length; i++) { XPathStep step = steps[i]; if (!allowPredicates && step.predicates.Length > 0) { throw new XPathUnsupportedException("predicates"); } if (step.axis == XPathStep.AXIS_SELF) { if (step.test != XPathStep.TEST_TYPE_NODE) { throw new XPathUnsupportedException("step other than 'child::name', '.', '..'"); } } else if (step.axis == XPathStep.AXIS_PARENT) { if (!parentsAllowed || step.test != XPathStep.TEST_TYPE_NODE) { throw new XPathUnsupportedException("step other than 'child::name', '.', '..'"); } else { ref_.incrementRefLevel(); } } else if (step.axis == XPathStep.AXIS_ATTRIBUTE) { if (step.test == XPathStep.TEST_NAME) { ref_.add(step.name.ToString(), TreeReference.INDEX_ATTRIBUTE); parentsAllowed = false; //TODO: Can you step back from an attribute, or should this always be //the last step? } else { throw new XPathUnsupportedException("attribute step other than 'attribute::name"); } } else if (step.axis == XPathStep.AXIS_CHILD) { if (step.test == XPathStep.TEST_NAME) { ref_.add(step.name.ToString(), TreeReference.INDEX_UNBOUND); parentsAllowed = false; } else if (step.test == XPathStep.TEST_NAME_WILDCARD) { ref_.add(TreeReference.NAME_WILDCARD, TreeReference.INDEX_UNBOUND); parentsAllowed = false; } else { throw new XPathUnsupportedException("step other than 'child::name', '.', '..'"); } } else { throw new XPathUnsupportedException("step other than 'child::name', '.', '..'"); } } return(ref_); }