/// <returns> The value represented by this xpath. Can only be evaluated when this xpath represents exactly one /// reference, or when it represents 0 references after a filtering operation (a reference which _could_ have /// existed, but didn't, rather than a reference which could not represent a real node). /// </returns> public override System.Object unpack() { lock (evaluated) { if (evaluated) { return(base.unpack()); } //this element is the important one. For Basic nodeset evaluations (referring to one node with no //multiplicites) we should be able to do this without doing the expansion //first, see if this treeref is usable without expansion int size = unExpandedRef.size(); bool safe = true;; for (int i = 0; i < size; ++i) { //We can't evaluated any predicates for sure if (unExpandedRef.getPredicate(i) != null) { safe = false; break; } int mult = unExpandedRef.getMultiplicity(i); if (!(mult >= 0 || mult == TreeReference.INDEX_UNBOUND)) { safe = false; break; } } if (!safe) { performEvaluation(); return(base.unpack()); } //TOOD: Evaluate error fallbacks, here. I don't know whether this handles the 0 case //the same way, although invalid multiplicities should be fine. try { //TODO: This doesn't handle templated nodes (repeats which may exist in the future) //figure out if we can roll that in easily. For now the catch handles it return(XPathPathExpr.getRefValue(instance, ec, unExpandedRef)); } catch (XPathException xpe) { //This isn't really a best effort attempt, so if we can, see if evaluating cleany works. performEvaluation(); return(base.unpack()); } } }