Exemplo n.º 1
0
        public String serializeNode(TreeElement instanceNode)
        {
            String ae = "";

            // don't serialize template nodes or non-relevant nodes
            if (!instanceNode.isRelevant() ||
                instanceNode.getMult() == TreeReference.INDEX_TEMPLATE)
            {
                return(null);
            }

            if (instanceNode.getValue() != null)
            {
                Object serializedAnswer = serializer.serializeAnswerData(
                    instanceNode.getValue(), instanceNode.dataType);

                if (serializedAnswer is XmlElement)
                {
                    // DON"T handle this.
                    throw new SystemException("Can't handle serialized output for"
                                              + instanceNode.getValue().ToString() + ", "
                                              + serializedAnswer);
                }
                else if (serializedAnswer is String)
                {
                    XmlDocument theXmlDoc = new XmlDocument();
                    XmlElement  e         = theXmlDoc.CreateElement("TreeElement");//TODO
                    XmlText     xmlText   = theXmlDoc.CreateTextNode((String)serializedAnswer);
                    e.AppendChild(xmlText);

                    String tag = instanceNode.getAttributeValue("", "tag");
                    ae += ((tag != null) ? tag + delimeter : delimeter); // tag
                    // might
                    // be
                    // null

                    for (int k = 0; k < e.ChildNodes.Count; k++)
                    {
                        ae += e.ChildNodes[k].InnerText.ToString() + delimeter;
                    }
                }
                else
                {
                    throw new SystemException("Can't handle serialized output for"
                                              + instanceNode.getValue().ToString() + ", "
                                              + serializedAnswer);
                }

                if (serializer.containsExternalData(instanceNode.getValue()))
                {
                    IDataPointer[] pointer = serializer
                                             .retrieveExternalDataPointer(instanceNode.getValue());
                    for (int i = 0; i < pointer.Length; ++i)
                    {
                        dataPointers.Add(pointer[i]);
                    }
                }
            }
            return(ae);
        }
Exemplo n.º 2
0
        public IDataPointer[] retrieveExternalDataPointer(IAnswerData data)
        {
            IEnumerator en = additionalSerializers.GetEnumerator();

            while (en.MoveNext())
            {
                IAnswerDataSerializer serializer = (IAnswerDataSerializer)en.Current;
                Boolean contains = serializer.containsExternalData(data);
                if (contains != null)
                {
                    return(serializer.retrieveExternalDataPointer(data));
                }
            }
            if (data is PointerAnswerData)
            {
                IDataPointer[] pointer = new IDataPointer[1];
                pointer[0] = (IDataPointer)((PointerAnswerData)data).getValue();
                return(pointer);
            }
            else if (data is MultiPointerAnswerData)
            {
                return((IDataPointer[])((MultiPointerAnswerData)data).Value);
            }
            //This shouldn't have been called.
            return(null);
        }
Exemplo n.º 3
0
        /*
         * (non-Javadoc)
         * @see org.javarosa.core.model.IAnswerDataSerializer#containsExternalData(org.javarosa.core.model.data.IAnswerData)
         */
        public Boolean containsExternalData(IAnswerData data)
        {
            //First check for registered serializers to identify whether
            //they override this one.
            IEnumerator en = additionalSerializers.GetEnumerator();

            while (en.MoveNext())
            {
                IAnswerDataSerializer serializer = (IAnswerDataSerializer)en.Current;
                Boolean contains = serializer.containsExternalData(data);
                if (contains != null)
                {
                    return(contains);
                }
            }
            if (data is PointerAnswerData ||
                data is MultiPointerAnswerData)
            {
                return(true);
            }
            return(false);
        }
Exemplo n.º 4
0
        public XmlElement serializeNode(TreeElement instanceNode)
        {
            XmlElement e = theXmlDoc.CreateElement(instanceNode.getName());//TODO Name

            //don't serialize template nodes or non-relevant nodes
            if (!instanceNode.isRelevant() || instanceNode.getMult() == TreeReference.INDEX_TEMPLATE)
            {
                return(null);
            }

            if (instanceNode.getValue() != null)
            {
                Object serializedAnswer = serializer.serializeAnswerData(instanceNode.getValue(), instanceNode.dataType);

                if (serializedAnswer is XmlElement)
                {
                    e = (XmlElement)serializedAnswer;
                }
                else if (serializedAnswer is String)
                {
                    e = e.OwnerDocument.CreateElement(instanceNode.getName());

                    XmlText xmlText = theXmlDoc.CreateTextNode((String)serializedAnswer);  //TODO name
                    e.AppendChild(xmlText);
                }
                else
                {
                    throw new SystemException("Can't handle serialized output for" + instanceNode.getValue().ToString() + ", " + serializedAnswer);
                }

                if (serializer.containsExternalData(instanceNode.getValue()))
                {
                    IDataPointer[] pointer = serializer.retrieveExternalDataPointer(instanceNode.getValue());
                    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
                ArrayList childNames = new ArrayList();
                for (int i = 0; i < instanceNode.getNumChildren(); i++)
                {
                    String childName = instanceNode.getChildAt(i).getName();
                    Console.WriteLine("CHILDNAME: " + childName);
                    if (!childNames.Contains(childName))
                    {
                        childNames.Add(childName);
                    }
                }

                for (int i = 0; i < childNames.Count; i++)
                {
                    String childName = (String)childNames[i];
                    int    mult      = instanceNode.getChildMultiplicity(childName);
                    for (int j = 0; j < mult; j++)
                    {
                        XmlElement child = serializeNode(instanceNode.getChild(childName, j));
                        if (child != null)
                        {
                            e.AppendChild(child);
                        }
                    }
                }
            }

            XmlElement e1 = e.OwnerDocument.CreateElement(instanceNode.getName());

            e.ParentNode.ReplaceChild(e1, e);

            // add hard-coded attributes
            for (int i = 0; i < instanceNode.getAttributeCount(); i++)
            {
                String namespace_ = instanceNode.getAttributeNamespace(i);
                String name       = instanceNode.getAttributeName(i);
                String val        = instanceNode.getAttributeValue(i);
                e.SetAttribute(name, namespace_, val);
            }

            return(e);
        }