This commit was manufactured by cvs2svn to create branch 'mono-1-0'.
[mono.git] / mcs / class / corlib / System.Security / NamedPermissionSet.cs
1 //
2 // System.Security.NamedPermissionSet
3 //
4 // Authors:
5 //      Dan Lewis (dihlewis@yahoo.co.uk)
6 //      Sebastien Pouliot (spouliot@motus.com)
7 //
8 // (C) 2002
9 // Portions (C) 2003, 2004 Motus Technologies Inc. (http://www.motus.com)
10 //
11
12 //
13 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
14 //
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
22 // 
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
25 // 
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 //
34
35 //
36 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
37 //
38 // Permission is hereby granted, free of charge, to any person obtaining
39 // a copy of this software and associated documentation files (the
40 // "Software"), to deal in the Software without restriction, including
41 // without limitation the rights to use, copy, modify, merge, publish,
42 // distribute, sublicense, and/or sell copies of the Software, and to
43 // permit persons to whom the Software is furnished to do so, subject to
44 // the following conditions:
45 // 
46 // The above copyright notice and this permission notice shall be
47 // included in all copies or substantial portions of the Software.
48 // 
49 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
50 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
51 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
52 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
53 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
54 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
55 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
56 //
57
58 using System;
59 using System.Security.Permissions;
60
61 namespace System.Security {
62         
63         [Serializable]
64         public sealed class NamedPermissionSet : PermissionSet {
65
66                 // for PolicyLevel (to avoid validation duplication)
67                 internal NamedPermissionSet () : base () {}
68
69                 public NamedPermissionSet (string name, PermissionSet set) : base (set) 
70                 {
71                         Name = name;
72                 }
73
74                 public NamedPermissionSet (string name, PermissionState state) : base (state) 
75                 {
76                         Name = name;
77                 }
78
79                 public NamedPermissionSet (NamedPermissionSet set) : this (set.name, set) {}
80
81                 public NamedPermissionSet (string name) : this (name, PermissionState.None) {}
82
83                 // properties
84
85                 public string Description {
86                         get { return description; }
87                         set { description = value; }
88                 }
89
90                 public string Name {
91                         get { return name; }
92                         set { 
93                                 if ((value == null) || (value == String.Empty)) 
94                                         throw new ArgumentException ("invalid name");
95                                 name = value; 
96                         }
97                 }
98
99                 public override PermissionSet Copy () 
100                 {
101                         return new NamedPermissionSet (this);
102                 }
103
104                 public NamedPermissionSet Copy (string name) 
105                 {
106                         NamedPermissionSet nps = new NamedPermissionSet (this);
107                         nps.Name = name;
108                         return nps;
109                 }
110
111                 public override void FromXml (SecurityElement e) 
112                 {
113                         FromXml (e, "NamedPermissionSet");
114                         Name = (e.Attributes ["Name"] as string);
115                         description = (e.Attributes ["Description"] as string);
116                         if (description == null)
117                                 description = String.Empty;
118                 }
119
120                 public override SecurityElement ToXml () 
121                 {
122                         SecurityElement se = base.ToXml ();
123                         if (name != null)
124                                 se.AddAttribute ("Name", name);
125                         if (description != null)
126                                 se.AddAttribute ("Description", description);
127                         return se;
128                 }
129
130                 // private
131
132                 private string name;
133                 private string description;
134         }
135 }