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
        public static XPathPathExpr fromRef(TreeReference ref_Renamed)
        {
            XPathPathExpr path = new XPathPathExpr();

            path.init_context = (ref_Renamed.Absolute?INIT_CONTEXT_ROOT:INIT_CONTEXT_RELATIVE);
            path.steps        = new XPathStep[ref_Renamed.size()];
            for (int i = 0; i < path.steps.Length; i++)
            {
                if (ref_Renamed.getName(i).Equals(TreeReference.NAME_WILDCARD))
                {
                    path.steps[i] = new XPathStep(XPathStep.AXIS_CHILD, XPathStep.TEST_NAME_WILDCARD).intern();
                }
                else
                {
                    path.steps[i] = new XPathStep(XPathStep.AXIS_CHILD, new XPathQName(ref_Renamed.getName(i))).intern();
                }
            }
            return(path);
        }
Exemplo n.º 3
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));
            }
        }
Exemplo n.º 4
0
        private void  InitBlock()
        {
            if (expr is XPathPathExpr)
            {
                return(((XPathPathExpr)expr).eval(model, evalContext).getReferences());
            }
            else
            {
                throw new FatalException("evalNodeset: must be path expression");
            }

            Set <TreeReference> triggers = new HashSet <TreeReference>();

            getTriggers(expr, triggers, contextRef);
            return(triggers);

            if (x is XPathPathExpr)
            {
                TreeReference ref_Renamed    = ((XPathPathExpr)x).getReference();
                TreeReference contextualized = ref_Renamed;
                if (contextRef != null)
                {
                    contextualized = ref_Renamed.contextualize(contextRef);
                }

                //TODO: It's possible we should just handle this the same way as "genericize". Not entirely clear.
                if (contextualized.hasPredicates())
                {
                    contextualized = contextualized.removePredicates();
                }

                v.add(contextualized);

                for (int i = 0; i < ref_Renamed.size(); i++)
                {
                    if (predicates == null)
                    {
                        continue;
                    }

                    //we can't generate this properly without an absolute reference
                    if (!ref_Renamed.Absolute)
                    {
                        throw new System.ArgumentException("can't get triggers for relative references");
                    }
                    TreeReference predicateContext = ref_Renamed.getSubReference(i);


                    for (XPathExpression predicate: predicates)
                    {
                        getTriggers(predicate, v, predicateContext);
                    }
                }
            }
            else if (x is XPathBinaryOpExpr)
            {
                getTriggers(((XPathBinaryOpExpr)x).a, v, contextRef);
                getTriggers(((XPathBinaryOpExpr)x).b, v, contextRef);
            }
            else if (x is XPathUnaryOpExpr)
            {
                getTriggers(((XPathUnaryOpExpr)x).a, v, contextRef);
            }
            else if (x is XPathFuncExpr)
            {
                XPathFuncExpr fx = (XPathFuncExpr)x;
                for (int i = 0; i < fx.args.Length; i++)
                {
                    getTriggers(fx.args[i], v, contextRef);
                }
            }
            return(expr.pivot(model, evalContext));
        }