~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/mono-addins/Mono.Addins/Mono.Addins.Description/ObjectDescription.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// ObjectDescription.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.Specialized;
 
32
using System.Xml;
 
33
using Mono.Addins.Serialization;
 
34
 
 
35
namespace Mono.Addins.Description
 
36
{
 
37
        /// <summary>
 
38
        /// Base class for add-in description definitions.
 
39
        /// </summary>
 
40
        public class ObjectDescription: IBinaryXmlElement
 
41
        {
 
42
                internal XmlElement Element;
 
43
                object parent;
 
44
                
 
45
                internal ObjectDescription (XmlElement elem)
 
46
                {
 
47
                        Element = elem;
 
48
                }
 
49
                
 
50
                internal ObjectDescription ()
 
51
                {
 
52
                }
 
53
                
 
54
                /// <summary>
 
55
                /// Gets the parent object.
 
56
                /// </summary>
 
57
                /// <value>
 
58
                /// The parent object.
 
59
                /// </value>
 
60
                public object Parent {
 
61
                        get { return parent; }
 
62
                }
 
63
                
 
64
                /// <summary>
 
65
                /// Gets the parent add-in description.
 
66
                /// </summary>
 
67
                /// <value>
 
68
                /// The parent add-in description.
 
69
                /// </value>
 
70
                public AddinDescription ParentAddinDescription {
 
71
                        get {
 
72
                                if (parent is AddinDescription)
 
73
                                        return (AddinDescription) parent;
 
74
                                else if (parent is ObjectDescription)
 
75
                                        return ((ObjectDescription)parent).ParentAddinDescription;
 
76
                                else
 
77
                                        return null;
 
78
                        }
 
79
                }
 
80
 
 
81
                internal string ParseString (string s)
 
82
                {
 
83
                        var desc = ParentAddinDescription;
 
84
                        if (desc != null)
 
85
                                return desc.ParseString (s);
 
86
                        else
 
87
                                return s;
 
88
                }
 
89
                
 
90
                internal void SetParent (object ob)
 
91
                {
 
92
                        parent = ob;
 
93
                }
 
94
                
 
95
                void IBinaryXmlElement.Write (BinaryXmlWriter writer)
 
96
                {
 
97
                        Write (writer);
 
98
                }
 
99
                
 
100
                void IBinaryXmlElement.Read (BinaryXmlReader reader)
 
101
                {
 
102
                        Read (reader);
 
103
                }
 
104
                
 
105
                internal virtual void Write (BinaryXmlWriter writer)
 
106
                {
 
107
                }
 
108
                
 
109
                internal virtual void Read (BinaryXmlReader reader)
 
110
                {
 
111
                }
 
112
                
 
113
                internal virtual void SaveXml (XmlElement parent)
 
114
                {
 
115
                }
 
116
                
 
117
                internal void CreateElement (XmlElement parent, string nodeName)
 
118
                {
 
119
                        if (Element == null) {
 
120
                                Element = parent.OwnerDocument.CreateElement (nodeName); 
 
121
                                parent.AppendChild (Element);
 
122
                        }
 
123
                }
 
124
                
 
125
                internal string ReadXmlDescription ()
 
126
                {
 
127
                        XmlElement de = Element ["Description"];
 
128
                        if (de != null)
 
129
                                return de.InnerText;
 
130
                        else
 
131
                                return null;
 
132
                }
 
133
                
 
134
                internal void SaveXmlDescription (string desc)
 
135
                {
 
136
                        XmlElement de = Element ["Description"];
 
137
                        if (desc != null && desc.Length > 0) {
 
138
                                if (de == null) {
 
139
                                        de = Element.OwnerDocument.CreateElement ("Description");
 
140
                                        Element.AppendChild (de);
 
141
                                }
 
142
                                de.InnerText = desc;
 
143
                        } else {
 
144
                                if (de != null)
 
145
                                        Element.RemoveChild (de);
 
146
                        }
 
147
                }
 
148
                
 
149
                internal virtual void Verify (string location, StringCollection errors)
 
150
                {
 
151
                }
 
152
                
 
153
                internal void VerifyNotEmpty (string location, StringCollection errors, string attr, string val)
 
154
                {
 
155
                        if (val == null || val.Length == 0)
 
156
                                errors.Add (location + ": attribute '" + attr + "' can't be empty.");
 
157
                }
 
158
        }
 
159
}