/Prototipo/Servlet/lib/xstream-distribution-1.4.1-bin/xstream-1.4.1/docs/architecture.html

http://prototipomemoria.googlecode.com/ · HTML · 232 lines · 166 code · 45 blank · 21 comment · 0 complexity · f38d57dea0a2f98f3579793f5359a5b6 MD5 · raw file

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <!--
  4. Copyright (C) 2005, 2006 Joe Walnes.
  5. Copyright (C) 2006, 2007, 2008 XStream committers.
  6. All rights reserved.
  7. The software in this package is published under the terms of the BSD
  8. style license a copy of which has been included with this distribution in
  9. the LICENSE.txt file.
  10. Created on 29. January 2005 by Joe Walnes
  11. -->
  12. <head>
  13. <title>XStream - Architecture Overview</title>
  14. <link rel="stylesheet" type="text/css" href="style.css"/>
  15. <!-- Google analytics -->
  16. <script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
  17. </script>
  18. <script type="text/javascript">
  19. _uacct = "UA-110973-2";
  20. urchinTracker();
  21. </script>
  22. </head>
  23. <body>
  24. <div id="banner">
  25. <a href="index.html"><img id="logo" src="logo.gif" alt="XStream"/></a>
  26. </div>
  27. <div id="center" class="Content2Column"> <!-- Content3Column for index -->
  28. <div id="content">
  29. <h1 class="FirstChild">Architecture Overview</h1>
  30. <p>The architecture of XStream consists of the four main components:</p>
  31. <ul>
  32. <li><b>Converters</b></li>
  33. <!-- TODO: Mappers -->
  34. <li><b>Drivers (Writer and Reader)</b></li>
  35. <li><b>Context</b></li>
  36. <li><b>Facade</b></li>
  37. </ul>
  38. <!-- ************ -->
  39. <h1 id="Converters">Converters</h1>
  40. <p>Whenever XStream encounters an object that needs to be converted to/from XML, it delegates to a suitable
  41. <a href="javadoc/com/thoughtworks/xstream/converters/Converter.html">Converter</a> implementation associated
  42. with the class of that Object.</p>
  43. <p>XStream comes <a href="converters.html">bundled with many converters</a> for common types, including primitives,
  44. String, Collections, arrays, null, Date, etc.</p>
  45. <p>XStream also has a <i>default Converter</i>, that is used when no other Converters match a type. This uses
  46. reflection to automatically generate the XML for all the fields in an object.</p>
  47. <p>If an object is composed of other objects, the Converter may delegate to other Converters.</p>
  48. <p class="highlight">To customize the XML for particular object type a new Converter should be implemented.</p>
  49. <!-- ************ -->
  50. <h1 id="Drivers">Drivers (Writer and Reader)</h1>
  51. <p>XStream is abstracted from the underlying XML data using the
  52. <a href="javadoc/com/thoughtworks/xstream/io/HierarchicalStreamWriter.html">HierarchicalStreamWriter</a>
  53. and <a href="javadoc/com/thoughtworks/xstream/io/HierarchicalStreamReader.html">HierarchicalStreamReader</a>
  54. interfaces for serializing and deserializing respectively.</p>
  55. <p>This abstraction allows XStream to read XML from direct streams using an XML parser or directly manipulate
  56. existing structures (such as DOM). This prevents the overhead of having to reparse if XStream is working from
  57. XML that has been partially processed by other libraries (for instance a SOAP library). It also avoids tying XStream
  58. to a particular library.</p>
  59. <p>XStream comes bundled with
  60. <a href="javadoc/com/thoughtworks/xstream/io/xml/package-summary.html">reader and writer implementations</a> for
  61. most major XML libraries.</p>
  62. <p class="highlight">Writer and Readers can be implemented allowing XStream to serialize to most XML APIs.
  63. Writers and Readers can also be created around tree based non XML structures.</p>
  64. <!--
  65. note: one reader/writer per context
  66. note: why not sax
  67. -->
  68. <!-- ************ -->
  69. <h1 id="Context">Context</h1>
  70. <p>When XStream serializes or deserializes some objects, it creates a
  71. <a href="javadoc/com/thoughtworks/xstream/converters/MarshallingContext.html">MarshallingContext</a> or
  72. <a href="javadoc/com/thoughtworks/xstream/converters/UnmarshallingContext">UnmarshallingContext</a>,
  73. which handle the traversing of the data and delegation to the necessary Converters.</p>
  74. <p class="highlight">The MarshallingContext/UnmarshallingContext is made available to converters allowing them
  75. to tell XStream to process objects contained within other objects.</p>
  76. <p>XStream provides three pairs of context implementations that traverse the object graph with slightly
  77. different behaviors. The default can be changed using
  78. <a href="javadoc/com/thoughtworks/xstream/XStream.html">XStream.setMode()</a>, passing in one of
  79. the following parameters:</p>
  80. <ul>
  81. <li>
  82. <b>XStream.XPATH_RELATIVE_REFERENCES</b><br/>
  83. <i>(Default)</i> Uses relative XPath references to signify duplicate references. This produces XML with
  84. the least clutter.
  85. </li>
  86. <li>
  87. <b>XStream.XPATH_ABSOLUTE_REFERENCES</b><br/>
  88. Uses absolute XPath references to signify duplicate references. This might produce for some situations
  89. better readable XML. <i>Note, that XStream will read XML with relative paths as well as with absolute
  90. paths independent of the XPATH mode.</i>
  91. </li>
  92. <li>
  93. <b>XStream.ID_REFERENCES</b><br/>
  94. Uses ID references to signify duplicate references. In some scenarios, such as when using hand-written
  95. XML, this is easier to work with.
  96. </li>
  97. <li>
  98. <b>XStream.NO_REFERENCES</b><br/>
  99. This disables object graph support and treats the object structure like a tree. Duplicate references are
  100. treated as two separate objects and circular references cause an exception. This is slightly faster and
  101. uses less memory than the other two modes.
  102. </li>
  103. </ul>
  104. <p class="highlight">A new context is created for each object graph that is serialized. Both the
  105. <a href="javadoc/com/thoughtworks/xstream/converters/MarshallingContext.html">MarshallingContext</a> and
  106. <a href="javadoc/com/thoughtworks/xstream/converters/UnmarshallingContext.html">UnmarshallingContext</a>
  107. implement <a href="javadoc/com/thoughtworks/xstream/converters/DataHolder.html">DataHolder</a>,
  108. a hash table passed around whilst processing the object graph that can be used as the user sees fit (in a similar
  109. way that the HttpServletRequest attributes are used in a web-application).</p>
  110. <!-- ************ -->
  111. <h1 id="Facade">XStream facade</h1>
  112. <p>The main <a href="javadoc/com/thoughtworks/xstream/XStream.html">XStream</a> class is typically used as the
  113. entry point. This assembles the necessary components of XStream (as described above; Context, Converter,
  114. Writer/Reader and ClassMapper) and provides a simple to use API for common operations.</p>
  115. <p class="highlight">Remember, the XStream class is just a facade - it can always be bypassed for more advanced
  116. operations.</p>
  117. <br/>
  118. </div>
  119. </div>
  120. <div class="SidePanel" id="left">
  121. <div class="MenuGroup">
  122. <h1>Software</h1>
  123. <ul>
  124. <li><a href="index.html">About XStream</a></li>
  125. <li><a href="news.html">News</a></li>
  126. <li><a href="changes.html">Change History</a></li>
  127. <li><a href="versioning.html">About Versioning</a></li>
  128. </ul>
  129. </div>
  130. <div class="MenuGroup">
  131. <h1>Evaluating XStream</h1>
  132. <ul>
  133. <li><a href="tutorial.html">Two Minute Tutorial</a></li>
  134. <li><a href="graphs.html">Object references</a></li>
  135. <li><a href="manual-tweaking-output.html">Tweaking the Output</a></li>
  136. <li><a href="license.html">License</a></li>
  137. <li><a href="download.html">Download</a></li>
  138. <li><a href="references.html">References</a></li>
  139. <li><a href="parser-benchmarks.html">Parser Benchmarks</a></li>
  140. <li><a href="http://www.ohloh.net/projects/3459">Code Statistics</a></li>
  141. </ul>
  142. </div>
  143. <div class="MenuGroup">
  144. <h1>Using XStream</h1>
  145. <ul>
  146. <li class="currentLink">Architecture Overview</li>
  147. <li><a href="converters.html">Converters</a></li>
  148. <li><a href="faq.html">Frequently Asked Questions</a></li>
  149. <li><a href="list-user.html">Users' Mailing List</a></li>
  150. <li><a href="issues.html">Reporting Issues</a></li>
  151. </ul>
  152. </div>
  153. <div class="MenuGroup">
  154. <h1>Javadoc</h1>
  155. <ul>
  156. <li><a href="javadoc/index.html">XStream Core</a></li>
  157. <li><a href="hibernate-javadoc/index.html">Hibernate Extensions</a></li>
  158. <li><a href="benchmark-javadoc/index.html">Benchmark Module</a></li>
  159. </ul>
  160. </div>
  161. <div class="MenuGroup">
  162. <h1>Tutorials</h1>
  163. <ul>
  164. <li><a href="tutorial.html">Two Minute Tutorial</a></li>
  165. <li><a href="alias-tutorial.html">Alias Tutorial</a></li>
  166. <li><a href="annotations-tutorial.html">Annotations Tutorial</a></li>
  167. <li><a href="converter-tutorial.html">Converter Tutorial</a></li>
  168. <li><a href="objectstream.html">Object Streams Tutorial</a></li>
  169. <li><a href="persistence-tutorial.html">Persistence API Tutorial</a></li>
  170. <li><a href="json-tutorial.html">JSON Tutorial</a></li>
  171. </ul>
  172. </div>
  173. <div class="MenuGroup">
  174. <h1>Developing XStream</h1>
  175. <ul>
  176. <li><a href="how-to-contribute.html">How to Contribute</a></li>
  177. <li><a href="list-dev.html">Developers' Mailing List</a></li>
  178. <li><a href="team.html">Development Team</a></li>
  179. <li><a href="repository.html">Source Repository</a></li>
  180. <li><a href="http://bamboo.ci.codehaus.org/browse/XSTREAM">Continuous Integration</a></li>
  181. </ul>
  182. </div>
  183. </div>
  184. </body>
  185. </html>