HandlerFactoryConfiguration.cs 1.6 KB

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