예제 #1
0
        /// <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));
            }
        }
예제 #2
0
        /*
         * (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);
            }
        }
예제 #3
0
        /*
         * (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();
        }
예제 #4
0
        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);
        }
예제 #5
0
        /// <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));
            }
        }