Made class sealed
[mono.git] / mcs / class / corlib / System.Security.Policy / FirstMatchCodeGroup.cs
1 // System.Security.Policy.FirstMatchCodeGroup
2 //
3 // Author(s):
4 //  Jackson Harper (Jackson@LatitudeGeo.com)
5 //
6
7 using System;
8
9 namespace System.Security.Policy {
10
11         public sealed class FirstMatchCodeGroup : CodeGroup {
12                 
13                 public FirstMatchCodeGroup(IMembershipCondition membershipCondition, PolicyStatement policy) :
14                         base (membershipCondition, policy)
15                 {
16                 }
17
18                 //
19                 // Public Properties
20                 //
21
22                 public override string MergeLogic
23                 {
24                         get { return "First Match"; }
25                 }
26
27                 //
28                 // Public Methods
29                 //
30                 
31                 public override CodeGroup Copy()
32                 {
33                         FirstMatchCodeGroup copy = CopyNoChildren ();
34
35                         foreach (CodeGroup group in Children) {
36                                 copy.AddChild ( group );
37                         }
38
39                         return copy;
40                 }
41
42                 public override PolicyStatement Resolve(Evidence evidence)
43                 {
44                         PolicyStatement policy = null;
45                         PolicyStatement child_policy;
46
47                         if (null == evidence)
48                                 throw new ArgumentNullException ();
49
50                         if (MembershipCondition.Check (evidence)) {
51                                 if (null != PolicyStatement) {
52                                         policy = PolicyStatement;
53                                 } else {
54                                         // Loop through all children breaking on the first one that resolves
55                                         foreach (CodeGroup child in Children) {
56                                                 if (null == (child_policy = child.Resolve (evidence)))
57                                                         continue;
58                                                 policy = child_policy;
59                                                 break;
60                                         }
61                                 }
62                         }
63                         
64                         return policy;
65                 }
66                 
67                 public override CodeGroup ResolveMatchingCodeGroups(Evidence evidence)
68                 {
69                         CodeGroup group = null;
70
71                         if (null == evidence)
72                                 throw new ArgumentNullException ();
73                         
74                         if (MembershipCondition.Check (evidence)) {
75                                 group = CopyNoChildren ();
76                                 
77                                 // Add the first child that resolves
78                                 foreach (CodeGroup child in Children) {
79                                         if ( null == child.Resolve (evidence))
80                                                 continue;
81                                         group.AddChild (child);
82                                         break;
83                                 }
84                         }
85
86                         return group;
87                 }
88         
89                 //
90                 // Private Methods
91                 //
92         
93                 private FirstMatchCodeGroup CopyNoChildren()
94                 {
95                         FirstMatchCodeGroup copy = new FirstMatchCodeGroup (MembershipCondition, PolicyStatement);
96
97                         copy.Name = Name;
98                         copy.Description = Description;
99
100                         return copy;
101                 }
102         }
103
104 }
105