/src/lib/xml/namespaces/xmlns_composite_node.e

http://github.com/tybor/Liberty · Specman e · 234 lines · 181 code · 19 blank · 34 comment · 10 complexity · c8f5376effe728f4e533c374ab9a72fd MD5 · raw file

  1. -- See the Copyright notice at the end of this file.
  2. --
  3. class XMLNS_COMPOSITE_NODE
  4. --
  5. -- A node in an XMLNS_TREE
  6. --
  7. inherit
  8. XMLNS_NODE
  9. create {XMLNS_TREE}
  10. make
  11. feature {ANY}
  12. namespace: UNICODE_STRING
  13. -- The namespace of the node
  14. name: UNICODE_STRING
  15. -- The name of the node
  16. attribute_namespace (index: INTEGER): UNICODE_STRING
  17. -- The namespace of the i'th attribute
  18. require
  19. index.in_range(1, attributes_count)
  20. local
  21. i, d, n: INTEGER
  22. do
  23. if index <= no_namespace_attributes.count then
  24. Result := Void
  25. else
  26. from
  27. i := attributes.lower
  28. d := index - no_namespace_attributes.count
  29. until
  30. Result /= Void
  31. loop
  32. n := attributes.key(i).count
  33. if d <= n then
  34. Result := attributes.key(i)
  35. else
  36. d := d - n
  37. i := i + 1
  38. end
  39. end
  40. end
  41. end
  42. attribute_name (index: INTEGER): UNICODE_STRING
  43. -- The name of the i'th attribute
  44. require
  45. index.in_range(1, attributes_count)
  46. local
  47. i, d, n: INTEGER
  48. do
  49. if index <= no_namespace_attributes.count then
  50. Result := no_namespace_attributes.key(index)
  51. else
  52. from
  53. i := attributes.lower
  54. d := index - no_namespace_attributes.count
  55. until
  56. Result /= Void
  57. loop
  58. n := attributes.key(i).count
  59. if d <= n then
  60. Result := attributes.item(i).key(d)
  61. else
  62. d := d - n
  63. i := i + 1
  64. end
  65. end
  66. end
  67. end
  68. attribute_value (index: INTEGER): UNICODE_STRING
  69. -- The value of the i'th attribute
  70. require
  71. index.in_range(1, attributes_count)
  72. local
  73. i, d, n: INTEGER
  74. do
  75. if index <= no_namespace_attributes.count then
  76. Result := no_namespace_attributes.item(index)
  77. else
  78. from
  79. i := attributes.lower
  80. d := index - no_namespace_attributes.count
  81. until
  82. Result /= Void
  83. loop
  84. n := attributes.key(i).count
  85. if d <= n then
  86. Result := attributes.item(i).item(d)
  87. else
  88. d := d - n
  89. i := i + 1
  90. end
  91. end
  92. end
  93. end
  94. attribute_at (a_attribute_namespace, a_attribute_name: UNICODE_STRING): UNICODE_STRING
  95. -- The value of the attribute given by its name; Void if not set
  96. local
  97. att: HASHED_DICTIONARY[UNICODE_STRING, UNICODE_STRING]
  98. do
  99. if a_attribute_namespace = Void then
  100. att := no_namespace_attributes
  101. else
  102. att := attributes.reference_at(a_attribute_namespace)
  103. end
  104. if att /= Void then
  105. Result := att.reference_at(a_attribute_name)
  106. end
  107. end
  108. attributes_count: INTEGER
  109. -- The number of attributes
  110. local
  111. i: INTEGER
  112. do
  113. Result := no_namespace_attributes.count
  114. from
  115. i := attributes.lower
  116. until
  117. i > attributes.upper
  118. loop
  119. Result := Result + attributes.item(i).count
  120. i := i + 1
  121. end
  122. end
  123. child (index: INTEGER): XMLNS_NODE
  124. -- The i'th child
  125. require
  126. index.in_range(1, children_count)
  127. do
  128. Result := children.item(index - 1)
  129. end
  130. children_count: INTEGER
  131. -- The number of children
  132. do
  133. Result := children.count
  134. end
  135. feature {ANY}
  136. accept (visitor: VISITOR)
  137. local
  138. v: XMLNS_NODE_VISITOR
  139. do
  140. v ::= visitor
  141. v.visit_composite_node(Current)
  142. end
  143. feature {XMLNS_TREE}
  144. set_attribute (a_attribute_namespace, a_attribute_name, a_attribute_value: UNICODE_STRING)
  145. require
  146. a_attribute_name /= Void
  147. a_attribute_value /= Void
  148. local
  149. att: HASHED_DICTIONARY[UNICODE_STRING, UNICODE_STRING]
  150. do
  151. if a_attribute_namespace = Void then
  152. att := no_namespace_attributes
  153. else
  154. att := attributes.reference_at(a_attribute_namespace)
  155. if att = Void then
  156. create att.make
  157. attributes.add(att, a_attribute_namespace)
  158. end
  159. end
  160. att.add(a_attribute_value, a_attribute_name)
  161. ensure
  162. attribute_at(a_attribute_namespace, a_attribute_name) = a_attribute_value
  163. end
  164. add_child (node: XMLNS_NODE)
  165. require
  166. node /= Void
  167. node.parent = Void
  168. do
  169. children.add_last(node)
  170. node.set_parent(Current)
  171. ensure
  172. node.parent = Current
  173. child(children_count) = node
  174. end
  175. feature {}
  176. attributes: HASHED_DICTIONARY[HASHED_DICTIONARY[UNICODE_STRING, UNICODE_STRING], UNICODE_STRING]
  177. no_namespace_attributes: HASHED_DICTIONARY[UNICODE_STRING, UNICODE_STRING]
  178. children: FAST_ARRAY[XMLNS_NODE]
  179. make (a_namespace: like namespace; a_name: like name; a_line: like line; a_column: like column)
  180. require
  181. a_name /= Void
  182. a_line > 0
  183. a_column > 0
  184. do
  185. namespace := a_namespace
  186. name := a_name
  187. line := a_line
  188. column := a_column
  189. create attributes.make
  190. create no_namespace_attributes.make
  191. create children.make(0)
  192. end
  193. invariant
  194. name /= Void
  195. end -- class XMLNS_COMPOSITE_NODE
  196. --
  197. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  198. --
  199. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  200. -- of this software and associated documentation files (the "Software"), to deal
  201. -- in the Software without restriction, including without limitation the rights
  202. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  203. -- copies of the Software, and to permit persons to whom the Software is
  204. -- furnished to do so, subject to the following conditions:
  205. --
  206. -- The above copyright notice and this permission notice shall be included in
  207. -- all copies or substantial portions of the Software.
  208. --
  209. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  210. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  211. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  212. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  213. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  214. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  215. -- THE SOFTWARE.