/// <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 void InitBlock() { this(base_Renamed, context); this.formInstances = formInstances; this(base_Renamed); this.formInstances = formInstances; this.instance = instance; this.formInstances = formInstances; this.instance = instance; this.contextNode = TreeReference.rootRef(); functionHandlers = new HashMap <String, IFunctionHandler>(); //UPGRADE_TODO: Class 'java.util.HashMap' was converted to 'System.Collections.Hashtable' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilHashMap'" variables = new System.Collections.Hashtable(); for (String var: variables.keySet()) { //UPGRADE_TODO: Method 'java.util.HashMap.get' was converted to 'System.Collections.Hashtable.Item' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilHashMapget_javalangObject'" setVariable(var, variables[var]); } return(expandReference(ref_Renamed, false)); if (!ref_Renamed.isAbsolute()) { return(null); } FormInstance baseInstance; if (ref_Renamed.getInstanceName() != null) { baseInstance = getInstance(ref_Renamed.getInstanceName()); } else { baseInstance = instance; } if (baseInstance == null) { throw new System.SystemException("Unable to expand reference " + ref_Renamed.toString(true) + ", no appropriate instance in evaluation context"); } List <TreeReference> v = new List <TreeReference>(); expandReference(ref_Renamed, baseInstance, baseInstance.getRoot().Ref, v, includeTemplates); return(v); int depth = workingRef.size(); //check to see if we've matched fully if (depth == sourceRef.size()) { //TODO: Do we need to clone these references? refs.addElement(workingRef); } else { //Otherwise, need to get the next set of matching references System.String name = sourceRef.getName(depth); predicates = sourceRef.getPredicate(depth); //Copy predicates for batch fetch if (predicates != null) { List <XPathExpression> predCopy = new List <XPathExpression>(); for (XPathExpression xpe: predicates) { predCopy.addElement(xpe); } predicates = predCopy; } //ETHERTON: Is this where we should test for predicates? int mult = sourceRef.getMultiplicity(depth); List <TreeReference> set = new List <TreeReference>(); TreeElement node = instance.resolveReference(workingRef); List <TreeReference> passingSet = new List <TreeReference>(); { if (node.NumChildren > 0) { if (mult == TreeReference.INDEX_UNBOUND) { int count = node.getChildMultiplicity(name); for (int i = 0; i < count; i++) { TreeElement child = node.getChild(name, i); if (child != null) { set_Renamed.addElement(child.Ref); } else { throw new System.SystemException("Missing or non-sequntial nodes expanding a reference"); // missing/non-sequential // nodes } } if (includeTemplates) { TreeElement template = node.getChild(name, TreeReference.INDEX_TEMPLATE); if (template != null) { set_Renamed.addElement(template.Ref); } } } else if (mult != TreeReference.INDEX_ATTRIBUTE) { //TODO: Make this test mult >= 0? //If the multiplicity is a simple integer, just get //the appropriate child TreeElement child = node.getChild(name, mult); if (child != null) { set_Renamed.addElement(child.Ref); } } } if (mult == TreeReference.INDEX_ATTRIBUTE) { TreeElement attribute = node.getAttribute(null, name); if (attribute != null) { set_Renamed.addElement(attribute.Ref); } } } if (predicates != null && predicateEvaluationProgress != null) { predicateEvaluationProgress[1] += set_Renamed.size(); } if (predicates != null) { bool firstTime = true; List <TreeReference> passed = new List <TreeReference>(); for (XPathExpression xpe: predicates) { for (int i = 0; i < set_Renamed.size(); ++i) { //if there are predicates then we need to see if e.nextElement meets the standard of the predicate TreeReference treeRef = set_Renamed.elementAt(i); //test the predicate on the treeElement EvaluationContext evalContext = rescope(treeRef, (firstTime?treeRef.MultLast:i)); System.Object o = xpe.eval(instance, evalContext); if (o is System.Boolean) { bool testOutcome = ((System.Boolean)o); if (testOutcome) { passed.addElement(treeRef); } } } firstTime = false; set_Renamed.clear(); set_Renamed.addAll(passed); passed.clear(); if (predicateEvaluationProgress != null) { predicateEvaluationProgress[0]++; } } } for (int i = 0; i < set_Renamed.size(); ++i) { TreeReference treeRef = set_Renamed.elementAt(i); expandReference(sourceRef, instance, treeRef, refs, includeTemplates); } } }
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); }
/// <summary> recursively read in a node of the instance, by filling out the template instance</summary> /// <param name="e"> /// </param> /// <param name="ref"> /// </param> /// <param name="in"> /// </param> /// <param name="pf"> /// </param> /// <throws> IOException </throws> /// <throws> DeserializationException </throws> //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'" private void readTreeElement(TreeElement e, System.IO.BinaryReader in_Renamed, PrototypeFactory pf) { TreeElement templ = instance.getTemplatePath(e.Ref); bool isGroup = !templ.Leaf; if (isGroup) { System.Collections.ArrayList childTypes = 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 (!childTypes.Contains(childName)) { childTypes.Add(childName); } } for (int i = 0; i < childTypes.Count; i++) { System.String childName = (System.String)childTypes[i]; TreeReference childTemplRef = e.Ref.extendRef(childName, 0); TreeElement childTempl = instance.getTemplatePath(childTemplRef); bool repeatable = childTempl.Repeatable; int n = ExtUtil.readInt(in_Renamed); bool relevant = (n > 0); if (!repeatable && n > 1) { throw new DeserializationException("Detected repeated instances of a non-repeatable node"); } if (repeatable) { int mult = e.getChildMultiplicity(childName); for (int j = mult - 1; j >= 0; j--) { e.removeChild(childName, j); } for (int j = 0; j < n; j++) { TreeReference dstRef = e.Ref.extendRef(childName, j); try { instance.copyNode(childTempl, dstRef); } catch (InvalidReferenceException ire) { //If there is an invalid reference, this is a malformed instance, //so we'll throw a Deserialization exception. TreeReference r = ire.InvalidReference; if (r == null) { //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 DeserializationException("Null Reference while attempting to deserialize! " + ire.Message); } else { //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 DeserializationException("Invalid Reference while attemtping to deserialize! Reference: " + r.toString(true) + " | " + ire.Message); } } TreeElement child = e.getChild(childName, j); child.setRelevant(true); readTreeElement(child, in_Renamed, pf); } } else { TreeElement child = e.getChild(childName, 0); child.setRelevant(relevant); if (relevant) { readTreeElement(child, in_Renamed, pf); } } } } else { e.Value = (IAnswerData)ExtUtil.read(in_Renamed, new ExtWrapAnswerData(this, e.DataType)); } }