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.

Antidote.html 12 kB

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