Exemplo n.º 1
0
        /// <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());
                }
            }
        }
Exemplo n.º 2
0
        private void  InitBlock()
        {
            TreeReference ref_Renamed = this.getReference();

            //Either concretely the sentinal, or "."
            if (ref_Renamed.Equals(sentinal) || (ref_Renamed.RefLevel == 0))
            {
                return(sentinal);
            }
            else
            {
                //It's very, very hard to figure out how to pivot predicates. For now, just skip it
                for (int i = 0; i < ref_Renamed.size(); ++i)
                {
                    if (ref_Renamed.getPredicate(i) != null && ref_Renamed.getPredicate(i).size() > 0)
                    {
                        throw new UnpivotableExpressionException("Can't pivot filtered treereferences. Ref: " + ref_Renamed.toString(true) + " has predicates.");
                    }
                }
                return(this.eval(model, evalContext));
            }
        }