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

« back to all changes in this revision

Viewing changes to Mono.Addins/Mono.Addins.Description/ExtensionPoint.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
// ExtensionPoint.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.Collections;
 
32
using System.Xml;
 
33
using Mono.Addins.Serialization;
 
34
using System.Collections.Specialized;
 
35
 
 
36
namespace Mono.Addins.Description
 
37
{
 
38
        public class ExtensionPoint: ObjectDescription
 
39
        {
 
40
                string path;
 
41
                string name;
 
42
                string description;
 
43
                ExtensionNodeSet nodeSet;
 
44
                ConditionTypeDescriptionCollection conditions;
 
45
                
 
46
                // Information gathered from others addins:
 
47
                
 
48
                StringCollection addins;        // Add-ins which extend this extension point
 
49
                string rootAddin;                       // Add-in which defines this extension point
 
50
                
 
51
                internal ExtensionPoint (XmlElement elem): base (elem)
 
52
                {
 
53
                        path = elem.GetAttribute ("path");
 
54
                        name = elem.GetAttribute ("name");
 
55
                        description = ReadXmlDescription ();
 
56
                }
 
57
                
 
58
                public ExtensionPoint ()
 
59
                {
 
60
                }
 
61
                
 
62
                internal override void Verify (string location, StringCollection errors)
 
63
                {
 
64
                        VerifyNotEmpty (location + "ExtensionPoint", errors, Path, "path");
 
65
                        NodeSet.Verify (location + "ExtensionPoint (" + Path + ")/", errors);
 
66
                        Conditions.Verify (location + "ExtensionPoint (" + Path + ")/", errors);
 
67
                }
 
68
                
 
69
                internal void SetExtensionsAddinId (string addinId)
 
70
                {
 
71
                        NodeSet.SetExtensionsAddinId (addinId);
 
72
                        foreach (ConditionTypeDescription cond in Conditions)
 
73
                                cond.AddinId = addinId;
 
74
                        Addins.Add (addinId);
 
75
                }
 
76
                
 
77
                internal void MergeWith (string thisAddinId, ExtensionPoint ep)
 
78
                {
 
79
                        NodeSet.MergeWith (thisAddinId, ep.NodeSet);
 
80
                        
 
81
                        foreach (ConditionTypeDescription cond in ep.Conditions) {
 
82
                                if (cond.AddinId != thisAddinId && !Conditions.Contains (cond))
 
83
                                        Conditions.Add (cond);
 
84
                        }
 
85
                        foreach (string s in ep.Addins) {
 
86
                                if (!Addins.Contains (s))
 
87
                                        Addins.Add (s);
 
88
                        }
 
89
                }
 
90
                
 
91
                internal void UnmergeExternalData (string thisAddinId, Hashtable addinsToUnmerge)
 
92
                {
 
93
                        NodeSet.UnmergeExternalData (thisAddinId, addinsToUnmerge);
 
94
                        
 
95
                        ArrayList todel = new ArrayList ();
 
96
                        foreach (ConditionTypeDescription cond in Conditions) {
 
97
                                if (cond.AddinId != thisAddinId && (addinsToUnmerge == null || addinsToUnmerge.Contains (cond.AddinId)))
 
98
                                        todel.Add (cond);
 
99
                        }
 
100
                        foreach (ConditionTypeDescription cond in todel)
 
101
                                Conditions.Remove (cond);
 
102
                        
 
103
                        if (addinsToUnmerge == null)
 
104
                                Addins.Clear ();
 
105
                        else {
 
106
                                foreach (string s in addinsToUnmerge.Keys)
 
107
                                        Addins.Remove (s);
 
108
                        }
 
109
                        if (thisAddinId != null && !Addins.Contains (thisAddinId))
 
110
                                Addins.Add (thisAddinId);
 
111
                }
 
112
                
 
113
                internal void Clear ()
 
114
                {
 
115
                        NodeSet.Clear ();
 
116
                        Conditions.Clear ();
 
117
                        Addins.Clear ();
 
118
                }
 
119
                
 
120
                internal override void SaveXml (XmlElement parent)
 
121
                {
 
122
                        CreateElement (parent, "ExtensionPoint"); 
 
123
                        
 
124
                        Element.SetAttribute ("path", Path);
 
125
                        
 
126
                        if (Name.Length > 0)
 
127
                                Element.SetAttribute ("name", Name);
 
128
                        else
 
129
                                Element.RemoveAttribute ("name");
 
130
                                
 
131
                        SaveXmlDescription (Description);
 
132
                        
 
133
                        if (nodeSet != null) {
 
134
                                nodeSet.Element = Element;
 
135
                                nodeSet.SaveXml (parent);
 
136
                        }
 
137
                }
 
138
                
 
139
                public string Path {
 
140
                        get { return path != null ? path : string.Empty; }
 
141
                        set { path = value; }
 
142
                }
 
143
                
 
144
                public string Name {
 
145
                        get { return name != null ? name : string.Empty; }
 
146
                        set { name = value; }
 
147
                }
 
148
                
 
149
                public string Description {
 
150
                        get { return description != null ? description : string.Empty; }
 
151
                        set { description = value; }
 
152
                }
 
153
                
 
154
                internal StringCollection Addins {
 
155
                        get {
 
156
                                if (addins == null)
 
157
                                        addins = new StringCollection ();
 
158
                                return addins;
 
159
                        }
 
160
                }
 
161
                
 
162
                internal string RootAddin {
 
163
                        get { return rootAddin; }
 
164
                        set { rootAddin = value; }
 
165
                }
 
166
                
 
167
                public ExtensionNodeSet NodeSet {
 
168
                        get {
 
169
                                if (nodeSet == null) {
 
170
                                        if (Element != null)
 
171
                                                nodeSet = new ExtensionNodeSet (Element);
 
172
                                        else
 
173
                                                nodeSet = new ExtensionNodeSet ();
 
174
                                        nodeSet.SetParent (this);
 
175
                                }
 
176
                                return nodeSet;
 
177
                        }
 
178
                }
 
179
                
 
180
                internal void SetNodeSet (ExtensionNodeSet nset)
 
181
                {
 
182
                        // Used only by the addin updater
 
183
                        nodeSet = nset;
 
184
                        nodeSet.SetParent (this);
 
185
                }
 
186
                
 
187
                public ConditionTypeDescriptionCollection Conditions {
 
188
                        get {
 
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));
 
194
                                        }
 
195
                                }
 
196
                                return conditions;
 
197
                        }
 
198
                }
 
199
                
 
200
                public ExtensionNodeType AddExtensionNode (string name, string typeName)
 
201
                {
 
202
                        ExtensionNodeType ntype = new ExtensionNodeType ();
 
203
                        ntype.Id = name;
 
204
                        ntype.TypeName = typeName;
 
205
                        NodeSet.NodeTypes.Add (ntype);
 
206
                        return ntype;
 
207
                }
 
208
                
 
209
                internal override void Write (BinaryXmlWriter writer)
 
210
                {
 
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);
 
218
                }
 
219
                
 
220
                internal override void Read (BinaryXmlReader reader)
 
221
                {
 
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));
 
230
                        if (nodeSet != null)
 
231
                                nodeSet.SetParent (this);
 
232
                }
 
233
        }
 
234
}