~ubuntu-branches/ubuntu/karmic/mono-addins/karmic

« back to all changes in this revision

Viewing changes to Mono.Addins/Mono.Addins.Description/ExtensionNodeType.cs

  • Committer: Bazaar Package Importer
  • Author(s): Mirco Bauer
  • Date: 2007-07-14 12:07:48 UTC
  • Revision ID: james.westby@ubuntu.com-20070714120748-2elczfsjlrdsrpms
Tags: upstream-0.2
ImportĀ upstreamĀ versionĀ 0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// ExtensionNodeType.cs
 
3
//
 
4
// Author:
 
5
//   Lluis Sanchez Gual
 
6
//
 
7
// Copyright (C) 2007 Novell, Inc (http://www.novell.com)
 
8
//
 
9
// Permission is hereby granted, free of charge, to any person obtaining
 
10
// a copy of this software and associated documentation files (the
 
11
// "Software"), to deal in the Software without restriction, including
 
12
// without limitation the rights to use, copy, modify, merge, publish,
 
13
// distribute, sublicense, and/or sell copies of the Software, and to
 
14
// permit persons to whom the Software is furnished to do so, subject to
 
15
// the following conditions:
 
16
// 
 
17
// The above copyright notice and this permission notice shall be
 
18
// included in all copies or substantial portions of the Software.
 
19
// 
 
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
27
//
 
28
 
 
29
 
 
30
using System;
 
31
using System.Xml;
 
32
using System.Collections;
 
33
using System.Collections.Specialized;
 
34
using Mono.Addins.Serialization;
 
35
 
 
36
namespace Mono.Addins.Description
 
37
{
 
38
        public class ExtensionNodeType: ExtensionNodeSet
 
39
        {
 
40
                string typeName;
 
41
                string objectTypeName;
 
42
                string description;
 
43
                string addinId;
 
44
                NodeTypeAttributeCollection attributes;
 
45
                
 
46
                // Cached clr type
 
47
                [NonSerialized]
 
48
                internal Type Type;
 
49
                
 
50
                // Cached serializable fields
 
51
                [NonSerialized]
 
52
                internal Hashtable Fields;
 
53
                internal string[] RequiredFields;
 
54
                
 
55
                // Addin where this extension type is implemented
 
56
                internal string AddinId {
 
57
                        get { return addinId; }
 
58
                        set { addinId = value; }
 
59
                }
 
60
                
 
61
                // Type of the extension node
 
62
                public string TypeName {
 
63
                        get { return typeName != null ? typeName : string.Empty; }
 
64
                        set { typeName = value; }
 
65
                }
 
66
                
 
67
                public string NodeName {
 
68
                        get { return Id; }
 
69
                        set { Id = value; }
 
70
                }
 
71
                
 
72
                // Type of the object that the extension creates (only valid for TypeNodeExtension).
 
73
                public string ObjectTypeName {
 
74
                        get { return objectTypeName != null ? objectTypeName : string.Empty; }
 
75
                        set { objectTypeName = value; }
 
76
                }
 
77
                
 
78
                // The description
 
79
                public string Description {
 
80
                        get { return description != null ? description : string.Empty; }
 
81
                        set { description = value; }
 
82
                }
 
83
                
 
84
                public NodeTypeAttributeCollection Attributes {
 
85
                        get {
 
86
                                if (attributes == null) {
 
87
                                        attributes = new NodeTypeAttributeCollection (this);
 
88
                                        if (Element != null) {
 
89
                                                XmlElement atts = Element ["Attributes"];
 
90
                                                if (atts != null) {
 
91
                                                        foreach (XmlNode node in atts.ChildNodes) {
 
92
                                                                XmlElement e = node as XmlElement;
 
93
                                                                if (e != null)
 
94
                                                                        attributes.Add (new NodeTypeAttribute (e));
 
95
                                                        }
 
96
                                                }
 
97
                                        }
 
98
                                }
 
99
                                return attributes;
 
100
                        }
 
101
                }
 
102
 
 
103
                internal ExtensionNodeType (XmlElement element): base (element)
 
104
                {
 
105
                        XmlAttribute at = element.Attributes ["type"];
 
106
                        if (at != null)
 
107
                                typeName = at.Value;
 
108
                        at = element.Attributes ["objectType"];
 
109
                        if (at != null)
 
110
                                objectTypeName = at.Value;
 
111
                        XmlElement de = element ["Description"];
 
112
                        if (de != null)
 
113
                                description = de.InnerText;
 
114
                }
 
115
                
 
116
                internal ExtensionNodeType ()
 
117
                {
 
118
                }
 
119
                        
 
120
                internal override string IdAttribute {
 
121
                        get { return "name"; }
 
122
                }
 
123
                
 
124
                internal override void Verify (string location, StringCollection errors)
 
125
                {
 
126
                        base.Verify (location, errors);
 
127
                }
 
128
                
 
129
                internal override void SaveXml (XmlElement parent, string nodeName)
 
130
                {
 
131
                        base.SaveXml (parent, "ExtensionNode");
 
132
                        
 
133
                        XmlElement atts = Element ["Attributes"];
 
134
                        if (Attributes.Count > 0) {
 
135
                                if (atts == null) {
 
136
                                        atts = parent.OwnerDocument.CreateElement ("Attributes");
 
137
                                        Element.AppendChild (atts);
 
138
                                }
 
139
                                Attributes.SaveXml (atts);
 
140
                        } else {
 
141
                                if (atts != null)
 
142
                                        Element.RemoveChild (atts);
 
143
                        }
 
144
                        
 
145
                        if (TypeName.Length > 0)
 
146
                                Element.SetAttribute ("type", TypeName);
 
147
                        else
 
148
                                Element.RemoveAttribute ("type");
 
149
                        
 
150
                        if (ObjectTypeName.Length > 0)
 
151
                                Element.SetAttribute ("objectType", ObjectTypeName);
 
152
                        else
 
153
                                Element.RemoveAttribute ("objectType");
 
154
 
 
155
                        SaveXmlDescription (Description);
 
156
                }
 
157
                
 
158
                internal override void Write (BinaryXmlWriter writer)
 
159
                {
 
160
                        base.Write (writer);
 
161
                        if (Id.Length == 0)
 
162
                                Id = "Type";
 
163
                        if (TypeName.Length == 0)
 
164
                                typeName = "Mono.Addins.TypeExtensionNode";
 
165
                        writer.WriteValue ("typeName", typeName);
 
166
                        writer.WriteValue ("objectTypeName", objectTypeName);
 
167
                        writer.WriteValue ("description", description);
 
168
                        writer.WriteValue ("addinId", addinId);
 
169
                        writer.WriteValue ("Attributes", attributes);
 
170
                }
 
171
                
 
172
                internal override void Read (BinaryXmlReader reader)
 
173
                {
 
174
                        base.Read (reader);
 
175
                        typeName = reader.ReadStringValue ("typeName");
 
176
                        objectTypeName = reader.ReadStringValue ("objectTypeName");
 
177
                        if (!reader.IgnoreDescriptionData)
 
178
                                description = reader.ReadStringValue ("description");
 
179
                        addinId = reader.ReadStringValue ("addinId");
 
180
                        if (!reader.IgnoreDescriptionData)
 
181
                                attributes = (NodeTypeAttributeCollection) reader.ReadValue ("Attributes", new NodeTypeAttributeCollection (this));
 
182
                }
 
183
        }
 
184
}