//this method is for copying in the answers to an itemset. the template node of the destination //is used for overall structure (including data types), and the itemset source node is used for //raw data. note that data may be coerced across types, which may result in type conversion error //very similar in structure to populate() public void populateTemplate(TreeElement incoming, FormDef f) { if (this.isLeaf()) { IAnswerData value = incoming.value; if (value == null) { this.setValue(null); } else { Type classType = CompactInstanceWrapper.classForDataType(this.dataType); if (classType == null) { throw new SystemException("data type [" + value.GetType().Name + "] not supported inside itemset"); } else if (classType.IsAssignableFrom(value.GetType()) && !(value is SelectOneData || value is SelectMultiData)) { this.setValue(value); } else { String textVal = RestoreUtils.xfFact.serializeData(value); IAnswerData typedVal = RestoreUtils.xfFact.parseData(textVal, this.dataType, this.getRef(), f); this.setValue(typedVal); } } } else { for (int i = 0; i < this.getNumChildren(); i++) { TreeElement child = this.getChildAt(i); List <TreeElement> newChildren = incoming.getChildrenWithName(child.getName()); if (child.repeatable) { for (int k = 0; k < newChildren.Count; k++) { TreeElement template = f.Instance.getTemplate(child.getRef()); TreeElement newChild = template.deepCopy(false); newChild.setMult(k); this.children.Insert(i + k + 1, newChild); newChild.populateTemplate((TreeElement)newChildren[k], f); } i += newChildren.Count; } else { child.populateTemplate((TreeElement)newChildren[0], f); } } } }
public static Object unpackValue(IAnswerData val) { if (val == null) { return(""); } else if (val is UncastData) { return(val.Value); } else if (val is IntegerData) { return(( Double)(((int)val.Value))); } else if (val is LongData) { return(( Double)(((long)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 { Console.WriteLine("warning: unrecognized data type in xpath expr: " + val.GetType().Name); return(val.Value); //is this a good idea? } }