/src/lib/xml/dtd/xml_dtd_node.e

http://github.com/tybor/Liberty · Specman e · 197 lines · 147 code · 25 blank · 25 comment · 3 complexity · 7eec7c540059376e1f7c1c88aa464891 MD5 · raw file

  1. -- See the Copyright notice at the end of this file.
  2. --
  3. class XML_DTD_NODE
  4. --
  5. -- A real node read from the XML stream.
  6. --
  7. insert
  8. RECYCLABLE
  9. redefine
  10. fill_tagged_out_memory
  11. end
  12. create {XML_DTD_VALIDATOR}
  13. make
  14. feature {ANY}
  15. fill_tagged_out_memory
  16. local
  17. i: INTEGER
  18. do
  19. name.utf8_encode_in(tagged_out_memory)
  20. if not children.is_empty then
  21. tagged_out_memory.extend('(')
  22. from
  23. i := children.lower
  24. until
  25. i > children.upper
  26. loop
  27. if i /= children.lower then
  28. tagged_out_memory.append(once ", ")
  29. end
  30. children.item(i).fill_tagged_out_memory
  31. i := i + 1
  32. end
  33. tagged_out_memory.extend(')')
  34. end
  35. end
  36. feature {XML_DTD_VALIDATOR, XML_DTD_ELEMENT}
  37. name: UNICODE_STRING
  38. require
  39. element /= Void
  40. do
  41. Result := element.name
  42. end
  43. element: XML_DTD_ELEMENT
  44. parent: XML_DTD_NODE
  45. children: FAST_ARRAY[XML_DTD_NODE]
  46. set_element (a_element: like element) assign element
  47. do
  48. element := a_element
  49. ensure
  50. element = a_element
  51. end
  52. set_parent (a_parent: like parent) assign parent
  53. require
  54. not a_parent.fast_has(Current)
  55. do
  56. a_parent.add_last(Current)
  57. parent := a_parent
  58. end
  59. feature {XML_DTD_NODE, XML_DTD_VALIDATOR}
  60. valid_index (index: INTEGER): BOOLEAN
  61. do
  62. Result := children.valid_index(index)
  63. end
  64. remove (index: INTEGER)
  65. require
  66. valid_index(index)
  67. do
  68. children.remove(index)
  69. end
  70. add_last (a_node: XML_DTD_NODE)
  71. do
  72. children.add_last(a_node)
  73. ensure
  74. not is_empty
  75. end
  76. is_empty: BOOLEAN
  77. do
  78. Result := children.is_empty
  79. end
  80. count: INTEGER
  81. do
  82. Result := children.count
  83. end
  84. fast_has (a_node: XML_DTD_NODE): BOOLEAN
  85. do
  86. Result := children.fast_has(a_node)
  87. end
  88. first: XML_DTD_NODE
  89. require
  90. not is_empty
  91. do
  92. Result := children.first
  93. end
  94. last: XML_DTD_NODE
  95. require
  96. not is_empty
  97. do
  98. Result := children.last
  99. end
  100. item (index: INTEGER): XML_DTD_NODE
  101. require
  102. valid_index(index)
  103. do
  104. Result := children.item(index)
  105. end
  106. fast_first_index_of (a_node: XML_DTD_NODE): INTEGER
  107. do
  108. Result := children.fast_first_index_of(a_node)
  109. end
  110. feature {XML_DTD_VALIDATOR} -- Tree validation
  111. is_valid_child (explorer: XML_DTD_VALIDATOR; node_name: UNICODE_STRING): BOOLEAN
  112. require
  113. explorer /= Void
  114. element.is_built
  115. do
  116. Result := element.is_valid_child(explorer, node_name, children)
  117. end
  118. is_valid_data (explorer: XML_DTD_VALIDATOR; data: UNICODE_STRING): BOOLEAN
  119. require
  120. explorer /= Void
  121. element.is_built
  122. do
  123. Result := element.is_valid_data(explorer, data, children)
  124. end
  125. feature {RECYCLING_POOL}
  126. recycle
  127. local
  128. i: INTEGER
  129. do
  130. if parent /= Void then
  131. i := parent.fast_first_index_of(Current)
  132. check
  133. parent.valid_index(i)
  134. end
  135. parent.remove(i)
  136. check
  137. not parent.fast_has(Current)
  138. end
  139. end
  140. parent := Void
  141. ensure
  142. (old parent /= Void) implies (not (old parent).fast_has(Current))
  143. parent = Void
  144. end
  145. feature {}
  146. make
  147. do
  148. create children.make(0)
  149. end
  150. invariant
  151. children /= Void
  152. end -- class XML_DTD_NODE
  153. --
  154. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  155. --
  156. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  157. -- of this software and associated documentation files (the "Software"), to deal
  158. -- in the Software without restriction, including without limitation the rights
  159. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  160. -- copies of the Software, and to permit persons to whom the Software is
  161. -- furnished to do so, subject to the following conditions:
  162. --
  163. -- The above copyright notice and this permission notice shall be included in
  164. -- all copies or substantial portions of the Software.
  165. --
  166. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  167. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  168. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  169. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  170. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  171. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  172. -- THE SOFTWARE.