Ejemplo n.º 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);
        }
Ejemplo 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));
            }
        }
Ejemplo n.º 3
0
        /// <summary> recursively read in a node of the instance, by filling out the template instance</summary>
        /// <param name="e">
        /// </param>
        /// <param name="ref">
        /// </param>
        /// <param name="in">
        /// </param>
        /// <param name="pf">
        /// </param>
        /// <throws>  IOException </throws>
        /// <throws>  DeserializationException </throws>
        //UPGRADE_TODO: Class 'java.io.DataInputStream' was converted to 'System.IO.BinaryReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioDataInputStream'"
        private void  readTreeElement(TreeElement e, System.IO.BinaryReader in_Renamed, PrototypeFactory pf)
        {
            TreeElement templ   = instance.getTemplatePath(e.Ref);
            bool        isGroup = !templ.Leaf;

            if (isGroup)
            {
                System.Collections.ArrayList childTypes = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
                for (int i = 0; i < templ.NumChildren; i++)
                {
                    System.String childName = templ.getChildAt(i).Name;
                    if (!childTypes.Contains(childName))
                    {
                        childTypes.Add(childName);
                    }
                }

                for (int i = 0; i < childTypes.Count; i++)
                {
                    System.String childName = (System.String)childTypes[i];

                    TreeReference childTemplRef = e.Ref.extendRef(childName, 0);
                    TreeElement   childTempl    = instance.getTemplatePath(childTemplRef);

                    bool repeatable = childTempl.Repeatable;
                    int  n          = ExtUtil.readInt(in_Renamed);

                    bool relevant = (n > 0);
                    if (!repeatable && n > 1)
                    {
                        throw new DeserializationException("Detected repeated instances of a non-repeatable node");
                    }

                    if (repeatable)
                    {
                        int mult = e.getChildMultiplicity(childName);
                        for (int j = mult - 1; j >= 0; j--)
                        {
                            e.removeChild(childName, j);
                        }

                        for (int j = 0; j < n; j++)
                        {
                            TreeReference dstRef = e.Ref.extendRef(childName, j);
                            try
                            {
                                instance.copyNode(childTempl, dstRef);
                            }
                            catch (InvalidReferenceException ire)
                            {
                                //If there is an invalid reference, this is a malformed instance,
                                //so we'll throw a Deserialization exception.
                                TreeReference r = ire.InvalidReference;
                                if (r == null)
                                {
                                    //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                                    throw new DeserializationException("Null Reference while attempting to deserialize! " + ire.Message);
                                }
                                else
                                {
                                    //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                                    throw new DeserializationException("Invalid Reference while attemtping to deserialize! Reference: " + r.toString(true) + " | " + ire.Message);
                                }
                            }

                            TreeElement child = e.getChild(childName, j);
                            child.setRelevant(true);
                            readTreeElement(child, in_Renamed, pf);
                        }
                    }
                    else
                    {
                        TreeElement child = e.getChild(childName, 0);
                        child.setRelevant(relevant);
                        if (relevant)
                        {
                            readTreeElement(child, in_Renamed, pf);
                        }
                    }
                }
            }
            else
            {
                e.Value = (IAnswerData)ExtUtil.read(in_Renamed, new ExtWrapAnswerData(this, e.DataType));
            }
        }