public static FormInstance subDataModel(TreeElement top) { TreeElement newTop = top.shallowCopy(); newTop.setMult(0); return(new FormInstance(newTop)); }
private void InitBlock() { ExtUtil.writeNumeric(out_Renamed, attributes.size()); for (TreeElement e: attributes) { ExtUtil.write(out_Renamed, e.getNamespace()); ExtUtil.write(out_Renamed, e.getName()); ExtUtil.write(out_Renamed, e.getAttributeValue()); } int size = (int)ExtUtil.readNumeric(in_Renamed); List <TreeElement> attributes = new List <TreeElement>(); for (int i = 0; i < size; ++i) { System.String namespace_Renamed = ExtUtil.readString(in_Renamed); System.String name = ExtUtil.readString(in_Renamed); System.String value_Renamed = ExtUtil.readString(in_Renamed); TreeElement attr = TreeElement.constructAttributeElement(namespace_Renamed, name, value_Renamed); attr.setParent(parent); attributes.addElement(attr); } return(attributes); ExtUtil.stringCache = stringCache; }
/// <summary> recursively write out a node of the instance</summary> /// <param name="out"> /// </param> /// <param name="e"> /// </param> /// <param name="ref"> /// </param> /// <throws> IOException </throws> //UPGRADE_TODO: Class 'java.io.DataOutputStream' was converted to 'System.IO.BinaryWriter' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioDataOutputStream'" private void writeTreeElement(System.IO.BinaryWriter out_Renamed, TreeElement e) { TreeElement templ = instance.getTemplatePath(e.Ref); bool isGroup = !templ.Leaf; if (isGroup) { System.Collections.ArrayList childTypesHandled = 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 (!childTypesHandled.Contains(childName)) { childTypesHandled.Add(childName); int mult = e.getChildMultiplicity(childName); if (mult > 0 && !e.getChild(childName, 0).isRelevant()) { mult = 0; } ExtUtil.writeNumeric(out_Renamed, mult); for (int j = 0; j < mult; j++) { writeTreeElement(out_Renamed, e.getChild(childName, j)); } } } } else { ExtUtil.write(out_Renamed, new ExtWrapAnswerData(this, e.DataType, e.Value)); } }
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); } }
/// <summary> Creates a FormEntryPrompt for the element at the given index in the form. /// /// </summary> /// <param name="form"> /// </param> /// <param name="index"> /// </param> public FormEntryPrompt(FormDef form, FormIndex index) : base(form, index) { InitBlock(); if (!(element is QuestionDef)) { throw new System.ArgumentException("FormEntryPrompt can only be created for QuestionDef elements"); } this.mTreeElement = form.MainInstance.resolveReference(index.Reference); }
/// <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)); }
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); } }
public virtual System.String getAdditionalAttribute(System.String namespace_Renamed, System.String name) { TreeElement e = TreeElement.getAttribute(additionalAttributes, namespace_Renamed, name); if (e != null) { return(e.getAttributeValue()); } return(null); }
public virtual System.String serializeNode(TreeElement instanceNode) { StringBuilder b = new StringBuilder(); // don't serialize template nodes or non-relevant nodes if (!instanceNode.isRelevant() || instanceNode.Mult == TreeReference.INDEX_TEMPLATE) { return(null); } if (instanceNode.Value != null) { System.Object serializedAnswer = serializer.serializeAnswerData(instanceNode.Value, instanceNode.DataType); if (serializedAnswer is Element) { // DON"T handle this. //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Object.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" throw new System.SystemException("Can't handle serialized output for" + instanceNode.Value.ToString() + ", " + serializedAnswer); } else if (serializedAnswer is System.String) { Element e = new Element(); e.addChild(Node.TEXT, (System.String)serializedAnswer); System.String tag = instanceNode.getAttributeValue("", "tag"); if (tag != null) { b.append(tag); } b.append(delimiter); for (int k = 0; k < e.getChildCount(); k++) { b.append(e.getChild(k).toString()); b.append(delimiter); } } else { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Object.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" throw new System.SystemException("Can't handle serialized output for" + instanceNode.Value.ToString() + ", " + serializedAnswer); } if (serializer.containsExternalData(instanceNode.Value)) { IDataPointer[] pointer = serializer.retrieveExternalDataPointer(instanceNode.Value); for (int i = 0; i < pointer.Length; ++i) { dataPointers.Add(pointer[i]); } } } return(b.toString()); }
public override void formElementStateChanged(TreeElement instanceNode, int changeFlags) { if (this.mTreeElement != instanceNode) { throw new System.SystemException("Widget received event from foreign question"); } if (viewWidget != null) { viewWidget.refreshWidget(changeFlags); } }
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; } }
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 virtual bool handlePostProcess(TreeElement node, System.String params_Renamed) { if ("end".Equals(params_Renamed)) { node.setAnswer(Enclosing_Instance.Timestamp); return(true); } else { return(false); } }
/// <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); } }
public virtual bool questionPostProcess(TreeElement node, System.String preloadType, System.String params_Renamed) { IPreloadHandler handler = (IPreloadHandler)preloadHandlers.get(preloadType); if (handler != null) { return(handler.handlePostProcess(node, params_Renamed)); } else { System.Console.Error.WriteLine("Do not know how to handle preloader [" + preloadType + "]"); return(false); } }
/// <summary> deserialize a compact instance. note the retrieval of the template data instance</summary> //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) { int formID = ExtUtil.readInt(in_Renamed); instance = getTemplateInstance(formID).Clone(); instance.ID = ExtUtil.readInt(in_Renamed); instance.DateSaved = (System.DateTime)ExtUtil.read(in_Renamed, new ExtWrapNullable(typeof(System.DateTime))); //formID, name, schema, versions, and namespaces are all invariants of the template instance TreeElement root = instance.getRoot(); readTreeElement(root, in_Renamed, pf); }
public static void importRMS(FormInstance dm, IStorageUtility storage, System.Type type, System.String path) { if (!typeof(Externalizable).IsAssignableFrom(type) || !typeof(Restorable).IsAssignableFrom(type)) { return; } bool idMatters = typeof(Persistable).IsAssignableFrom(type); System.String childName = ((Restorable)PrototypeFactory.getInstance(type)).RestorableType; TreeElement e = dm.resolveReference(absRef(path, dm)); System.Collections.ArrayList children = e.getChildrenWithName(childName); for (int i = 0; i < children.Count; i++) { FormInstance child = subDataModel((TreeElement)children[i]); Restorable inst = (Restorable)PrototypeFactory.getInstance(type); //restore record id first so 'importData' has access to it int recID = -1; if (idMatters) { recID = ((System.Int32)getValue(RECORD_ID_TAG, child)); ((Persistable)inst).ID = recID; } inst.importData(child); try { if (idMatters) { storage.write((Persistable)inst); } else { storage.add((Externalizable)inst); } } catch (System.Exception ex) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Class.getName' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" //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("Error importing RMS during restore! [" + type.FullName + ":" + recID + "]; " + ex.Message); } } }
/// <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); }
/// <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); } }
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 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); } }
// // 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)); } }
/// <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); } } } } } } } }
private void performAction(TreeElement node, int action) { switch (action) { case ACTION_NULL: break; case ACTION_SHOW: node.setRelevant(true); break; case ACTION_HIDE: node.setRelevant(false); break; case ACTION_ENABLE: node.setEnabled(true); break; case ACTION_DISABLE: node.setEnabled(false); break; case ACTION_LOCK: /* not supported */; break; case ACTION_UNLOCK: /* not supported */; break; case ACTION_REQUIRE: node.Required = true; break; case ACTION_DONT_REQUIRE: node.Required = false; break; } }
/* * (non-Javadoc) * @see org.javarosa.core.model.utils.ITreeVisitor#visit(org.javarosa.core.model.DataModelTree) */ public virtual void visit(FormInstance tree) { theXmlDoc = new Document(); //TreeElement root = tree.getRoot(); TreeElement root = tree.resolveReference(rootRef); //For some reason resolveReference won't ever return the root, so we'll //catch that case and just start at the root. if (root == null) { root = tree.getRoot(); } for (int i = 0; i < root.NumChildren; i++) { TreeElement childAt = root.getChildAt(i); } if (root != null) { theXmlDoc.addChild(Node.ELEMENT, serializeNode(root)); } Element top = theXmlDoc.getElement(0); System.String[] prefixes = tree.NamespacePrefixes; for (int i = 0; i < prefixes.Length; ++i) { top.setPrefix(prefixes[i], tree.getNamespaceURI(prefixes[i])); } if (tree.schema != null) { top.setNamespace(tree.schema); top.setPrefix("", tree.schema); } }
/* * (non-Javadoc) * * @see * org.javarosa.core.model.utils.ITreeVisitor#visit(org.javarosa.core.model * .DataModelTree) */ public virtual void visit(FormInstance tree) { nodeSet = new System.Text.StringBuilder().ToString(); //TreeElement root = tree.getRoot(); TreeElement root = tree.resolveReference(rootRef); xmlns = root.getAttributeValue("", "xmlns"); delimiter = root.getAttributeValue("", "delimiter"); if (delimiter == null) { // for the spelling-impaired... delimiter = root.getAttributeValue("", "delimeter"); } prefix = root.getAttributeValue("", "prefix"); xmlns = (xmlns != null)?xmlns:" "; delimiter = (delimiter != null)?delimiter:" "; prefix = (prefix != null)?prefix:" "; //Don't bother adding any delimiters, yet. Delimiters are //added before tags/data theSmsStr = prefix; // serialize each node to get it's answers for (int j = 0; j < root.NumChildren; j++) { TreeElement tee = root.getChildAt(j); System.String e = serializeNode(tee); if (e != null) { theSmsStr += e; } } theSmsStr = theSmsStr.Trim(); }
public virtual void setAdditionalAttribute(System.String namespace_Renamed, System.String name, System.String value_Renamed) { TreeElement.setAttribute(null, additionalAttributes, namespace_Renamed, name, value_Renamed); }
public virtual bool handlePostProcess(TreeElement node, System.String params_Renamed) { //do nothing return(false); }
public virtual bool handlePostProcess(TreeElement node, System.String params_Renamed) { Enclosing_Instance.saveProperty(params_Renamed, node); return(false); }