Read() public method

This read method is used to deserialize an object from the provided XML element. The class provided acts as the XML schema definition used to control the deserialization. If the XML schema does not have a Root annotation this throws an exception. Also if the root annotation name is not the same as the XML element name an exception is thrown.
public Read ( InputNode node, Class type ) : Object
node InputNode /// this is the node that is to be deserialized ///
type Class /// this is the XML schema class to be used ///
return Object
示例#1
0
        /// <summary>
        /// This is used to read the specified node from in to the list. If
        /// the node is null then this represents a null element value in
        /// the array. The node can be null only if there is a parent and
        /// that parent contains no child XML elements.
        /// </summary>
        /// <param name="node">
        /// this is the node to read the array value from
        /// </param>
        /// <param name="list">
        /// this is the list to add the array value in to
        /// </param>
        /// <param name="index">
        /// this is the offset to set the value in the array
        /// </param>
        public void Read(InputNode node, Object list, int index)
        {
            Class  type  = entry.Type;
            Object value = null;

            if (!node.isEmpty())
            {
                value = root.Read(node, type);
            }
            Array.set(list, index, value);
        }
示例#2
0
        /// <summary>
        /// This <c>read</c> method will read the XML element from the
        /// provided node. This checks to ensure that the deserialized type
        /// is the same as the entry type provided. If the types are not
        /// the same then an exception is thrown. This is done to ensure
        /// each node in the collection contain the same root annotation.
        /// </summary>
        /// <param name="node">
        /// this is the XML element that is to be deserialized
        /// </param>
        /// <param name="expect">
        /// this is the type expected of the deserialized type
        /// </param>
        /// <returns>
        /// this returns the item to attach to the object contact
        /// </returns>
        public Object Read(InputNode node, Class expect)
        {
            Object item   = root.Read(node, expect);
            Class  result = item.getClass();
            Class  type   = entry.Type;

            if (!type.isAssignableFrom(result))
            {
                throw new PersistenceException("Entry %s does not match %s", result, entry);
            }
            return(item);
        }
示例#3
0
        /// <summary>
        /// This method is used to read the value object from the node. The
        /// value read from the node is resolved using the template filter.
        /// If the value data can not be found according to the annotation
        /// attributes then null is assumed and returned.
        /// </summary>
        /// <param name="node">
        /// this is the node to read the value object from
        /// </param>
        /// <returns>
        /// this returns the value deserialized from the node
        /// </returns>
        public Object Read(InputNode node)
        {
            InputNode next   = node.getNext();
            Class     expect = type.Type;

            if (next == null)
            {
                return(null);
            }
            if (next.IsEmpty())
            {
                return(null);
            }
            return(root.Read(next, expect));
        }
示例#4
0
        /// <summary>
        /// This <c>populate</c> method wll read the XML element list
        /// from the provided node and deserialize its children as entry types.
        /// This will each entry type is deserialized as a root type, that
        /// is, its <c>Root</c> annotation must be present and the
        /// name of the entry element must match that root element name.
        /// </summary>
        /// <param name="node">
        /// this is the XML element that is to be deserialized
        /// </param>
        /// <param name="result">
        /// this is the collection that is to be populated
        /// </param>
        /// <returns>
        /// this returns the item to attach to the object contact
        /// </returns>
        public Object Populate(InputNode node, Object result)
        {
            Collection list = (Collection)result;

            while (true)
            {
                InputNode next   = node.getNext();
                Class     expect = entry.Type;
                if (next == null)
                {
                    return(list);
                }
                list.add(root.Read(next, expect));
            }
        }
示例#5
0
        /// <summary>
        /// This method is used to read the key value from the node. The
        /// value read from the node is resolved using the template filter.
        /// If the key value can not be found according to the annotation
        /// attributes then null is assumed and returned.
        /// </summary>
        /// <param name="node">
        /// this is the node to read the key value from
        /// </param>
        /// <param name="key">
        /// this is the name of the key wrapper XML element
        /// </param>
        /// <returns>
        /// this returns the value deserialized from the node
        /// </returns>
        public Object Read(InputNode node, String key)
        {
            String name   = style.GetElement(key);
            Class  expect = type.Type;

            if (name != null)
            {
                node = node.getNext(name);
            }
            if (node == null)
            {
                return(null);
            }
            if (node.IsEmpty())
            {
                return(null);
            }
            return(root.Read(node, expect));
        }