2002-10-08 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[mono.git] / mcs / class / System.Web / System.Web.Configuration / HandlerFactoryConfiguration.cs
1 // 
2 // System.Web.Configuration.HandlerFactoryConfiguration
3 //
4 // Authors:
5 //      Patrik Torstensson (ptorsten@hotmail.com)
6 //      Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 //
8 // (C) 2002 Ximian, Inc (http://www.ximian.com)
9 //
10
11 using System.Collections;
12
13 namespace System.Web.Configuration
14 {
15         class HandlerFactoryConfiguration
16         {
17                 ArrayList mappings;
18
19                 public HandlerFactoryConfiguration () : this (null)
20                 {
21                 }
22
23                 public HandlerFactoryConfiguration (HandlerFactoryConfiguration parent)
24                 {
25                         if (parent != null)
26                                 mappings = new ArrayList (parent.mappings);
27                         else
28                                 mappings = new ArrayList ();
29                 }
30
31                 public void Add (HandlerItem mapping)
32                 {
33                         mappings.Add (mapping);
34                 }
35
36                 public HandlerItem Remove (string verb, string path)
37                 {
38                         int i = GetIndex (verb, path);
39                         if (i == -1)
40                                 return null;
41                         
42                         HandlerItem item = (HandlerItem) mappings [i];
43                         mappings.RemoveAt (i);
44                         return item;
45                 }
46
47                 public void Clear ()
48                 {
49                         mappings.Clear ();
50                 }
51
52                 public HandlerItem FindHandler (string verb, string path)
53                 {
54                         int i = GetIndex (verb, path);
55                         if (i == -1)
56                                 return null;
57
58                         return (HandlerItem) mappings [i];
59                 }
60
61                 int GetIndex (string verb, string path)
62                 {
63                         int end = mappings.Count;
64
65                         for (int i = 0; i < end; i++) {
66                                 HandlerItem item = (HandlerItem) mappings [i];
67                                 if (item.IsMatch (verb, path))
68                                         return i;
69                         }
70
71                         return -1;
72                 }
73         }
74 }
75