You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

design.xml 12 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <?xml version="1.0"?>
  2. <document>
  3. <properties>
  4. <index value="1"/>
  5. <author email="simeon@fitch.net">Simeon H. K. Fitch</author>
  6. <author email="christoph.wilhelms@t-online.de">Christoph Wilhelms</author>
  7. <title>Design Overview</title>
  8. </properties>
  9. <body>
  10. <section name="Introduction">
  11. <p>The purpose of this document is to communicate the overall
  12. structure and design patters used in Antidote, the GUI for
  13. Ant. This document is a work in progress, as well as a living
  14. document, and it is most likely not be in full synchronization with
  15. the source code. Therefore, if there is any doubt, view the source
  16. ;-)
  17. </p>
  18. </section>
  19. <section name="Overview">
  20. <p>The Antidote architecture design aims to provide a high level
  21. of modularity and extensibility. Ideally the components of
  22. Antidote will be able to be assembled in different configurations
  23. to provide the type of application or plug-in desired.
  24. </p>
  25. <p>To achieve this modularity, a high level of decoupling is
  26. necessary. The standard UI design approach of providing separation
  27. of view (presentation) from model (data) is applied, leveraging
  28. the built-in Ant data model where possible, as well as the
  29. predefined Swing model interfaces. Furthermore, the architecture
  30. is highly event driven, whereby modules communicate via a shared
  31. communications channel.
  32. </p>
  33. <p>To a large extent, the configuration of application modules is
  34. driven by localized configuration files, allowing new modules or
  35. data views to be added, as well as providing multi-language
  36. support.
  37. </p>
  38. <p>The diagram below conveys a high altitude view of the
  39. application's structure. As the application grows, new components
  40. will be plugged in to what will be described as the <code>EventBus</code>
  41. </p>
  42. </section>
  43. <section name="Antidote Component Architecture/Event Bus">
  44. <source>
  45. +---------------+ +----------------+ +-------------+ +-------------+<br/>
  46. | | | | | | | |<br/>
  47. | ActionManager | | EventResponder | | AntModule | | AntModule |<br/>
  48. | | | | |(ProjectNav) | |(SourceEdit) |<br/>
  49. +---------------+ +----------------+ +-------------+ +-------------+<br/>
  50. | ^ ^ ^<br/>
  51. | | | |<br/>
  52. ActionEvent EventObject AntEvent AntEvent<br/>
  53. | | | |<br/>
  54. v v v v<br/>
  55. /---------------------------------------------------------------------\<br/>
  56. / \<br/>
  57. &lt; EventBus &gt;<br/>
  58. \ /<br/>
  59. \---------------------------------------------------------------------/<br/>
  60. | ^ ^ ^<br/>
  61. | | | |<br/>
  62. EventObject ChangeEvent BuildEvent EventObject<br/>
  63. | | | |<br/>
  64. v | | v<br/>
  65. +---------------+ +----------------+ +-------------+ +--------------+<br/>
  66. | | | | | | | |<br/>
  67. | Console | | ProjectProxy | | Ant | | (Your Module)|<br/>
  68. | | | | | | | |<br/>
  69. +---------------+ +----------------+ +-------------+ +--------------+
  70. </source>
  71. <p>The backbone of the application is the <TT>EventBus</TT>. Any
  72. component of the application can post events to the
  73. <code>EventBus</code>. Components that wish to receive events are
  74. called <code>BusMember</code>s.
  75. </p>
  76. <p>The <code>EventBus</code> will dispatch any object of type
  77. <code>java.util.Event</code>, which means that Ant <code>BuildEvent</code>
  78. objects, as well as <code>AWTEvent</code> objects can be posted (if desired). A
  79. new class of events called <code>AntEvent</code> is defined for Antidote
  80. specific events, which have the additional capability of being
  81. canceled mid-dispatch.
  82. </p>
  83. <p>Each <code>BusMember</code> must provide a <code>BusFilter</code> instance,
  84. which is the members' means of telling the bus which
  85. events it is interested in. This allows a <code>BusMember</code> to,
  86. say, only receive <code>AntEvent</code> objects.
  87. </p>
  88. <p>When a <code>BusMember</code> registers itself with the
  89. <code>EventBus</code>, it must provide a (so called) <i>interrupt
  90. level</i> which is a integer value defining a relative ordering
  91. for dispatching <code>EventObject</code>s to <code>BusMember</code>s. The
  92. purpose of this is to allow certain <code>BusMember</code> instances
  93. to see an event before others, and in the case of <code>AntEvent</code>
  94. objects, keep the event from propagating onward. The
  95. <code>EventBus</code> class defines the interrupt level constants
  96. <code>VETOING=1</code>, <code>MONITORING=5</code>, and <code>RESPONDING=10</code> to
  97. help define categories of members. The implied purpose being that:
  98. </p>
  99. <ul>
  100. <li><code>VETOING</code>: Listens for certain types of events, and
  101. may process them in a non-default manner to determine if the
  102. event should be canceled before being dispatched to the
  103. <code>RESPONDING</code> group.
  104. </li>
  105. <li><code>MONITORING</code>: Just listens for events, like a logger
  106. or status monitor.
  107. </li>
  108. <li><code>RESPONDING</code>: Process events in a default manner,
  109. knowing that the event has passed any <code>VETOING</code> members.
  110. </li>
  111. </ul>
  112. <p>Within a specific interrupt level, the order in which members will
  113. receive events is undefined. A <code>BusMember</code> may be registered
  114. at a level that is +/- of one of the defined levels, as long as it
  115. follows the constraint <code>MONITORING &lt;= interruptLevel &lt;=
  116. MAX_INTERRUPT</code>.
  117. </p>
  118. </section>
  119. <section name="Actions and ActionManager">
  120. <p>Extensive use of the <code>javax.swing.Action</code> interface is
  121. made for defining the set of menu and tool bar options that are
  122. available. The configuration file <code>action.properties</code>
  123. exists to define what should appear in the menu and toolbar, how
  124. it is displayed, and the <code>Action</code> command name that is
  125. dispatched when the user invokes that action. A class called
  126. <code>ActionManager</code> exists for not only processing the
  127. configuration file, but also for dispatching invoked action events
  128. to the <code>EventBus</code>, and for controlling the enabled state of
  129. an <code>Action</code>. When a new menu item or toolbar button is
  130. desired, first it is added to the <code>action.properties</code> file,
  131. and then the code to respond to it is added to the
  132. <code>EventResponder</code> (see below).
  133. </p>
  134. </section>
  135. <section name="Commands and EventResponder">
  136. <p>At some point in the stages of event processing, an event may
  137. require the data model to be modified, or some other task be
  138. performed. The <code>Command</code> interface is defined to classify
  139. code which performs some task or operation. This is distinct from
  140. an <code>Action</code>, which is a user request for an operation. A
  141. <code>Command</code> class is the encapsulation of the operation
  142. itself.
  143. </p>
  144. <p>When an <code>Action</code> generates an <code>ActionEvent</code>, the
  145. event is posted to the <code>EventBus</code> which delivers the event
  146. to all interested <code>BusMember</code>s. It eventually makes it to
  147. the <code>EventResponder</code> instance (registered at the
  148. <code>RESPONDING</code> interrupt level), which is responsible for
  149. translating specific events into <code>Command</code> objects, and
  150. then executing the <code>Command</code> object. For example, when the
  151. user selects the "Open..." menu option, an <code>ActionEvent</code> is
  152. generated by the Swing <code>MenuItem</code> class, which is then
  153. posted to the <code>EventBus</code> by the <code>ActionManager</code>. The
  154. <code>ActionEvent</code> is delivered to the <code>EventResponder</code>,
  155. which converts the <code>ActionEvent</code> into a <code>Command</code>
  156. instance. The <code>EventResponder</code> then calls the method
  157. <code>Command.execute()</code> to invoke the command (which displays a
  158. dialog for selecting a file to open).
  159. </p>
  160. <p>When adding new <code>Action</code>s or general tasks to the
  161. application, a <code>Command</code> object should be created to
  162. encapsulate the behavior. This includes most operations which
  163. modify the state of the data model.
  164. </p>
  165. <p>The purpose of this encapsulation is to allow the clean
  166. separation of making a request, and servicing a request. Due to
  167. various conditions in the application state, the actually response
  168. to a request may change, as well as who services it. This
  169. design approach facilitates that.
  170. </p>
  171. </section>
  172. <section name="Data Model and Views">
  173. <p><i>NB: This part of the architecture is not fleshed out very well. There
  174. needs to be a discussion of the degree to which the Antidote development
  175. should be able to impose changes on the Ant data model, and to what level
  176. that model should be mirrored in the Antidote code base. The coupling
  177. between them should be kept low, and at the same time changes to one should
  178. affect the other minimally. Still, features like property change events and
  179. bean introspection (or BeanInfo) may be needed to be added to the Ant data
  180. model. Right now the data model is encapsulated in the package
  181. <code>org.apache.tools.ant.gui.acs</code> (where "<code>acs</code>" stands for "Ant Construction Set").</i>
  182. </p>
  183. </section>
  184. <section name="Application Context">
  185. <p>In order to keep the coupling among application modules to a
  186. minimum, a single point of reference is needed for coordination
  187. and data sharing. The class <code>AppContext</code> is the catch-all
  188. class for containing the application state. Most modules and
  189. <code>Command</code> classes require an instance of the
  190. <code>AppContext</code> class. Because all state information in
  191. contained in an <code>AppContext</code> instance, multiple instances
  192. of Antidote can run inside the same JVM as long as each has it's
  193. own <code>AppContext</code>. (Interestingly, two instances of the
  194. Antidote could conceivably share an <code>AppContext</code> instance
  195. through RMI, allowing remote interaction/collaboration.)
  196. </p>
  197. </section>
  198. <section name="Configuration and ResourceManager">
  199. <p>Full "i18n" support should be assumed in modern applications,
  200. and all user viewable strings should be defined in a configuration
  201. file. For Antidote this configuration file is
  202. <code>antidote.properties</code>, which is located (with other UI
  203. resources) in the sub-package "resources".
  204. </p>
  205. <p>To aid in the lookup of text properties, as well as other
  206. resources like icons, a class called <code>ResourceManager</code> is
  207. defined. There are various convenience methods attached to this
  208. class, which will likely grow to make looking up configuration
  209. values as easy as possible.
  210. </p>
  211. <p>The organization of configuration properties is based on the
  212. fully qualified path of the class that requires the property. For
  213. example, the "about" box contains a messages, so it looks for the
  214. property "<code>org.apache.tools.ant.gui.About.message</code>" for the text
  215. message it should display. Therefore, the <code>ResourceManager</code>
  216. method <code>getString()</code> takes a <code>Class</code> instance as
  217. well as a <code>String</code> key. Please see the
  218. <code>ResourceManager</code> documentation for more information. Given
  219. this support, no user visible strings should appear in the source
  220. code itself.
  221. </p>
  222. </section>
  223. </body>
  224. </document>