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()); }
/// <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); }
// // 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)); } }
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 Element serializeNode(TreeElement instanceNode) { Element e = new Element(); //don't set anything on this element yet, as it might get overwritten //don't serialize template nodes or non-relevant nodes if ((respectRelevance && !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) { e = (Element)serializedAnswer; } else if (serializedAnswer is System.String) { e = new Element(); e.addChild(Node.TEXT, (System.String)serializedAnswer); } 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]); } } } else { //make sure all children of the same tag name are written en bloc System.Collections.ArrayList childNames = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); for (int i = 0; i < instanceNode.NumChildren; i++) { System.String childName = instanceNode.getChildAt(i).Name; if (!childNames.Contains(childName)) { childNames.Add(childName); } } for (int i = 0; i < childNames.Count; i++) { System.String childName = (System.String)childNames[i]; int mult = instanceNode.getChildMultiplicity(childName); for (int j = 0; j < mult; j++) { Element child = serializeNode(instanceNode.getChild(childName, j)); if (child != null) { e.addChild(Node.ELEMENT, child); } } } } e.setName(instanceNode.Name); // add hard-coded attributes for (int i = 0; i < instanceNode.AttributeCount; i++) { System.String namespace_Renamed = instanceNode.getAttributeNamespace(i); System.String name = instanceNode.getAttributeName(i); System.String val = instanceNode.getAttributeValue(i); // is it legal for getAttributeValue() to return null? playing it safe for now and assuming yes if (val == null) { val = ""; } e.setAttribute(namespace_Renamed, name, val); } if (instanceNode.Namespace != null) { e.setNamespace(instanceNode.Namespace); } return(e); }