Beispiel #1
0
        public override System.Object eval(FormInstance model, EvaluationContext evalContext)
        {
            System.Object aval   = a.eval(model, evalContext);
            System.Object bval   = b.eval(model, evalContext);
            bool          result = false;

            //xpath spec says comparisons only defined for numbers (not defined for strings)
            aval = XPathFuncExpr.toNumeric(aval);
            bval = XPathFuncExpr.toNumeric(bval);

            double fa = ((System.Double)aval);
            double fb = ((System.Double)bval);

            switch (op)
            {
            case LT:  result = fa < fb; break;

            case GT:  result = fa > fb; break;

            case LTE:  result = fa <= fb; break;

            case GTE:  result = fa >= fb; break;
            }

            return(result);
        }
Beispiel #2
0
        public static void  applyDataType(FormInstance dm, System.String path, TreeReference parent, int dataType)
        {
            TreeReference ref_Renamed = childRef(path, parent);

            System.Collections.ArrayList v = new EvaluationContext(dm).expandReference(ref_Renamed);
            for (int i = 0; i < v.Count; i++)
            {
                TreeElement e = dm.resolveReference((TreeReference)v[i]);
                e.DataType = dataType;
            }
        }
Beispiel #3
0
        public override System.Object eval(FormInstance model, EvaluationContext evalContext)
        {
            System.Object aval = XPathFuncExpr.unpack(a.eval(model, evalContext));
            System.Object bval = XPathFuncExpr.unpack(b.eval(model, evalContext));
            bool          eq   = false;

            if (aval is System.Boolean || bval is System.Boolean)
            {
                if (!(aval is System.Boolean))
                {
                    aval = XPathFuncExpr.toBoolean(aval);
                }
                else if (!(bval is System.Boolean))
                {
                    bval = XPathFuncExpr.toBoolean(bval);
                }

                bool ba = ((System.Boolean)aval);
                bool bb = ((System.Boolean)bval);
                eq = (ba == bb);
            }
            else if (aval is System.Double || bval is System.Double)
            {
                if (!(aval is System.Double))
                {
                    aval = XPathFuncExpr.toNumeric(aval);
                }
                else if (!(bval is System.Double))
                {
                    bval = XPathFuncExpr.toNumeric(bval);
                }

                double fa = ((System.Double)aval);
                double fb = ((System.Double)bval);
                eq = System.Math.Abs(fa - fb) < 1.0e-12;
            }
            else
            {
                aval = XPathFuncExpr.toString(aval);
                bval = XPathFuncExpr.toString(bval);
                eq   = (aval.Equals(bval));
            }

            return(equal?eq:!eq);
        }
Beispiel #4
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);
        }
Beispiel #5
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;
         }
     }
 }
Beispiel #6
0
        //
        //	boolean nodeset = forceNodeset;
        //	if (!nodeset) {
        //		//is this a nodeset? it is if the ref contains any unbound multiplicities AND the unbound nodes are repeatable
        //		//the way i'm calculating this sucks; there has got to be an easier way to find out if a node is repeatable
        //		TreeReference repeatTestRef = TreeReference.rootRef();
        //		for (int i = 0; i < ref.size(); i++) {
        //			repeatTestRef.add(ref.getName(i), ref.getMultiplicity(i));
        //			if (ref.getMultiplicity(i) == TreeReference.INDEX_UNBOUND) {
        //				if (m.getTemplate(repeatTestRef) != null) {
        //					nodeset = true;
        //					break;
        //				}
        //			}
        //		}
        //	}

        public static System.Object getRefValue(FormInstance model, EvaluationContext ec, TreeReference ref_Renamed)
        {
            if (ec.isConstraint && ref_Renamed.Equals(ec.ContextRef))
            {
                //ITEMSET TODO: need to update this; for itemset/copy constraints, need to simulate a whole xml sub-tree here
                return(unpackValue(ec.candidateValue));
            }
            else
            {
                TreeElement node = model.resolveReference(ref_Renamed);
                if (node == null)
                {
                    //shouldn't happen -- only existent nodes should be in nodeset
                    throw new XPathTypeMismatchException("Node " + ref_Renamed.ToString() + " does not exist!");
                }

                return(unpackValue(node.isRelevant()?node.Value:null));
            }
        }
Beispiel #7
0
 public virtual System.String getConstraintText(System.String textForm, IAnswerData attemptedValue)
 {
     if (mTreeElement.Constraint == null)
     {
         return(null);
     }
     else
     {
         EvaluationContext ec = new EvaluationContext(form.exprEvalContext, mTreeElement.Ref);
         if (textForm != null)
         {
             ec.OutputTextForm = textForm;
         }
         if (attemptedValue != null)
         {
             ec.isConstraint   = true;
             ec.candidateValue = attemptedValue;
         }
         return(mTreeElement.Constraint.getConstraintMessage(ec, form.MainInstance, textForm));
     }
 }
Beispiel #8
0
        public override System.Object eval(FormInstance model, EvaluationContext evalContext)
        {
            double aval = XPathFuncExpr.toNumeric(a.eval(model, evalContext));
            double bval = XPathFuncExpr.toNumeric(b.eval(model, evalContext));

            double result = 0;

            switch (op)
            {
            case ADD:  result = aval + bval; break;

            case SUBTRACT:  result = aval - bval; break;

            case MULTIPLY:  result = aval * bval; break;

            case DIVIDE:  result = aval / bval; break;

            case MODULO:  result = aval % bval; break;
            }
            return((double)result);
        }
Beispiel #9
0
        public override System.Object eval(FormInstance model, EvaluationContext evalContext)
        {
            bool aval = XPathFuncExpr.toBoolean(a.eval(model, evalContext));

            //short-circuiting
            if ((!aval && op == AND) || (aval && op == OR))
            {
                return(aval);
            }

            bool bval = XPathFuncExpr.toBoolean(b.eval(model, evalContext));

            bool result = false;

            switch (op)
            {
            case AND:  result = aval && bval; break;

            case OR:  result = aval || bval; break;
            }
            return(result);
        }
 public override System.Object eval(FormInstance model, EvaluationContext evalContext)
 {
     return(s);
 }
Beispiel #11
0
        public override System.Object eval(FormInstance model, EvaluationContext evalContext)
        {
            double aval = XPathFuncExpr.toNumeric(a.eval(model, evalContext));

            return((double)(-aval));
        }
Beispiel #12
0
 public override System.Object eval(FormInstance model, EvaluationContext evalContext)
 {
     throw new XPathUnsupportedException("nodeset union operation");
 }
Beispiel #13
0
 public override System.Object eval(FormInstance model, EvaluationContext evalContext)
 {
     throw new XPathUnsupportedException("filter expression");
 }
Beispiel #14
0
        /// <summary> Construct an XPath nodeset.
        ///
        /// </summary>
        /// <param name="nodes">
        /// </param>
        /// <param name="instance">
        /// </param>
        /// <param name="ec">
        /// </param>

        public XPathNodeset(List <TreeReference> nodes, FormInstance instance, EvaluationContext ec)
Beispiel #15
0
        public override XPathNodeset eval(FormInstance m, EvaluationContext ec)
        {
            TreeReference genericRef = getReference();

            TreeReference ref_Renamed;

            if (genericRef.Context == TreeReference.CONTEXT_ORIGINAL)
            {
                ref_Renamed = genericRef.contextualize(ec.OriginalContext);
            }
            else
            {
                ref_Renamed = genericRef.contextualize(ec.ContextRef);
            }

            //We don't necessarily know the model we want to be working with until we've contextualized the
            //node

            //check if this nodeset refers to a non-main instance
            if (ref_Renamed.InstanceName != null && ref_Renamed.Absolute)
            {
                FormInstance nonMain = ec.getInstance(ref_Renamed.InstanceName);
                if (nonMain != null)
                {
                    m = nonMain;
                }
                else
                {
                    throw new XPathMissingInstanceException(ref_Renamed.InstanceName, "Instance referenced by " + ref_Renamed.toString(true) + " does not exist");
                }
            }
            else
            {
                //TODO: We should really stop passing 'm' around and start just getting the right instance from ec
                //at a more central level
                m = ec.MainInstance;

                if (m == null)
                {
                    System.String refStr = ref_Renamed == null?"":ref_Renamed.toString(true);
                    throw new XPathException("Cannot evaluate the reference [" + refStr + "] in the current evaluation context. No default instance has been declared!");
                }
            }

            // regardless of the above, we want to ensure there is a definition
            if (m.getRoot() == null)
            {
                //This instance is _declared_, but doesn't actually have any data in it.
                throw new XPathMissingInstanceException(ref_Renamed.InstanceName, "Instance referenced by " + ref_Renamed.toString(true) + " has not been loaded");
            }

            // this makes no sense...
            //		if (ref.isAbsolute() && m.getTemplatePath(ref) == null) {
            //			Vector<TreeReference> nodesetRefs = new Vector<TreeReference>();
            //			return new XPathNodeset(nodesetRefs, m, ec);
            //		}



            //to fix conditions based on non-relevant data, filter the nodeset by relevancy
            for (int i = 0; i < nodesetRefs.size(); i++)
            {
                if (!m.resolveReference((TreeReference)nodesetRefs.elementAt(i)).isRelevant())
                {
                    nodesetRefs.removeElementAt(i);
                    i--;
                }
            }

            return(new XPathNodeset(nodesetRefs, m, ec));
        }
Beispiel #16
0
 public abstract System.Object eval(FormInstance model, EvaluationContext evalContext);
 public override System.Object eval(FormInstance model, EvaluationContext evalContext)
 {
     return(evalContext.getVariable(id.ToString()));
 }
Beispiel #18
0
 /// <summary> Construct an XPath nodeset.
 ///
 /// </summary>
 /// <param name="nodes">
 /// </param>
 /// <param name="instance">
 /// </param>
 /// <param name="ec">
 /// </param>
 public XPathLazyNodeset(TreeReference unExpandedRef, FormInstance instance, EvaluationContext ec) : base(instance, ec)
 {
     InitBlock();
     this.unExpandedRef = unExpandedRef;
 }
Beispiel #19
0
 public virtual System.Object eval(EvaluationContext evalContext)
 {
     return(this.eval(evalContext.MainInstance, evalContext));
 }
Beispiel #20
0
 public virtual bool eval(FormInstance model, EvaluationContext evalContext)
 {
     return(XPathFuncExpr.toBoolean(evalRaw(model, evalContext)));
 }
Beispiel #21
0
 public final List <Object> pivot(FormInstance model, EvaluationContext evalContext) throws UnpivotableExpressionException
Beispiel #22
0
 public virtual System.String evalReadable(FormInstance model, EvaluationContext evalContext)
 {
     return(XPathFuncExpr.toString(evalRaw(model, evalContext)));
 }
Beispiel #23
0
 public List <TreeReference> evalNodeset(FormInstance model, EvaluationContext evalContext)
Beispiel #24
0
 /// <summary> for lazy evaluation
 ///
 /// </summary>
 /// <param name="instance">
 /// </param>
 /// <param name="ec">
 /// </param>
 protected internal XPathNodeset(FormInstance instance, EvaluationContext ec)
 {
     InitBlock();
     this.instance = instance;
     this.ec       = ec;
 }