コード例 #1
0
        public override void  processAction(FormDef model, TreeReference contextRef)
        {
            //Qualify the reference if necessary
            TreeReference qualifiedReference = contextRef == null?target:target.contextualize(contextRef);

            //For now we only process setValue actions which are within the
            //context if a context is provided. This happens for repeats where
            //insert events should only trigger on the right nodes
            if (contextRef != null)
            {
                //Note: right now we're qualifying then testing parentage to see wheter
                //there was a conflict, but it's not super clear whether this is a perfect
                //strategy
                if (!contextRef.isParentOf(qualifiedReference, false))
                {
                    return;
                }
            }

            //TODO: either the target or the value's node might not exist here, catch and throw
            //reasonably
            EvaluationContext context = new EvaluationContext(model.EvaluationContext, qualifiedReference);

            System.Object result;

            if (explicitValue != null)
            {
                result = explicitValue;
            }
            else
            {
                result = XPathFuncExpr.unpack(value_Renamed.eval(model.MainInstance, context));
            }

            AbstractTreeElement node = context.resolveReference(qualifiedReference);

            if (node == null)
            {
                throw new System.NullReferenceException("Target of TreeReference " + qualifiedReference.toString(true) + " could not be resolved!");
            }
            int         dataType = node.getDataType();
            IAnswerData val      = Recalculate.wrapData(result, dataType);

            model.setValue(val == null?null:AnswerDataFactory.templateByDataType(dataType).cast(val.uncast()), qualifiedReference);
        }
コード例 #2
0
 public virtual System.Object evalRaw(FormInstance model, EvaluationContext evalContext)
 {
     try
     {
         return(XPathFuncExpr.unpack(expr.eval(model, evalContext)));
     }
     catch (XPathUnsupportedException e)
     {
         if (xpath != null)
         {
             throw new XPathUnsupportedException(xpath);
         }
         else
         {
             throw e;
         }
     }
 }
コード例 #3
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));
        }
コード例 #4
0
 public virtual System.String evalReadable(FormInstance model, EvaluationContext evalContext)
 {
     return(XPathFuncExpr.toString(evalRaw(model, evalContext)));
 }
コード例 #5
0
 public virtual bool eval(FormInstance model, EvaluationContext evalContext)
 {
     return(XPathFuncExpr.toBoolean(evalRaw(model, evalContext)));
 }