2
0

HandlerFactoryConfiguration.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. Hashtable _cache;
  17. int ownIndex;
  18. public HandlerFactoryConfiguration () : this (null)
  19. {
  20. }
  21. public HandlerFactoryConfiguration (HandlerFactoryConfiguration parent)
  22. {
  23. if (parent != null)
  24. mappings = new ArrayList (parent.mappings);
  25. else
  26. mappings = new ArrayList ();
  27. _cache = Hashtable.Synchronized(new Hashtable());
  28. ownIndex = mappings.Count;
  29. }
  30. public void Add (HandlerItem mapping)
  31. {
  32. mappings.Add (mapping);
  33. }
  34. public HandlerItem Remove (string verb, string path)
  35. {
  36. int i = GetIndex (verb, path);
  37. if (i == -1)
  38. return null;
  39. HandlerItem item = (HandlerItem) mappings [i];
  40. mappings.RemoveAt (i);
  41. if (_cache.ContainsKey(verb+"+"+path))
  42. _cache.Remove(verb+"+"+path);
  43. return item;
  44. }
  45. public void Clear ()
  46. {
  47. mappings.Clear ();
  48. _cache.Clear();
  49. }
  50. public HandlerItem FindHandler (string verb, string path)
  51. {
  52. int i = GetIndex (verb, path);
  53. if (i == -1)
  54. return null;
  55. return (HandlerItem) mappings [i];
  56. }
  57. int GetIndex (string verb, string path)
  58. {
  59. string cahceKey = verb+"+"+path;
  60. object answer = _cache[cahceKey];
  61. if (answer != null)
  62. return (int)answer;
  63. int end = mappings.Count;
  64. for (int i = ownIndex; i < end; i++) {
  65. HandlerItem item = (HandlerItem) mappings [i];
  66. if (item.IsMatch (verb, path))
  67. {
  68. _cache[cahceKey] = i;
  69. return i;
  70. }
  71. }
  72. // parent mappings
  73. end = ownIndex;
  74. for (int i = 0; i < end; i++) {
  75. HandlerItem item = (HandlerItem) mappings [i];
  76. if (item.IsMatch (verb, path))
  77. {
  78. _cache[cahceKey] = i;
  79. return i;
  80. }
  81. }
  82. _cache[cahceKey] = -1;
  83. return -1;
  84. }
  85. }
  86. }