~ifolder-dev/simias/trunk-packaging

« back to all changes in this revision

Viewing changes to src/core/StoreProvider/.svn/text-base/Record.cs.svn-base

  • Committer: Jorge O. Castro
  • Date: 2007-12-03 06:56:46 UTC
  • Revision ID: jorge@ubuntu.com-20071203065646-mupcnjcwgm5mnhyt
* Remove a bunch of .svn directories we no longer need.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/****************************************************************************
2
 
 |
3
 
 | Copyright (c) 2007 Novell, Inc.
4
 
 | All Rights Reserved.
5
 
 |
6
 
 | This program is free software; you can redistribute it and/or
7
 
 | modify it under the terms of version 2 of the GNU General Public License as
8
 
 | published by the Free Software Foundation.
9
 
 |
10
 
 | This program is distributed in the hope that it will be useful,
11
 
 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 | GNU General Public License for more details.
14
 
 |
15
 
 | You should have received a copy of the GNU General Public License
16
 
 | along with this program; if not, contact Novell, Inc.
17
 
 |
18
 
 | To contact Novell about this file by physical or electronic mail,
19
 
 | you may find current contact information at www.novell.com 
20
 
 |
21
 
 | Author: Russ Young
22
 
 |***************************************************************************/
23
 
 
24
 
 
25
 
using System;
26
 
using System.Xml;
27
 
using System.Collections;
28
 
 
29
 
namespace Simias.Storage.Provider
30
 
{
31
 
        /// <summary>
32
 
        /// Represents a Collection Store Provider record.
33
 
        /// </summary>
34
 
        public class Record : IEnumerable
35
 
        {
36
 
                private XmlElement recordEl;
37
 
                /// <summary>
38
 
                /// The Name of the Record.
39
 
                /// </summary>
40
 
                public string Name;
41
 
                /// <summary>
42
 
                /// The ID of the Record.
43
 
                /// </summary>
44
 
                public string Id;
45
 
                /// <summary>
46
 
                /// The type of the Record.
47
 
                /// </summary>
48
 
                public string Type;
49
 
                
50
 
                /// <summary>
51
 
                /// Creates a Record from an XML Element. Can be used to enumerate
52
 
                /// the Properties contained in this record.
53
 
                /// </summary>
54
 
                /// <param name="recordXml">The XML Element that describes the Record.</param>
55
 
                public Record(XmlElement recordXml)
56
 
                {
57
 
                        recordEl = recordXml;
58
 
 
59
 
                        // Get the Name, ID, and type.
60
 
                        Name = recordEl.GetAttribute(XmlTags.NameAttr);
61
 
                        Id = recordEl.GetAttribute(XmlTags.IdAttr);
62
 
                        Type = recordEl.GetAttribute(XmlTags.TypeAttr);
63
 
                
64
 
                        // Make sure this is a valid record.
65
 
                        if (Name == null || Id == null || Type == null)
66
 
                        {
67
 
                                throw new FormatException();
68
 
                        }
69
 
                }
70
 
 
71
 
                /// <summary>
72
 
                /// Creates a Record from the strings.
73
 
                /// </summary>
74
 
                /// <param name="name">The name of the Record</param>
75
 
                /// <param name="id">The ID of the Record.</param>
76
 
                /// <param name="type">The type of the Record.</param>
77
 
                public Record(string name, string id, string type)
78
 
                {
79
 
                        recordEl = null;
80
 
                        Name = name;
81
 
                        Id = id;
82
 
                        Type = type;
83
 
                }
84
 
 
85
 
                /// <summary>
86
 
                /// Called to get an XML node for this Record.  This node does not include
87
 
                /// the property nodes.
88
 
                /// </summary>
89
 
                /// <param name="doc">The document that the XML node belongs to.</param>
90
 
                /// <returns>The XmlElement representing this Record.</returns>
91
 
                public XmlElement ToXml(XmlDocument doc)
92
 
                {
93
 
                        recordEl = doc.CreateElement(XmlTags.ObjectTag);
94
 
                        recordEl.SetAttribute(XmlTags.NameAttr, Name);
95
 
                        recordEl.SetAttribute(XmlTags.IdAttr, Id);
96
 
                        recordEl.SetAttribute(XmlTags.TypeAttr, Type);
97
 
                        return recordEl;
98
 
                }
99
 
 
100
 
                #region IEnumerable Members
101
 
 
102
 
                /// <summary>
103
 
                /// Gets the Property enumerator of this Record.
104
 
                /// </summary>
105
 
                /// <returns></returns>
106
 
                public IEnumerator GetEnumerator()
107
 
                {
108
 
                        return (new PropertyEnumerator(recordEl.SelectNodes(XmlTags.PropertyTag)));
109
 
                }
110
 
 
111
 
                #endregion
112
 
        }
113
 
 
114
 
        /// <summary>
115
 
        /// Class to enumerate through properties of a record.
116
 
        /// </summary>
117
 
        public class PropertyEnumerator : IEnumerator
118
 
        {
119
 
                IEnumerator     properties;
120
 
 
121
 
                /// <summary>
122
 
                /// Exposes an XmlNodeList as Properties.
123
 
                /// </summary>
124
 
                /// <param name="pList"></param>
125
 
                public PropertyEnumerator(XmlNodeList pList)
126
 
                {
127
 
                        properties = pList.GetEnumerator();
128
 
                }
129
 
 
130
 
                #region IEnumerator Members
131
 
 
132
 
                /// <summary>
133
 
                /// Sets the enumerator to its initial position, which is before the first Property in the collection.
134
 
                /// </summary>
135
 
                public void Reset()
136
 
                {
137
 
                        properties.Reset();
138
 
                }
139
 
 
140
 
                /// <summary>
141
 
                /// Gets the current Property in the collection.
142
 
                /// </summary>
143
 
                public object Current
144
 
                {
145
 
                        get
146
 
                        {
147
 
                                return new Property((XmlElement)properties.Current);
148
 
                        }
149
 
                }
150
 
 
151
 
                /// <summary>
152
 
                /// Advances the enumerator to the next Property in the collection.
153
 
                /// </summary>
154
 
                /// <returns></returns>
155
 
                public bool MoveNext()
156
 
                {
157
 
                        return properties.MoveNext();
158
 
                }
159
 
 
160
 
                #endregion
161
 
        }
162
 
 
163
 
        #region Property class
164
 
 
165
 
        /// <summary>
166
 
        /// Class to convert a property to and from XML.
167
 
        /// </summary>
168
 
        public class Property
169
 
        {
170
 
                private XmlElement property;
171
 
                /// <summary>
172
 
                /// Property Name.
173
 
                /// </summary>
174
 
                public string Name;
175
 
                /// <summary>
176
 
                /// Property Type.
177
 
                /// </summary>
178
 
                public string Type;
179
 
                /// <summary>
180
 
                /// Property Value.
181
 
                /// </summary>
182
 
                public string Value;
183
 
                /// <summary>
184
 
                /// Property Flags.
185
 
                /// </summary>
186
 
                public string Flags;
187
 
        
188
 
                /// <summary>
189
 
                /// Creates a Property from an XML element.
190
 
                /// </summary>
191
 
                /// <param name="propertyEl">The XML element for this Property.</param>
192
 
                public Property(XmlElement propertyEl)
193
 
                {
194
 
                        property = propertyEl;
195
 
                        Name = property.GetAttribute(XmlTags.NameAttr);
196
 
                        Type = property.GetAttribute(XmlTags.TypeAttr);
197
 
                        Value = property.InnerXml;
198
 
                        Flags = property.GetAttribute(XmlTags.FlagsAttr);
199
 
                        if (string.Empty == Flags)
200
 
                        {
201
 
                                Flags = "0";
202
 
                        }
203
 
                }
204
 
 
205
 
                /// <summary>
206
 
                /// Called to create an XML node that represents a property.
207
 
                /// </summary>
208
 
                /// <param name="doc">The document the XML node belongs to.</param>
209
 
                /// <param name="Name">The name of the property.</param>
210
 
                /// <param name="Type">The type of the property.</param>
211
 
                /// <param name="Flags">The flags of the property.</param>
212
 
                /// <param name="Value">The value of the property.</param>
213
 
                /// <returns>The created XMLElement.</returns>
214
 
                public static XmlElement CreateXmlNode(XmlDocument doc, string Name, string Type, string Flags, string Value)
215
 
                {
216
 
                        XmlElement node = doc.CreateElement(XmlTags.PropertyTag);
217
 
                        node.SetAttribute(XmlTags.NameAttr, Name);
218
 
                        node.SetAttribute(XmlTags.TypeAttr, Type);
219
 
                        node.SetAttribute(XmlTags.FlagsAttr, Flags);
220
 
                        node.InnerXml = Value;
221
 
                        return node;
222
 
                }
223
 
        }
224
 
 
225
 
        #endregion
226
 
}