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.
31
using System.Collections;
33
using Mono.Addins.Serialization;
34
using System.Collections.Specialized;
36
namespace Mono.Addins.Description
38
public class ExtensionPoint: ObjectDescription
43
ExtensionNodeSet nodeSet;
44
ConditionTypeDescriptionCollection conditions;
46
// Information gathered from others addins:
48
StringCollection addins; // Add-ins which extend this extension point
49
string rootAddin; // Add-in which defines this extension point
51
internal ExtensionPoint (XmlElement elem): base (elem)
53
path = elem.GetAttribute ("path");
54
name = elem.GetAttribute ("name");
55
description = ReadXmlDescription ();
58
public ExtensionPoint ()
62
internal override void Verify (string location, StringCollection errors)
64
VerifyNotEmpty (location + "ExtensionPoint", errors, Path, "path");
65
NodeSet.Verify (location + "ExtensionPoint (" + Path + ")/", errors);
66
Conditions.Verify (location + "ExtensionPoint (" + Path + ")/", errors);
69
internal void SetExtensionsAddinId (string addinId)
71
NodeSet.SetExtensionsAddinId (addinId);
72
foreach (ConditionTypeDescription cond in Conditions)
73
cond.AddinId = addinId;
77
internal void MergeWith (string thisAddinId, ExtensionPoint ep)
79
NodeSet.MergeWith (thisAddinId, ep.NodeSet);
81
foreach (ConditionTypeDescription cond in ep.Conditions) {
82
if (cond.AddinId != thisAddinId && !Conditions.Contains (cond))
83
Conditions.Add (cond);
85
foreach (string s in ep.Addins) {
86
if (!Addins.Contains (s))
91
internal void UnmergeExternalData (string thisAddinId, Hashtable addinsToUnmerge)
93
NodeSet.UnmergeExternalData (thisAddinId, addinsToUnmerge);
95
ArrayList todel = new ArrayList ();
96
foreach (ConditionTypeDescription cond in Conditions) {
97
if (cond.AddinId != thisAddinId && (addinsToUnmerge == null || addinsToUnmerge.Contains (cond.AddinId)))
100
foreach (ConditionTypeDescription cond in todel)
101
Conditions.Remove (cond);
103
if (addinsToUnmerge == null)
106
foreach (string s in addinsToUnmerge.Keys)
109
if (thisAddinId != null && !Addins.Contains (thisAddinId))
110
Addins.Add (thisAddinId);
113
internal void Clear ()
120
internal override void SaveXml (XmlElement parent)
122
CreateElement (parent, "ExtensionPoint");
124
Element.SetAttribute ("path", Path);
127
Element.SetAttribute ("name", Name);
129
Element.RemoveAttribute ("name");
131
SaveXmlDescription (Description);
133
if (nodeSet != null) {
134
nodeSet.Element = Element;
135
nodeSet.SaveXml (parent);
140
get { return path != null ? path : string.Empty; }
141
set { path = value; }
145
get { return name != null ? name : string.Empty; }
146
set { name = value; }
149
public string Description {
150
get { return description != null ? description : string.Empty; }
151
set { description = value; }
154
internal StringCollection Addins {
157
addins = new StringCollection ();
162
internal string RootAddin {
163
get { return rootAddin; }
164
set { rootAddin = value; }
167
public ExtensionNodeSet NodeSet {
169
if (nodeSet == null) {
171
nodeSet = new ExtensionNodeSet (Element);
173
nodeSet = new ExtensionNodeSet ();
174
nodeSet.SetParent (this);
180
internal void SetNodeSet (ExtensionNodeSet nset)
182
// Used only by the addin updater
184
nodeSet.SetParent (this);
187
public ConditionTypeDescriptionCollection Conditions {
189
if (conditions == null) {
190
conditions = new ConditionTypeDescriptionCollection (this);
191
if (Element != null) {
192
foreach (XmlElement elem in Element.SelectNodes ("ConditionType"))
193
conditions.Add (new ConditionTypeDescription (elem));
200
public ExtensionNodeType AddExtensionNode (string name, string typeName)
202
ExtensionNodeType ntype = new ExtensionNodeType ();
204
ntype.TypeName = typeName;
205
NodeSet.NodeTypes.Add (ntype);
209
internal override void Write (BinaryXmlWriter writer)
211
writer.WriteValue ("path", path);
212
writer.WriteValue ("name", name);
213
writer.WriteValue ("description", Description);
214
writer.WriteValue ("rootAddin", rootAddin);
215
writer.WriteValue ("addins", Addins);
216
writer.WriteValue ("NodeSet", NodeSet);
217
writer.WriteValue ("Conditions", Conditions);
220
internal override void Read (BinaryXmlReader reader)
222
path = reader.ReadStringValue ("path");
223
name = reader.ReadStringValue ("name");
224
if (!reader.IgnoreDescriptionData)
225
description = reader.ReadStringValue ("description");
226
rootAddin = reader.ReadStringValue ("rootAddin");
227
addins = (StringCollection) reader.ReadValue ("addins", new StringCollection ());
228
nodeSet = (ExtensionNodeSet) reader.ReadValue ("NodeSet");
229
conditions = (ConditionTypeDescriptionCollection) reader.ReadValue ("Conditions", new ConditionTypeDescriptionCollection (this));
231
nodeSet.SetParent (this);