private EvaluationContext rescope(TreeReference treeRef, int currentContextPosition) { EvaluationContext ec = new EvaluationContext(this, treeRef); // broken: ec.currentContextPosition = currentContextPosition; //If there was no original context position, we'll want to set the next original //context to be this rescoping (which would be the backup original one). if (this.original != null) { ec.OriginalContext = this.OriginalContext; } else { //Check to see if we have a context, if not, the treeRef is the original declared //nodeset. if (TreeReference.rootRef().Equals(this.ContextRef)) { ec.OriginalContext = treeRef; } else { //If we do have a legit context, use it! ec.OriginalContext = this.ContextRef; } } return(ec); }
public virtual void addTarget(TreeReference target) { if (targets.indexOf(target) == - 1) { targets.addElement(target); } }
/* * (non-Javadoc) * @see org.javarosa.core.model.utils.ITreeVisitor#visit(org.javarosa.core.model.DataModelTree) */ public virtual void serialize(DataInstance instance, TreeReference base_Renamed) { //TODO: Namespaces? AbstractTreeElement root; if (base_Renamed == null) { root = instance.getRoot(); } else { root = instance.resolveReference(base_Renamed); } //write root serializer.startTag(root.getNamespace(), root.getName()); for (int i = 0; i < root.getNumChildren(); i++) { //write children AbstractTreeElement childAt = root.getChildAt(i); serializeNode(childAt); } //end root serializer.endTag(root.getNamespace(), root.getName()); serializer.flush(); }
public virtual IDataPayload createSerializedPayload(FormInstance model, IDataReference ref_Renamed) { init(); rootRef = org.javarosa.core.model.instance.FormInstance.unpackReference(ref_Renamed); if (this.serializer == null) { this.AnswerDataSerializer = new XFormAnswerDataSerializer(); } model.accept(this); if (theXmlDoc != null) { //TODO: Did this strip necessary data? sbyte[] form = XFormSerializer.getUtfBytes(theXmlDoc); if (dataPointers.Count == 0) { return(new ByteArrayPayload(form, null, org.javarosa.core.services.transport.payload.IDataPayload_Fields.PAYLOAD_TYPE_XML)); } MultiMessagePayload payload = new MultiMessagePayload(); payload.addPayload(new ByteArrayPayload(form, "xml_submission_file", org.javarosa.core.services.transport.payload.IDataPayload_Fields.PAYLOAD_TYPE_XML)); System.Collections.IEnumerator en = dataPointers.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'" IDataPointer pointer = (IDataPointer)en.Current; payload.addPayload(new DataPointerPayload(pointer)); } return(payload); } else { return(null); } }
private bool setRepeatNextMultiplicity(System.Collections.ArrayList elements, System.Collections.ArrayList multiplicities) { // find out if node is repeatable TreeReference nodeRef = form.getChildInstanceRef(elements, multiplicities); TreeElement node = form.MainInstance.resolveReference(nodeRef); if (node == null || node.Repeatable) { // node == null if there are no // instances of the repeat int mult; if (node == null) { mult = 0; // no repeats; next is 0 } else { System.String name = node.Name; TreeElement parentNode = form.MainInstance.resolveReference(nodeRef.ParentRef); mult = parentNode.getChildMultiplicity(name); } multiplicities[multiplicities.Count - 1] = (System.Int32)(repeatStructure == REPEAT_STRUCTURE_NON_LINEAR?TreeReference.INDEX_REPEAT_JUNCTURE:mult); return(true); } else { return(false); } }
public virtual void assignRefs(FormDef f) { FormIndex cur = this; List <Integer> indexes = new List <Integer>(); List <Integer> multiplicities = new List <Integer>(); List <IFormElement> elements = new List <IFormElement>(); f.collapseIndex(this, indexes, multiplicities, elements); List <Integer> curMults = new List <Integer>(); List <IFormElement> curElems = new List <IFormElement>(); int i = 0; while (cur != null) { curMults.addElement(multiplicities.elementAt(i)); curElems.addElement(elements.elementAt(i)); TreeReference ref_Renamed = f.getChildInstanceRef(curElems, curMults); cur.reference = ref_Renamed; cur = cur.NextLevel; i++; } }
public static void templateChild(FormInstance dm, System.String prefixPath, TreeReference parent, Restorable r) { TreeReference childRef = (prefixPath == null ? parent : RestoreUtils.childRef(prefixPath, parent)); childRef = org.javarosa.core.model.util.restorable.RestoreUtils.childRef(r.RestorableType, childRef); templateData(r, dm, childRef); }
public Triggerable(IConditionExpr expr, TreeReference contextRef) { InitBlock(); this.expr = expr; this.contextRef = contextRef; this.originalContextRef = contextRef; this.targets = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); }
public virtual void setDestRef(QuestionDef q) { destRef = FormInstance.unpackReference(q.Bind).Clone(); if (copyMode) { destRef.add(copyRef.NameLast, TreeReference.INDEX_UNBOUND); } }
//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'" public virtual void readExternal(System.IO.BinaryReader in_Renamed, PrototypeFactory pf) { expr = (IConditionExpr) ExtUtil.read(in_Renamed, new ExtWrapTagged(), pf); contextRef = (TreeReference) ExtUtil.read(in_Renamed, typeof(TreeReference), pf); originalContextRef = (TreeReference) ExtUtil.read(in_Renamed, typeof(TreeReference), pf); targets =(List< TreeReference >) ExtUtil.read(in, new ExtWrapList(TreeReference. }
//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'" public override void readExternal(System.IO.BinaryReader in_Renamed, PrototypeFactory pf) { target = (TreeReference)ExtUtil.read(in_Renamed, typeof(TreeReference), pf); explicitValue = ExtUtil.nullIfEmpty(ExtUtil.readString(in_Renamed)); if (explicitValue == null) { value_Renamed = (XPathExpression)ExtUtil.read(in_Renamed, new ExtWrapTagged(), pf); } }
public static TreeReference absRef(System.String refStr, FormInstance dm) { TreeReference ref_ = ref_Renamed(refStr); if (!ref_.isAbsolute()) { ref_ = ref_.parent(topRef(dm)); } return(ref_); }
public virtual TreeElement resolveReference(TreeReference qualifiedRef) { FormInstance instance = this.MainInstance; if (qualifiedRef.InstanceName != null) { instance = this.getInstance(qualifiedRef.InstanceName); } return(instance.resolveReference(qualifiedRef)); }
public static void applyDataType(FormInstance dm, System.String path, TreeReference parent, int dataType) { TreeReference ref_ = childRef(path, parent); List <TreeReference> v = dm.expandReference(ref_); for (int i = 0; i < v.Count; i++) { TreeElement e = dm.resolveReference((TreeReference)v[i]); e.dataType = dataType; } }
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; } }
//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'" public virtual void readExternal(System.IO.BinaryReader in_Renamed, PrototypeFactory pf) { nodesetRef = (TreeReference)ExtUtil.read(in_Renamed, typeof(TreeReference), pf); nodesetExpr = (IConditionExpr)ExtUtil.read(in_Renamed, new ExtWrapTagged(), pf); contextRef = (TreeReference)ExtUtil.read(in_Renamed, typeof(TreeReference), pf); labelRef = (TreeReference)ExtUtil.read(in_Renamed, typeof(TreeReference), pf); labelExpr = (IConditionExpr)ExtUtil.read(in_Renamed, new ExtWrapTagged(), pf); valueRef = (TreeReference)ExtUtil.read(in_Renamed, new ExtWrapNullable(typeof(TreeReference)), pf); valueExpr = (IConditionExpr)ExtUtil.read(in_Renamed, new ExtWrapNullable(new ExtWrapTagged()), pf); copyRef = (TreeReference)ExtUtil.read(in_Renamed, new ExtWrapNullable(typeof(TreeReference)), pf); labelIsItext = ExtUtil.readBool(in_Renamed); copyMode = ExtUtil.readBool(in_Renamed); }
public static void templateData(Restorable r, FormInstance dm, TreeReference parent) { if (parent == null) { parent = topRef(dm); applyDataType(dm, "timestamp", parent, typeof(System.DateTime)); } if (r is Persistable) { applyDataType(dm, RECORD_ID_TAG, parent, typeof(System.Int32)); } r.templateData(dm, parent); }
/// <summary> Determine if the current FormIndex is relevant. Only relevant indexes /// should be returned when filling out a form. /// /// </summary> /// <param name="index"> /// </param> /// <returns> true if current element at FormIndex is relevant /// </returns> public virtual bool isIndexRelevant(FormIndex index) { TreeReference ref_Renamed = form.getChildInstanceRef(index); bool isAskNewRepeat = (getEvent(index) == FormEntryController.EVENT_PROMPT_NEW_REPEAT); bool isRepeatJuncture = (getEvent(index) == FormEntryController.EVENT_REPEAT_JUNCTURE); bool relevant; if (isAskNewRepeat) { relevant = form.isRepeatRelevant(ref_Renamed) && form.canCreateRepeat(ref_Renamed, index); //repeat junctures are still relevant if no new repeat can be created; that option //is simply missing from the menu } else if (isRepeatJuncture) { relevant = form.isRepeatRelevant(ref_Renamed); } else { TreeElement node = form.MainInstance.resolveReference(ref_Renamed); relevant = node.isRelevant(); // check instance flag first } if (relevant) { // if instance flag/condition says relevant, we still // have to check the <group>/<repeat> hierarchy FormIndex ancestorIndex = index; while (!ancestorIndex.isTerminal()) { // This should be safe now that the TreeReference is contained // in the ancestor index itself TreeElement ancestorNode = form.MainInstance.resolveReference(ancestorIndex.LocalReference); if (!ancestorNode.isRelevant()) { relevant = false; break; } ancestorIndex = ancestorIndex.NextLevel; } } return(relevant); }
public static void addData(FormInstance dm, System.String xpath, System.Object data, int dataType) { if (data == null) { dataType = -1; } IAnswerData val; switch (dataType) { case -1: val = null; break; case Constants.DATATYPE_TEXT: val = new StringData((System.String)data); break; case Constants.DATATYPE_INTEGER: //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'" val = new IntegerData(ref new System.Int32[] { (System.Int32)data }[0]); break; case Constants.DATATYPE_LONG: //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'" val = new LongData(ref new System.Int64[] { (System.Int64)data }[0]); break; case Constants.DATATYPE_DECIMAL: //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'" val = new DecimalData(ref new System.Double[] { (System.Double)data }[0]); break; case Constants.DATATYPE_BOOLEAN: val = new StringData(((System.Boolean)data) ? "t" : "f"); break; case Constants.DATATYPE_DATE: //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'" val = new DateData(ref new System.DateTime[] { (System.DateTime)data }[0]); break; case Constants.DATATYPE_DATE_TIME: //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'" val = new DateTimeData(ref new System.DateTime[] { (System.DateTime)data }[0]); break; case Constants.DATATYPE_TIME: //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'" val = new TimeData(ref new System.DateTime[] { (System.DateTime)data }[0]); break; case Constants.DATATYPE_CHOICE_LIST: val = (SelectMultiData)data; break; default: throw new System.ArgumentException("Don't know how to handle data type [" + dataType + "]"); } TreeReference ref_Renamed = absRef(xpath, dm); if (dm.addNode(ref_Renamed, val, dataType) == null) { throw new System.SystemException("error setting value during object backup [" + xpath + "]"); } }
/// <summary> Constructs an index which references an element past the level of /// specificity of the current context, founded by the currentLevel /// index. /// (currentLevel, (nextLevel...)) /// </summary> public FormIndex(FormIndex nextLevel, FormIndex currentLevel) { if (currentLevel == null) { this.nextLevel = nextLevel.nextLevel; this.localIndex = nextLevel.localIndex; this.instanceIndex = nextLevel.instanceIndex; this.reference = nextLevel.reference; } else { this.nextLevel = nextLevel; this.localIndex = currentLevel.LocalIndex; this.instanceIndex = currentLevel.InstanceIndex; this.reference = currentLevel.reference; } }
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); }
public static void mergeDataModel(FormInstance parent, FormInstance child, TreeReference parentRef) { TreeElement parentNode = parent.resolveReference(parentRef); //ugly if (parentNode == null) { parentRef = parent.addNode(parentRef); parentNode = parent.resolveReference(parentRef); } TreeElement childNode = child.getRoot(); int mult = parentNode.getChildMultiplicity(childNode.getName()); childNode.setMult(mult); parentNode.addChild(childNode); }
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); }
/* * (non-Javadoc) * @see org.javarosa.core.model.utils.IInstanceSerializingVisitor#serializeDataModel(org.javarosa.core.model.IFormDataModel) */ public virtual sbyte[] serializeInstance(FormInstance model, IDataReference ref_Renamed) { init(); rootRef = org.javarosa.core.model.instance.FormInstance.unpackReference(ref_Renamed); if (this.serializer == null) { this.AnswerDataSerializer = new XFormAnswerDataSerializer(); } model.accept(this); if (theXmlDoc != null) { return(XFormSerializer.getUtfBytes(theXmlDoc)); } else { return(null); } }
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); } }
public virtual IDataPayload createSerializedPayload(FormInstance model, IDataReference ref_Renamed) { init(); rootRef = org.javarosa.core.model.instance.FormInstance.unpackReference(ref_Renamed); if (this.serializer == null) { this.AnswerDataSerializer = new XFormAnswerDataSerializer(); } model.accept(this); if (theSmsStr != null) { //UPGRADE_TODO: Method 'java.lang.String.getBytes' was converted to 'System.Text.Encoding.GetEncoding(string).GetBytes(string)' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javalangStringgetBytes_javalangString'" sbyte[] form = SupportClass.ToSByteArray(System.Text.Encoding.GetEncoding("UTF-16").GetBytes(theSmsStr)); return(new ByteArrayPayload(form, null, org.javarosa.core.services.transport.payload.IDataPayload_Fields.PAYLOAD_TYPE_SMS)); } else { return(null); } }
/* * (non-Javadoc) * @see org.javarosa.core.model.utils.IInstanceSerializingVisitor#serializeInstance(org.javarosa.core.model.instance.FormInstance, org.javarosa.core.model.IDataReference) */ public virtual sbyte[] serializeInstance(FormInstance model, IDataReference ref_Renamed) { init(); rootRef = org.javarosa.core.model.instance.FormInstance.unpackReference(ref_Renamed); if (this.serializer == null) { this.AnswerDataSerializer = new XFormAnswerDataSerializer(); } model.accept(this); if (theSmsStr != null) { //Encode in UTF-16 by default, since it's the default for complex messages //UPGRADE_TODO: Method 'java.lang.String.getBytes' was converted to 'System.Text.Encoding.GetEncoding(string).GetBytes(string)' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javalangStringgetBytes_javalangString'" return(SupportClass.ToSByteArray(System.Text.Encoding.GetEncoding("UTF-16BE").GetBytes(theSmsStr))); } else { return(null); } }
/// <summary> Not for re-implementation, dispatches all of the evaluation</summary> /// <param name="instance"> /// </param> /// <param name="evalContext"> /// </param> /// <param name="f"> /// </param> public void apply(FormInstance instance, EvaluationContext parentContext, TreeReference context, FormDef f) { //The triggeringRoot is the highest level of actual data we can inquire about, but it _isn't_ necessarily the basis //for the actual expressions, so we need genericize that ref against the current context TreeReference ungenericised = originalContextRef.contextualize(context); EvaluationContext ec = new EvaluationContext(parentContext, ungenericised); System.Object result = eval(instance, ec); for (int i = 0; i < targets.size(); i++) { TreeReference targetRef = ((TreeReference) targets.elementAt(i)).contextualize(ec.ContextRef); System.Collections.ArrayList v = ec.expandReference(targetRef); for (int j = 0; j < v.Count; j++) { TreeReference affectedRef = (TreeReference) v[j]; apply(affectedRef, result, instance, f); } } }
/// <param name="index"> /// </param> /// <returns> true if the element at the specified index is read only /// </returns> public virtual bool isIndexReadonly(FormIndex index) { if (index.BeginningOfFormIndex || index.EndOfFormIndex) { return(true); } TreeReference ref_Renamed = form.getChildInstanceRef(index); bool isAskNewRepeat = (getEvent(index) == FormEntryController.EVENT_PROMPT_NEW_REPEAT || getEvent(index) == FormEntryController.EVENT_REPEAT_JUNCTURE); if (isAskNewRepeat) { return(false); } else { TreeElement node = form.MainInstance.resolveReference(ref_Renamed); return(!node.isEnabled()); } }
/// <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); } } } } } } } }