avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ymikul...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/csframework/src/cs/Configuration DefaultConfigurationSerializer.cs
Date Tue, 19 Nov 2002 11:31:04 GMT
ymikulski    2002/11/19 03:31:03

  Modified:    csframework/src/cs/Configuration
                        DefaultConfigurationSerializer.cs
  Log:
  no message
  
  Revision  Changes    Path
  1.6       +51 -20    jakarta-avalon-excalibur/csframework/src/cs/Configuration/DefaultConfigurationSerializer.cs
  
  Index: DefaultConfigurationSerializer.cs
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/csframework/src/cs/Configuration/DefaultConfigurationSerializer.cs,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DefaultConfigurationSerializer.cs	27 Oct 2002 15:54:35 -0000	1.5
  +++ DefaultConfigurationSerializer.cs	19 Nov 2002 11:31:02 -0000	1.6
  @@ -9,11 +9,12 @@
   using System.Collections;
   using System.IO;
   using System.Xml;
  +using System.Text;
   
   namespace Apache.Avalon.Configuration
   {
   	/// <summary>
  -	/// A Serializer of <see cref="DefaultConfiguration"/>.
  +	/// A Serializer/Deserializer of a <see cref="DefaultConfiguration"/>.
   	/// </summary>
   	public class DefaultConfigurationSerializer
   	{
  @@ -42,6 +43,11 @@
   			writer.Close(); 
   		}
   
  +		/// <summary>
  +		/// Makes a serialization of a <see cref="DefaultConfiguration"/> instance.
  +		/// </summary>
  +		/// <param name="writer"></param>
  +		/// <param name="configuration">A <see cref="DefaultConfiguration"/> instance
to serialize.</param>
   		public static void Serialize(XmlWriter writer, DefaultConfiguration configuration)
   		{
   			// serialize the configuration
  @@ -71,7 +77,7 @@
   		/// Makes a deserialization of a <see cref="DefaultConfiguration"/> instance.
   		/// </summary>
   		/// <param name="fileName">The name of the file, containing the XML document to
deserialize.</param>
  -		/// <returns>A deserialized <see cref="DefaultConfiguration"/>  instance.</returns>
  +		/// <returns>A deserialized <see cref="DefaultConfiguration"/> instance.</returns>
   		public static DefaultConfiguration Deserialize(string fileName)
   		{
   			DefaultConfiguration configuration = null;
  @@ -83,7 +89,7 @@
   
   			if (root != null)
   			{
  -				configuration = Deserialize(root);
  +				configuration = Deserialize(root, null);
   			}
   
   			return configuration;
  @@ -93,35 +99,60 @@
   		/// Makes a deserialization of <see cref="System.Xml.XmlNode"/> instance.
   		/// </summary>
   		/// <param name="node">The node to deserialize.</param>
  -		/// <returns>A deserialized <see cref="DefaultConfiguration"/>  instance.</returns>
  -		public static DefaultConfiguration Deserialize(XmlNode node)
  +		/// <param name="parent">A deserialized <see cref="DefaultConfiguration"/>
parent instance.</param>
  +		/// <returns>A deserialized <see cref="DefaultConfiguration"/> instance.</returns>
  +		public static DefaultConfiguration Deserialize(XmlNode node, DefaultConfiguration parent)
   		{
   			// node deserialization
  -			DefaultConfiguration configuration =
  -				new DefaultConfiguration(node.LocalName, "-", node.NamespaceURI, node.Prefix);
  -			
  -			configuration.Value = node.InnerText;
  +			DefaultConfiguration configuration = null;
   
  -			// attribute deserialization
  -			if (node.Attributes != null)
  +			if ((node.NodeType  == XmlNodeType.CDATA) || (node.NodeType == XmlNodeType.Text))
   			{
  -				foreach (XmlAttribute attr in node.Attributes)
  +				if (parent != null)
   				{
  -					if (string.Compare(attr.Prefix, string.Empty) == 0)
  -					{
  -						configuration.Attributes[attr.Name] = attr.Value;  
  -					}
  +					parent.Value = string.Concat(parent.Value, node.Value);
   				}
   			}
   
  -			// child deserialization
  -			foreach (XmlNode child in node.ChildNodes)
  +			if ((node.NodeType  == XmlNodeType.Document) || (node.NodeType == XmlNodeType.Element))
   			{
  -				DefaultConfiguration childConfiguration = Deserialize(child);
  -				configuration.Children.Add(childConfiguration); 
  +				configuration = new DefaultConfiguration(node.LocalName, "-", node.NamespaceURI, node.Prefix);
  +	
  +				// attribute deserialization
  +				if (node.Attributes != null)
  +				{
  +					foreach (XmlAttribute attr in node.Attributes)
  +					{
  +						if (string.Compare(attr.Prefix, string.Empty) == 0)
  +						{
  +							configuration.Attributes[attr.Name] = attr.Value;  
  +						}
  +					}
  +				}
  +
  +				// child deserialization
  +				foreach (XmlNode child in node.ChildNodes)
  +				{
  +					DefaultConfiguration childConfiguration = Deserialize(child, configuration);
  +					
  +					if (childConfiguration != null)
  +					{
  +						configuration.Children.Add(childConfiguration); 
  +					}
  +				}
   			}
   
   			return configuration;
  +		}
  +
  +		/// <summary>
  +		/// Makes a deserialization of <see cref="System.Xml.XmlNode"/> instance.
  +		/// </summary>
  +		/// <param name="node">The node to deserialize.</param>
  +		/// <returns>A deserialized <see cref="DefaultConfiguration"/> instance.</returns>
  +		public static DefaultConfiguration Deserialize(XmlNode node)
  +		{
  +			return Deserialize(node, null);
   		}
   	}
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message