Write() public method

This write method is used to convert the provided object to an XML element. This creates a child node from the given OutputNode object. Once this child element is created it is populated with the fields of the source object in accordance with the XML schema class.
public Write ( OutputNode node, Object source ) : void
node OutputNode
source Object /// this is the object to be serialized to XML ///
return void
Beispiel #1
0
        /// <summary>
        /// This <c>write</c> method will write the specified object
        /// to the given XML element as as array entries. Each entry within
        /// the given array must be assignable to the array component type.
        /// Each array entry is serialized as a root element, that is, its
        /// <c>Root</c> annotation is used to extract the name.
        /// </summary>
        /// <param name="source">
        /// this is the source object array to be serialized
        /// </param>
        /// <param name="node">
        /// this is the XML element container to be populated
        /// </param>
        public void Write(OutputNode node, Object source)
        {
            int size = Array.getLength(source);

            for (int i = 0; i < size; i++)
            {
                Object item = Array.get(source, i);
                Class  type = entry.Type;
                root.Write(node, item, type, parent);
            }
            node.commit();
        }
Beispiel #2
0
        /// <summary>
        /// This method is used to write the value to the specified node.
        /// The value written to the node must be a composite object and if
        /// the object provided to this is null then nothing is written.
        /// </summary>
        /// <param name="node">
        /// this is the node that the value is written to
        /// </param>
        /// <param name="item">
        /// this is the item that is to be written
        /// </param>
        public void Write(OutputNode node, Object item)
        {
            Class  expect = type.Type;
            String key    = entry.GetValue();

            if (key == null)
            {
                key = context.GetName(expect);
            }
            String name = style.GetElement(key);

            root.Write(node, item, expect, name);
        }
Beispiel #3
0
 /// <summary>
 /// This <c>write</c> method will write the specified object
 /// to the given XML element as as list entries. Each entry within
 /// the given collection must be assignable from the annotated
 /// type specified within the <c>ElementList</c> annotation.
 /// Each entry is serialized as a root element, that is, its
 /// <c>Root</c> annotation is used to extract the name.
 /// </summary>
 /// <param name="list">
 /// this is the source collection to be serialized
 /// </param>
 /// <param name="node">
 /// this is the XML element container to be populated
 /// </param>
 public void Write(OutputNode node, Collection list)
 {
     for (Object item : list)
     {
         if (item != null)
         {
             Class type   = entry.Type;
             Class result = item.getClass();
             if (!type.isAssignableFrom(result))
             {
                 throw new PersistenceException("Entry %s does not match %s", result, type);
             }
             root.Write(node, item, type, name);
         }
     }
 }
Beispiel #4
0
        /// <summary>
        /// This method is used to write the value to the specified node.
        /// The value written to the node must be a composite object and if
        /// the element map annotation is configured to have a key attribute
        /// then this method will throw an exception.
        /// </summary>
        /// <param name="node">
        /// this is the node that the value is written to
        /// </param>
        /// <param name="item">
        /// this is the item that is to be written
        /// </param>
        public void Write(OutputNode node, Object item)
        {
            Class  expect = type.Type;
            String key    = entry.Key;

            if (entry.IsAttribute())
            {
                throw new ElementException("Can not have %s as an attribute", expect);
            }
            if (key == null)
            {
                key = context.GetName(expect);
            }
            String name = style.GetElement(key);

            root.Write(node, item, expect, name);
        }
Beispiel #5
0
        /// <summary>
        /// This <c>write</c> method will write the specified object
        /// to the given XML element as as list entries. Each entry within
        /// the given collection must be assignable from the annotated
        /// type specified within the <c>ElementList</c> annotation.
        /// Each entry is serialized as a root element, that is, its
        /// <c>Root</c> annotation is used to extract the name.
        /// </summary>
        /// <param name="source">
        /// this is the source collection to be serialized
        /// </param>
        /// <param name="node">
        /// this is the XML element container to be populated
        /// </param>
        public void Write(OutputNode node, Object source)
        {
            Collection list = (Collection)source;

            for (Object item : list)
            {
                if (item != null)
                {
                    Class expect = entry.Type;
                    Class type   = item.getClass();
                    if (!expect.isAssignableFrom(type))
                    {
                        throw new PersistenceException("Entry %s does not match %s", type, entry);
                    }
                    root.Write(node, item, expect, name);
                }
            }
        }