XmlMappingDictionary.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. //
  2. // System.Xml.Query.XmlMappingDictionary
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // (C)2004 Novell Inc.
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. #if NET_2_0
  30. namespace System.Xml.Query
  31. {
  32. public sealed class XmlMappingDictionary
  33. : IDictionary, ICollection, IEnumerable, IXmlCompilerInclude
  34. {
  35. private Hashtable mappings;
  36. public XmlMappingDictionary ()
  37. {
  38. mappings = new Hashtable ();
  39. }
  40. public event QueryEventHandler OnProcessingEvent;
  41. [MonoTODO ("Check name conflicts")]
  42. public XmlMapping Add (string name, string mappingUrl)
  43. {
  44. using (XmlReader xr = new XmlTextReader (mappingUrl)) {
  45. return Add (name, xr);
  46. }
  47. }
  48. [MonoTODO ("Check name conflicts")]
  49. public XmlMapping Add (string name, XmlReader reader)
  50. {
  51. XmlMapping map = mapppings [name] as XmlMapping;
  52. if (map != null) {
  53. map = new XmlMapping (reader);
  54. mappings [name] = map;
  55. }
  56. return map;
  57. }
  58. [MonoTODO ("Check name conflicts")]
  59. public void Add (string name, XmlMapping mapping)
  60. {
  61. mappings.Add (name, mapping);
  62. }
  63. // Why virtual method inside sealed class :-?
  64. public virtual void Clear ()
  65. {
  66. mappings.Clear ();
  67. }
  68. public bool Contains (string name)
  69. {
  70. return mappings.Contains (name);
  71. }
  72. public virtual IDictionaryEnumerator GetEnumerator ()
  73. {
  74. return mappings.GetEnumerator ();
  75. }
  76. public void Remove (string name)
  77. {
  78. mappings.Remove (name);
  79. }
  80. public virtual int Count {
  81. get { return mappings.Count; }
  82. }
  83. public XmlMapping this [string name] {
  84. get { return mappings [name] as XmlMapping; }
  85. set { mappings [name] = value; }
  86. }
  87. void ICollections.CopyTo (Array array, int index)
  88. {
  89. mappings.CopyTo (array, index);
  90. }
  91. [MonoTODO]
  92. bool ICollection.IsSynchronized {
  93. get { throw new NotImplementedException (); }
  94. }
  95. [MonoTODO]
  96. object ICollection.SyncRoot {
  97. get { throw new NotImplementedException (); }
  98. }
  99. [MonoTODO ("What if invalid type value?")]
  100. void IDictionary.Add (object key, object value)
  101. {
  102. if (value is string)
  103. Add ((string) key, (string) value);
  104. else if (value is XmlReader)
  105. Add ((string) key, (XmlReader) value);
  106. else
  107. Add ((string) key, (XmlMapping) value);
  108. }
  109. bool IDictionary.Contains (object key)
  110. {
  111. return Containts ((string) key);
  112. }
  113. bool IDictionary IsFixedSize {
  114. get { return false; }
  115. }
  116. bool IDictionary.IsReadOnly {
  117. get { return false; }
  118. }
  119. object IDictionary.this [object key] {
  120. get { return this [(string) key]; }
  121. set { this [(string) key] = (XmlMapping) value; }
  122. }
  123. ICollection IDictionary.Keys {
  124. get { return mappings.Keys; }
  125. }
  126. ICollection IDictionary.Values {
  127. get { return mappings.Values; }
  128. }
  129. void IDictionary.Remove (object key)
  130. {
  131. mappings.Remove ((string) key);
  132. }
  133. IEnumerator IEnumerable.GetEnumerator ()
  134. {
  135. return GetEnumerator ();
  136. }
  137. [MonoTODO]
  138. XmlExpression IXmlCompilerInclude.ResolveContextDocument ()
  139. {
  140. throw new NotImplementedException ();
  141. }
  142. [MonoTODO]
  143. XmlExpression IXmlCompilerInclude.ResolveContextFunction (
  144. XmlQualifiedName funcName, object [] funcParams)
  145. {
  146. throw new NotImplementedException ();
  147. }
  148. [MonoTODO]
  149. XmlExpression IXmlCompilerInclude.ResolveContextDocument (
  150. XmlQualifiedName varName)
  151. {
  152. throw new NotImplementedException ();
  153. }
  154. }
  155. }
  156. #endif // NET_2_0