1 // System.Security.Policy.FirstMatchCodeGroup
4 // Jackson Harper (Jackson@LatitudeGeo.com)
9 namespace System.Security.Policy {
11 public sealed class FirstMatchCodeGroup : CodeGroup {
13 public FirstMatchCodeGroup(IMembershipCondition membershipCondition, PolicyStatement policy) :
14 base (membershipCondition, policy)
22 public override string MergeLogic
24 get { return "First Match"; }
31 public override CodeGroup Copy()
33 FirstMatchCodeGroup copy = CopyNoChildren ();
35 foreach (CodeGroup group in Children) {
36 copy.AddChild ( group );
42 public override PolicyStatement Resolve(Evidence evidence)
44 PolicyStatement policy = null;
45 PolicyStatement child_policy;
48 throw new ArgumentNullException ();
50 if (MembershipCondition.Check (evidence)) {
51 if (null != PolicyStatement) {
52 policy = PolicyStatement;
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)))
58 policy = child_policy;
67 public override CodeGroup ResolveMatchingCodeGroups(Evidence evidence)
69 CodeGroup group = null;
72 throw new ArgumentNullException ();
74 if (MembershipCondition.Check (evidence)) {
75 group = CopyNoChildren ();
77 // Add the first child that resolves
78 foreach (CodeGroup child in Children) {
79 if ( null == child.Resolve (evidence))
81 group.AddChild (child);
93 private FirstMatchCodeGroup CopyNoChildren()
95 FirstMatchCodeGroup copy = new FirstMatchCodeGroup (MembershipCondition, PolicyStatement);
98 copy.Description = Description;