Beispiel #1
0
 public virtual IDataPointer[] retrieveExternalDataPointer(IAnswerData data)
 {
     System.Collections.IEnumerator en = additionalSerializers.GetEnumerator();
     //UPGRADE_TODO: Method 'java.util.Enumeration.hasMoreElements' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationhasMoreElements'"
     while (en.MoveNext())
     {
         //UPGRADE_TODO: Method 'java.util.Enumeration.nextElement' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationnextElement'"
         IAnswerDataSerializer serializer = (IAnswerDataSerializer)en.Current;
         System.Boolean        contains   = serializer.containsExternalData(data);
         //UPGRADE_TODO: The 'System.Boolean' structure does not have an equivalent to NULL. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1291'"
         if (contains != null)
         {
             return(serializer.retrieveExternalDataPointer(data));
         }
     }
     if (data is PointerAnswerData)
     {
         IDataPointer[] pointer = new IDataPointer[1];
         pointer[0] = (IDataPointer)((PointerAnswerData)data).Value;
         return(pointer);
     }
     else if (data is MultiPointerAnswerData)
     {
         return((IDataPointer[])((MultiPointerAnswerData)data).Value);
     }
     //This shouldn't have been called.
     return(null);
 }
Beispiel #2
0
        /// <summary> saveAnswer attempts to save the current answer into the data model
        /// without doing any constraint checking. Only use this if you know what
        /// you're doing. For normal form filling you should always use
        /// answerQuestion or answerCurrentQuestion.
        ///
        /// </summary>
        /// <param name="index">
        /// </param>
        /// <param name="data">
        /// </param>
        /// <returns> true if saved successfully, false otherwise.
        /// </returns>
        public virtual bool saveAnswer(FormIndex index, IAnswerData data)
        {
            if (model.getEvent(index) != FormEntryController.EVENT_QUESTION)
            {
                throw new System.SystemException("Non-Question object at the form index.");
            }
            TreeElement element = model.getTreeElement(index);

            return(commitAnswer(element, index, data));
        }
Beispiel #3
0
        private void saveProperty(System.String propName, TreeElement node)
        {
            IAnswerData answer = node.getValue();

            System.String value_Renamed = (answer == null ? null : answer.DisplayText);
            if (propName != null && propName.Length > 0 && value_Renamed != null && value_Renamed.Length > 0)
            {
                PropertyManager._().setProperty(propName, value_Renamed);
            }
        }
Beispiel #4
0
 public virtual bool canSerialize(IAnswerData data)
 {
     if (data is StringData || data is DateData || data is TimeData || data is SelectMultiData || data is SelectOneData || data is IntegerData || data is DecimalData || data is PointerAnswerData || data is MultiPointerAnswerData || data is GeoPointData || data is GeoTraceData || data is GeoShapeData || data is LongData || data is DateTimeData || data is UncastData)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #5
0
 /// <summary> commitAnswer actually saves the data into the datamodel.
 ///
 /// </summary>
 /// <param name="element">
 /// </param>
 /// <param name="index">
 /// </param>
 /// <param name="data">
 /// </param>
 /// <returns> true if saved successfully, false otherwise
 /// </returns>
 private bool commitAnswer(TreeElement element, FormIndex index, IAnswerData data)
 {
     if (data != null || element.Value != null)
     {
         // we should check if the data to be saved is already the same as
         // the data in the model, but we can't (no IAnswerData.equals())
         model.Form.setValue(data, index.Reference, element);
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #6
0
        /// <summary> Attempts to save the answer at the specified FormIndex into the
        /// datamodel.
        ///
        /// </summary>
        /// <param name="index">
        /// </param>
        /// <param name="data">
        /// </param>
        /// <returns> OK if save was successful, error if a constraint was violated.
        /// </returns>
        public virtual int answerQuestion(FormIndex index, IAnswerData data)
        {
            QuestionDef q = model.getQuestionPrompt(index).Question;

            if (model.getEvent(index) != FormEntryController.EVENT_QUESTION)
            {
                throw new System.SystemException("Non-Question object at the form index.");
            }
            TreeElement element         = model.getTreeElement(index);
            bool        complexQuestion = q.Complex;

            bool hasConstraints = false;

            if (element.Required && data == null)
            {
                return(ANSWER_REQUIRED_BUT_EMPTY);
            }
            else if (!complexQuestion && !model.Form.evaluateConstraint(index.Reference, data))
            {
                return(ANSWER_CONSTRAINT_VIOLATED);
            }
            else if (!complexQuestion)
            {
                commitAnswer(element, index, data);
                return(ANSWER_OK);
            }
            else if (complexQuestion && hasConstraints)
            {
                //TODO: itemsets: don't currently evaluate constraints for itemset/copy -- haven't figured out how handle it yet
                throw new System.SystemException("Itemsets do not currently evaluate constraints. Your constraint will not work, please remove it before proceeding.");
            }
            else
            {
                try
                {
                    model.Form.copyItemsetAnswer(q, element, data);
                }
                catch (InvalidReferenceException ire)
                {
                    SupportClass.WriteStackTrace(ire, Console.Error);
                    //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 System.SystemException("Invalid reference while copying itemset answer: " + ire.Message);
                }
                return(ANSWER_OK);
            }
        }
Beispiel #7
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 #8
0
        public static System.Object getValue(System.String xpath, TreeReference context, FormInstance tree)
        {
            TreeElement node = tree.resolveReference(ref_Renamed(xpath).contextualize(context));

            if (node == null)
            {
                throw new System.SystemException("Could not find node [" + xpath + "] when parsing saved instance!");
            }

            if (node.isRelevant())
            {
                IAnswerData val = node.getValue();
                return(val == null ? null : val.Value);
            }
            else
            {
                return(null);
            }
        }
Beispiel #9
0
 public virtual System.Object serializeAnswerData(IAnswerData data, int dataType)
 {
     // First, we want to go through the additional serializers, as they should
     // take priority to the default serializations
     System.Collections.IEnumerator en = additionalSerializers.GetEnumerator();
     //UPGRADE_TODO: Method 'java.util.Enumeration.hasMoreElements' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationhasMoreElements'"
     while (en.MoveNext())
     {
         //UPGRADE_TODO: Method 'java.util.Enumeration.nextElement' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationnextElement'"
         IAnswerDataSerializer serializer = (IAnswerDataSerializer)en.Current;
         if (serializer.canSerialize(data))
         {
             return(serializer.serializeAnswerData(data, dataType));
         }
     }
     //Defaults
     System.Object result = serializeAnswerData(data);
     return(result);
 }
Beispiel #10
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 #11
0
 /// <summary> For the current index: Checks whether the index represents a node which
 /// should exist given a non-interactive repeat, along with a count for that
 /// repeat which is beneath the dynamic level specified.
 ///
 /// If this index does represent such a node, the new model for the repeat is
 /// created behind the scenes and the index for the initial question is
 /// returned.
 ///
 /// Note: This method will not prevent the addition of new repeat elements in
 /// the interface, it will merely use the xforms repeat hint to create new
 /// nodes that are assumed to exist
 ///
 /// </summary>
 /// <param name="index">The index to be evaluated as to whether the underlying model is
 /// hinted to exist
 /// </param>
 private void  createModelIfNecessary(FormIndex index)
 {
     if (index.InForm)
     {
         IFormElement e = Form.getChild(index);
         if (e is GroupDef)
         {
             GroupDef g = (GroupDef)e;
             if (g.Repeat && g.CountReference != null)
             {
                 // Lu Gram: repeat count XPath needs to be contextualized for nested repeat groups
                 TreeReference countRef       = FormInstance.unpackReference(g.CountReference);
                 TreeReference contextualized = countRef.contextualize(index.Reference);
                 IAnswerData   count          = Form.MainInstance.resolveReference(contextualized).getValue();
                 if (count != null)
                 {
                     long          fullcount   = ((System.Int32)count.Value);
                     TreeReference ref_Renamed = Form.getChildInstanceRef(index);
                     TreeElement   element     = Form.MainInstance.resolveReference(ref_Renamed);
                     if (element == null)
                     {
                         if (index.getTerminal().InstanceIndex < fullcount)
                         {
                             try
                             {
                                 Form.createNewRepeat(index);
                             }
                             catch (InvalidReferenceException ire)
                             {
                                 SupportClass.WriteStackTrace(ire, Console.Error);
                                 //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 System.SystemException("Invalid Reference while creting new repeat!" + ire.Message);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Beispiel #12
0
        /// <summary>Copy Constructor *</summary>
        private EvaluationContext(EvaluationContext base_Renamed)
        {
            InitBlock();
            //TODO: These should be deep, not shallow
            this.functionHandlers = base_Renamed.functionHandlers;
            this.formInstances    = base_Renamed.formInstances;
            this.variables        = base_Renamed.variables;

            this.contextNode = base_Renamed.contextNode;
            this.instance    = base_Renamed.instance;

            this.isConstraint    = base_Renamed.isConstraint;
            this.candidateValue  = base_Renamed.candidateValue;
            this.isCheckAddChild = base_Renamed.isCheckAddChild;

            this.outputTextForm = base_Renamed.outputTextForm;
            this.original       = base_Renamed.original;

            //Hrm....... not sure about this one. this only happens after a rescoping,
            //and is fixed on the context. Anything that changes the context should
            //invalidate this
            this.currentContextPosition = base_Renamed.currentContextPosition;
        }
Beispiel #13
0
 /*
  * (non-Javadoc)
  * @see org.javarosa.core.model.IAnswerDataSerializer#containsExternalData(org.javarosa.core.model.data.IAnswerData)
  */
 public virtual System.Boolean containsExternalData(IAnswerData data)
 {
     //First check for registered serializers to identify whether
     //they override this one.
     System.Collections.IEnumerator en = additionalSerializers.GetEnumerator();
     //UPGRADE_TODO: Method 'java.util.Enumeration.hasMoreElements' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationhasMoreElements'"
     while (en.MoveNext())
     {
         //UPGRADE_TODO: Method 'java.util.Enumeration.nextElement' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationnextElement'"
         IAnswerDataSerializer serializer = (IAnswerDataSerializer)en.Current;
         System.Boolean        contains   = serializer.containsExternalData(data);
         //UPGRADE_TODO: The 'System.Boolean' structure does not have an equivalent to NULL. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1291'"
         if (contains != null)
         {
             return(contains);
         }
     }
     if (data is PointerAnswerData || data is MultiPointerAnswerData)
     {
         return(true);
     }
     return(false);
 }
Beispiel #14
0
 public ExtWrapAnswerData(CompactInstanceWrapper enclosingInstance, int dataType, IAnswerData val)
 {
     InitBlock(enclosingInstance);
     this.val      = val;
     this.dataType = dataType;
 }
Beispiel #15
0
 public static System.Object unpackValue(IAnswerData val)
 {
     if (val == null)
     {
         return("");
     }
     else if (val is UncastData)
     {
         return(val.Value);
     }
     else if (val is IntegerData)
     {
         return((double)((System.Int32)val.Value));
     }
     else if (val is LongData)
     {
         return((double)((System.Int64)val.Value));
     }
     else if (val is DecimalData)
     {
         return(val.Value);
     }
     else if (val is StringData)
     {
         return(val.Value);
     }
     else if (val is SelectOneData)
     {
         return(((Selection)val.Value).Value);
     }
     else if (val is SelectMultiData)
     {
         return((new XFormAnswerDataSerializer()).serializeAnswerData(val));
     }
     else if (val is DateData)
     {
         return(val.Value);
     }
     else if (val is BooleanData)
     {
         return(val.Value);
     }
     else if (val is GeoPointData)
     {
         // we have no access fns that interact with double[4] arrays (the getValue() data type)...
         return(val.DisplayText);
     }
     else if (val is GeoShapeData)
     {
         // we have no access fns that interact with GeoShape objects (the getValue() data type)...
         return(val.DisplayText);
     }
     else if (val is GeoTraceData)
     {
         // we have no access fns that interact with GeoTrace objects (the getValue() data type)...
         return(val.DisplayText);
     }
     else
     {
         System.Console.Out.WriteLine("warning: unrecognized data type in xpath expr: " + val.GetType().FullName);
         return(val.Value);                //is this a good idea?
     }
 }
Beispiel #16
0
 public virtual System.String serializeData(IAnswerData data)
 {
     return((System.String)(new XFormAnswerDataSerializer().serializeAnswerData(data)));
 }
Beispiel #17
0
 /// <summary> Attempts to save answer at the current FormIndex into the datamodel.
 ///
 /// </summary>
 /// <param name="data">
 /// </param>
 /// <returns>
 /// </returns>
 public virtual int answerQuestion(IAnswerData data)
 {
     return(answerQuestion(model.FormIndex, data));
 }
Beispiel #18
0
 public virtual System.String getConstraintText(IAnswerData attemptedValue)
 {
     return(getConstraintText(null, attemptedValue));
 }
Beispiel #19
0
 /// <summary> saveAnswer attempts to save the current answer into the data model
 /// without doing any constraint checking. Only use this if you know what
 /// you're doing. For normal form filling you should always use
 /// answerQuestion().
 ///
 /// </summary>
 /// <param name="index">
 /// </param>
 /// <param name="data">
 /// </param>
 /// <returns> true if saved successfully, false otherwise.
 /// </returns>
 public virtual bool saveAnswer(IAnswerData data)
 {
     return(saveAnswer(model.FormIndex, data));
 }
Beispiel #20
0
        public virtual System.Object serializeAnswerData(IAnswerData data)
        {
            if (data is StringData)
            {
                return(serializeAnswerData((StringData)data));
            }
            else if (data is SelectMultiData)
            {
                return(serializeAnswerData((SelectMultiData)data));
            }
            else if (data is SelectOneData)
            {
                return(serializeAnswerData((SelectOneData)data));
            }
            else if (data is IntegerData)
            {
                return(serializeAnswerData((IntegerData)data));
            }
            else if (data is LongData)
            {
                return(serializeAnswerData((LongData)data));
            }
            else if (data is DecimalData)
            {
                return(serializeAnswerData((DecimalData)data));
            }
            else if (data is DateData)
            {
                return(serializeAnswerData((DateData)data));
            }
            else if (data is TimeData)
            {
                return(serializeAnswerData((TimeData)data));
            }
            else if (data is PointerAnswerData)
            {
                return(serializeAnswerData((PointerAnswerData)data));
            }
            else if (data is MultiPointerAnswerData)
            {
                return(serializeAnswerData((MultiPointerAnswerData)data));
            }
            else if (data is GeoShapeData)
            {
                return(serializeAnswerData((GeoShapeData)data));
            }
            else if (data is GeoTraceData)
            {
                return(serializeAnswerData((GeoTraceData)data));
            }
            else if (data is GeoPointData)
            {
                return(serializeAnswerData((GeoPointData)data));
            }
            else if (data is DateTimeData)
            {
                return(serializeAnswerData((DateTimeData)data));
            }
            else if (data is BooleanData)
            {
                return(serializeAnswerData((BooleanData)data));
            }
            else if (data is UncastData)
            {
                return(serializeAnswerData((UncastData)data));
            }

            return(null);
        }