Author: fmantek
Date: Wed Sep 12 07:46:41 2007
New Revision: 248

Added:
   trunk/clients/cs/src/extensions/extensionbase.cs
Modified:
   trunk/clients/cs/samples/execrequest/main.cs
   trunk/clients/cs/src/extensions/simplecontainer.cs
   trunk/clients/cs/src/extensions/simpleelement.cs
   trunk/clients/cs/src/unittests/caltest.cs
   trunk/clients/cs/src/unittests/photostest.cs

Log:
Added an inbetween base class for SimpleElement.

Modified: trunk/clients/cs/samples/execrequest/main.cs
==============================================================================
--- trunk/clients/cs/samples/execrequest/main.cs        (original)
+++ trunk/clients/cs/samples/execrequest/main.cs        Wed Sep 12 07:46:41 2007
@@ -88,6 +88,7 @@
             }
             else 
             {
+                Console.WriteLine("Setting user credentials for: " + userName);
                 service.setUserCredentials(userName, passWord);
             }
 
@@ -95,6 +96,7 @@
             {
                 if (cmd.Equals("QUERY"))
                 {
+                    Console.WriteLine("Querying: " + targetUri);
                     Stream result = service.Query(new Uri(targetUri));
                     DumpStream(result);
                 }

Added: trunk/clients/cs/src/extensions/extensionbase.cs
==============================================================================
--- (empty file)
+++ trunk/clients/cs/src/extensions/extensionbase.cs    Wed Sep 12 07:46:41 2007
@@ -0,0 +1,201 @@
+/* Copyright (c) 2006 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+using System;
+using System.Collections;
+using System.Text;
+using System.Xml;
+using Google.GData.Client;
+using System.Globalization;
+
+namespace Google.GData.Extensions {
+
+    /// <summary>
+    /// Extensible type used in many places.
+    /// </summary>
+    public abstract class ExtensionBase : IExtensionElement, 
IExtensionElementFactory
+    {
+
+        private string xmlName;
+        private string xmlPrefix;
+        private string xmlNamespace;
+        private string value;
+        /// <summary>
+        /// this holds the attribute list for an extension element
+        /// </summary>
+        protected SortedList attributes;
+
+
+
+        /// <summary>
+        /// constructor
+        /// </summary>
+        /// <param name="name">the xml name</param>
+        /// <param name="prefix">the xml prefix</param>
+        /// <param name="ns">the xml namespace</param>
+        protected ExtensionBase(string name, string prefix, string ns)
+        {
+            this.xmlName = name;
+            this.xmlPrefix = prefix;
+            this.xmlNamespace = ns;
+        }
+
+        /// <summary>
+        /// returns the attributes list
+        /// </summary>
+        /// <returns>SortedList</returns>
+        internal SortedList getAttributes()
+        {
+            if (this.attributes == null)
+            {
+                this.attributes = new SortedList();
+            }
+            return this.attributes;
+        }
+        
+        
+        #region overloaded for persistence
+
+        //////////////////////////////////////////////////////////////////////
+        /// <summary>Returns the constant representing this XML 
element.</summary> 
+        //////////////////////////////////////////////////////////////////////
+        public string XmlName
+        {
+            get { return this.xmlName; }
+        }
+
+        //////////////////////////////////////////////////////////////////////
+        /// <summary>Returns the constant representing this XML 
element.</summary> 
+        //////////////////////////////////////////////////////////////////////
+        public string XmlNameSpace
+        {
+            get { return this.xmlNamespace; }
+        }
+        //////////////////////////////////////////////////////////////////////
+        /// <summary>Returns the constant representing this XML 
element.</summary> 
+        //////////////////////////////////////////////////////////////////////
+        public string XmlPrefix
+        {
+            get { return this.xmlPrefix; }
+        }
+
+        /// <summary>
+        /// debugging helper
+        /// </summary>
+        /// <returns></returns>
+        public override string ToString()
+        {
+            return base.ToString() + " for: " + XmlNameSpace + "- " + XmlName;
+        }
+
+
+        //////////////////////////////////////////////////////////////////////
+        /// <summary>Parses an xml node to create a Who object.</summary> 
+        /// <param name="node">the xml parses node, can be NULL</param>
+        /// <returns>the created SimpleElement object</returns>
+        //////////////////////////////////////////////////////////////////////
+        public abstract IExtensionElement CreateInstance(XmlNode node);
+  
+        /// <summary>
+        /// used to copy the attribute lists over
+        /// </summary>
+        /// <param name="factory"></param>
+        internal void InitInstance(SimpleElement factory)
+        {
+            this.attributes = null;
+            for (int i=0; i < factory.Attributes.Count; i++)
+            {
+                string name = factory.Attributes.GetKey(i) as string;
+                string value = factory.Attributes.GetByIndex(i) as string;
+                this.getAttributes().Add(name, value);
+            }
+        }
+
+        /// <summary>
+        /// default method override to handle attribute processing
+        /// the base implementation does process the attributes list
+        /// and reads all that are in there.
+        /// </summary>
+        /// <param name="node">XmlNode with attributes</param>
+        public virtual void ProcessAttributes(XmlNode node)
+        {
+            if (this.attributes != null)
+            {
+                for (int i=0; i < this.getAttributes().Count; i++)
+                {
+                    string name = this.getAttributes().GetKey(i) as string;
+                    string value = getAttribute(node, name);
+                    if (value != null)
+                    {
+                        this.getAttributes()[name] = value;
+                    }
+                }
+                return;
+            }
+        }
+
+        /// <summary>
+        /// helper method to extract an attribute as string from
+        /// an xmlnode using the passed in node and the attributename
+        /// </summary>
+        /// <param name="node">node to extract attribute from</param>
+        /// <param name="attributeName">the name of the attribute</param>
+        /// <returns>string - null if attribute is not present</returns>
+        protected string getAttribute(XmlNode node, string attributeName)
+        { 
+            string retValue = null;
+
+            if (node.Attributes != null)
+            {
+                if (node.Attributes[attributeName] != null)
+                {
+                    retValue = node.Attributes[attributeName].Value;
+                }
+            }
+            return retValue;
+        }
+      
+        /// <summary>
+        /// Persistence method for the EnumConstruct object
+        /// </summary>
+        /// <param name="writer">the xmlwriter to write into</param>
+        public virtual void Save(XmlWriter writer)
+        {
+            writer.WriteStartElement(XmlPrefix, XmlName, XmlNameSpace);
+            if (this.attributes != null)
+            {
+                for (int i=0; i < this.getAttributes().Count; i++)
+                {
+                    string name = this.getAttributes().GetKey(i) as string;
+                    string value = this.getAttributes().GetByIndex(i) as 
string;
+                    writer.WriteAttributeString(name, value);
+                }
+            }
+            SaveInnerXml(writer);
+
+            writer.WriteEndElement();
+        }
+
+        /// <summary>
+        /// a subclass that want's to save addtional XML would need to 
overload this
+        /// the default implementation does nothing
+        /// </summary>
+        /// <param name="writer"></param>
+        public virtual void SaveInnerXml(XmlWriter writer)
+        {
+        }
+        #endregion
+    }
+}  

Modified: trunk/clients/cs/src/extensions/simplecontainer.cs
==============================================================================
--- trunk/clients/cs/src/extensions/simplecontainer.cs  (original)
+++ trunk/clients/cs/src/extensions/simplecontainer.cs  Wed Sep 12 07:46:41 2007
@@ -27,7 +27,7 @@
     /// TODO: at one point think about using this as the base for atom:base
     /// as there is some utility overlap between the 2 of them
     /// </summary>
-    public class SimpleContainer : SimpleElement
+    public class SimpleContainer : ExtensionBase
     {
         private ArrayList extensions;
         private ArrayList extensionFactories;

Modified: trunk/clients/cs/src/extensions/simpleelement.cs
==============================================================================
--- trunk/clients/cs/src/extensions/simpleelement.cs    (original)
+++ trunk/clients/cs/src/extensions/simpleelement.cs    Wed Sep 12 07:46:41 2007
@@ -24,17 +24,13 @@
 
     /// <summary>
     /// Extensible enum type used in many places.
+    /// compared to the base class, this one
+    /// adds a default values
     /// </summary>
-    public abstract class SimpleElement : IExtensionElement, 
IExtensionElementFactory
+    public abstract class SimpleElement : ExtensionBase
     {
 
-        private string xmlName;
-        private string xmlPrefix;
-        private string xmlNamespace;
         private string value;
-        private SortedList attributes;
-
-
 
         /// <summary>
         /// constructor
@@ -43,12 +39,12 @@
         /// <param name="prefix">the xml prefix</param>
         /// <param name="ns">the xml namespace</param>
         protected SimpleElement(string name, string prefix, string ns)
+                    :base(name, prefix,ns)
         {
-            this.xmlName = name;
-            this.xmlPrefix = prefix;
-            this.xmlNamespace = ns;
         }
 
+
+
         /// <summary>
         /// constructor
         /// </summary>
@@ -57,10 +53,8 @@
         /// <param name="ns">the xml namespace</param>
         /// <param name="value">the intial value</param>
         protected SimpleElement(string name, string prefix, string ns, string 
value)
+                    :base(name, prefix, ns)
         {
-            this.xmlName = name;
-            this.xmlPrefix = prefix;
-            this.xmlNamespace = ns;
             this.value = value;
         }
 
@@ -74,11 +68,7 @@
         {
             get 
             {
-                if (this.attributes == null)
-                {
-                    this.attributes = new SortedList();
-                }
-                return this.attributes;
+                return getAttributes();
             }
             set {this.attributes = value;}
         }
@@ -114,29 +104,6 @@
    
         #region overloaded for persistence
 
-        //////////////////////////////////////////////////////////////////////
-        /// <summary>Returns the constant representing this XML 
element.</summary> 
-        //////////////////////////////////////////////////////////////////////
-        public string XmlName
-        {
-            get { return this.xmlName; }
-        }
-
-        //////////////////////////////////////////////////////////////////////
-        /// <summary>Returns the constant representing this XML 
element.</summary> 
-        //////////////////////////////////////////////////////////////////////
-        public string XmlNameSpace
-        {
-            get { return this.xmlNamespace; }
-        }
-        //////////////////////////////////////////////////////////////////////
-        /// <summary>Returns the constant representing this XML 
element.</summary> 
-        //////////////////////////////////////////////////////////////////////
-        public string XmlPrefix
-        {
-            get { return this.xmlPrefix; }
-        }
-
         /// <summary>
         /// debugging helper
         /// </summary>
@@ -152,7 +119,7 @@
         /// <param name="node">the xml parses node, can be NULL</param>
         /// <returns>the created SimpleElement object</returns>
         //////////////////////////////////////////////////////////////////////
-        public virtual IExtensionElement CreateInstance(XmlNode node) 
+        public override IExtensionElement CreateInstance(XmlNode node) 
         {
             Tracing.TraceCall();
 
@@ -180,87 +147,17 @@
             return e;
         }
 
+        
         /// <summary>
-        /// used to copy the attribute lists over
+        /// saves out the value, get's called from Save
         /// </summary>
-        /// <param name="factory"></param>
-        internal void InitInstance(SimpleElement factory)
+        /// <param name="writer"></param>
+        public override void SaveInnerXml(XmlWriter writer)
         {
-            this.attributes = null;
-            for (int i=0; i < factory.Attributes.Count; i++)
-            {
-                string name = factory.Attributes.GetKey(i) as string;
-                string value = factory.Attributes.GetByIndex(i) as string;
-                this.Attributes.Add(name, value);
-            }
-        }
-
-        /// <summary>
-        /// default method override to handle attribute processing
-        /// the base implementation does process the attributes list
-        /// and reads all that are in there.
-        /// </summary>
-        /// <param name="node">XmlNode with attributes</param>
-        public virtual void ProcessAttributes(XmlNode node)
-        {
-            if (this.attributes != null)
-            {
-                for (int i=0; i < this.Attributes.Count; i++)
-                {
-                    string name = this.Attributes.GetKey(i) as string;
-                    string value = getAttribute(node, name);
-                    if (value != null)
-                    {
-                        this.Attributes[name] = value;
-                    }
-                }
-                return;
-            }
-        }
-
-        /// <summary>
-        /// helper method to extract an attribute as string from
-        /// an xmlnode using the passed in node and the attributename
-        /// </summary>
-        /// <param name="node">node to extract attribute from</param>
-        /// <param name="attributeName">the name of the attribute</param>
-        /// <returns>string - null if attribute is not present</returns>
-        protected string getAttribute(XmlNode node, string attributeName)
-        { 
-            string retValue = null;
-
-            if (node.Attributes != null)
-            {
-                if (node.Attributes[attributeName] != null)
-                {
-                    retValue = node.Attributes[attributeName].Value;
-                }
-            }
-            return retValue;
-        }
-      
-        /// <summary>
-        /// Persistence method for the EnumConstruct object
-        /// </summary>
-        /// <param name="writer">the xmlwriter to write into</param>
-        public virtual void Save(XmlWriter writer)
-        {
-            writer.WriteStartElement(XmlPrefix, XmlName, XmlNameSpace);
-            if (this.attributes != null)
-            {
-                for (int i=0; i < this.Attributes.Count; i++)
-                {
-                    string name = this.Attributes.GetKey(i) as string;
-                    string value = this.Attributes.GetByIndex(i) as string;
-                    writer.WriteAttributeString(name, value);
-                }
-            }
-
             if (this.value != null)
             {
                 writer.WriteString(this.value);
             }
-            writer.WriteEndElement();
         }
         #endregion
     }

Modified: trunk/clients/cs/src/unittests/caltest.cs
==============================================================================
--- trunk/clients/cs/src/unittests/caltest.cs   (original)
+++ trunk/clients/cs/src/unittests/caltest.cs   Wed Sep 12 07:46:41 2007
@@ -458,8 +458,8 @@
                 {
                     // get the first entry
                     EventEntry entry  = new EventEntry();
-                    entry.Title.Text = "Dinner with Sabine, Oct 1st, 10pm";
-                    entry.Title.Type = AtomTextConstructType.html;
+                    entry.Content.Content = "Dinner with Sabine, Oct 1st, 
10pm";
+                    entry.Content.Type = "html";
                     entry.QuickAdd = true;
 
 

Modified: trunk/clients/cs/src/unittests/photostest.cs
==============================================================================
--- trunk/clients/cs/src/unittests/photostest.cs        (original)
+++ trunk/clients/cs/src/unittests/photostest.cs        Wed Sep 12 07:46:41 2007
@@ -245,7 +245,7 @@
                 {
                     DumpSimpleElement(s);
 
-                    SimpleContainer sc = s as SimpleContainer;
+                    SimpleContainer sc = o as SimpleContainer;
 
                     if (sc != null)
                     {

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Data API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-help-dataapi?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to