2
// ExtensionNodeType.cs
7
// Copyright (C) 2007 Novell, Inc (http://www.novell.com)
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:
17
// The above copyright notice and this permission notice shall be
18
// included in all copies or substantial portions of the Software.
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.
32
using System.Collections;
33
using System.Collections.Specialized;
34
using Mono.Addins.Serialization;
36
namespace Mono.Addins.Description
38
public class ExtensionNodeType: ExtensionNodeSet
41
string objectTypeName;
44
NodeTypeAttributeCollection attributes;
50
// Cached serializable fields
52
internal Hashtable Fields;
53
internal string[] RequiredFields;
55
// Addin where this extension type is implemented
56
internal string AddinId {
57
get { return addinId; }
58
set { addinId = value; }
61
// Type of the extension node
62
public string TypeName {
63
get { return typeName != null ? typeName : string.Empty; }
64
set { typeName = value; }
67
public string NodeName {
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; }
79
public string Description {
80
get { return description != null ? description : string.Empty; }
81
set { description = value; }
84
public NodeTypeAttributeCollection Attributes {
86
if (attributes == null) {
87
attributes = new NodeTypeAttributeCollection (this);
88
if (Element != null) {
89
XmlElement atts = Element ["Attributes"];
91
foreach (XmlNode node in atts.ChildNodes) {
92
XmlElement e = node as XmlElement;
94
attributes.Add (new NodeTypeAttribute (e));
103
internal ExtensionNodeType (XmlElement element): base (element)
105
XmlAttribute at = element.Attributes ["type"];
108
at = element.Attributes ["objectType"];
110
objectTypeName = at.Value;
111
XmlElement de = element ["Description"];
113
description = de.InnerText;
116
internal ExtensionNodeType ()
120
internal override string IdAttribute {
121
get { return "name"; }
124
internal override void Verify (string location, StringCollection errors)
126
base.Verify (location, errors);
129
internal override void SaveXml (XmlElement parent, string nodeName)
131
base.SaveXml (parent, "ExtensionNode");
133
XmlElement atts = Element ["Attributes"];
134
if (Attributes.Count > 0) {
136
atts = parent.OwnerDocument.CreateElement ("Attributes");
137
Element.AppendChild (atts);
139
Attributes.SaveXml (atts);
142
Element.RemoveChild (atts);
145
if (TypeName.Length > 0)
146
Element.SetAttribute ("type", TypeName);
148
Element.RemoveAttribute ("type");
150
if (ObjectTypeName.Length > 0)
151
Element.SetAttribute ("objectType", ObjectTypeName);
153
Element.RemoveAttribute ("objectType");
155
SaveXmlDescription (Description);
158
internal override void Write (BinaryXmlWriter writer)
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);
172
internal override void Read (BinaryXmlReader 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));