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.

configuring.html 21 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <!-- Content Stylesheet for Site -->
  3. <!-- start the processing -->
  4. <html>
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
  7. <meta name="author" value="Peter Donald">
  8. <meta name="email" value="peter@apache.org">
  9. <title>Apache Myrmidon - On Task Configuring in Ant 2</title>
  10. </head>
  11. <body bgcolor="#ffffff" text="#000000" link="#525D76">
  12. <table border="0" width="100%" cellspacing="0">
  13. <!-- TOP IMAGE -->
  14. <tr>
  15. <td> <td colspan="2">
  16. <a href="http://jakarta.apache.org"><img src="http://jakarta.apache.org/images/jakarta-logo.gif" align="left" border="0"/></a>
  17. </td>
  18. </td>
  19. <td valign="bottom"><div align="right"><b><font size="+3" color="#525D76">Apache Myrmidon</font></b></div></td>
  20. </tr>
  21. </table>
  22. <table border="0" width="100%" cellspacing="4">
  23. <tr><td colspan="2">
  24. <hr noshade="" size="1"/>
  25. </td></tr>
  26. <tr>
  27. <!-- LEFT SIDE NAVIGATION -->
  28. <td valign="top" nowrap="true">
  29. <p><strong>Myrmidon</strong></p>
  30. <ul>
  31. <li> <a href="./index.html">Introduction</a>
  32. </li>
  33. <li> <a href="./getinvolved.html">Get Involved</a>
  34. </li>
  35. <li> <a href="./user.html">Building Myrmidon</a>
  36. </li>
  37. <li> <a href="./todo.html">Todo List</a>
  38. </li>
  39. </ul>
  40. <p><strong>User Guide</strong></p>
  41. <ul>
  42. <li> <a href="./buildfile.html">Project File</a>
  43. </li>
  44. <li> <a href="./vfs.html">Virtual File System</a>
  45. </li>
  46. <li> <a href="./ant1compat.html">Ant 1 Compatibility Layer</a>
  47. </li>
  48. <li> <a href="./differences.html">Differences to Ant 1</a>
  49. </li>
  50. <li> <a href="./task.html">My First Task</a>
  51. </li>
  52. </ul>
  53. <p><strong>Extending Ant</strong></p>
  54. <ul>
  55. <li> <a href="./configuring.html">Configuration HOWTO</a>
  56. </li>
  57. <li> <a href="./converter.html">Converter HOWTO</a>
  58. </li>
  59. <li> <a href="./type.html">Type HOWTO</a>
  60. </li>
  61. <li> <a href="./classloader.html">ClassLoader HOWTO</a>
  62. </li>
  63. <li> <a href="./librarys.html">Library HOWTO</a>
  64. </li>
  65. </ul>
  66. <p><strong>Container Design</strong></p>
  67. <ul>
  68. </ul>
  69. </td>
  70. <td align="left" valign="top">
  71. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  72. <tr><td bgcolor="#525D76">
  73. <font color="#ffffff" face="arial,helvetica,sanserif">
  74. <a name="Introduction"><strong>Introduction</strong></a>
  75. </font>
  76. </td></tr>
  77. <tr><td>
  78. <blockquote>
  79. <p>This section will describe in detail the mechanism via which tasks are
  80. configured. Configuration is the name given to the stage in tasks
  81. lifecycle via which the XML representation is mapped onto the task
  82. object.</p>
  83. </blockquote>
  84. </td></tr>
  85. </table>
  86. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  87. <tr><td bgcolor="#525D76">
  88. <font color="#ffffff" face="arial,helvetica,sanserif">
  89. <a name="Names"><strong>Names</strong></a>
  90. </font>
  91. </td></tr>
  92. <tr><td>
  93. <blockquote>
  94. <p>When mapping the XML representation on to the task object you
  95. need to be able map the names as they appear in the XML to the
  96. names as they appear in the Java code. The process is for generating
  97. a java name from the xml name is as follows.</p>
  98. <ol>
  99. <li>Capitalize the first character of name.</li>
  100. <li>Find any '-' characters in XML name and remove character and
  101. capitalize the following letter. (And there must be a following
  102. letter)</li>
  103. </ol>
  104. <p>Some example mappings;</p>
  105. <div align="left">
  106. <table cellspacing="4" cellpadding="0" border="0">
  107. <tr>
  108. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  109. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  110. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  111. </tr>
  112. <tr>
  113. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  114. <td bgcolor="#ffffff"><pre>
  115. my-name ===&gt; MyName
  116. aString ===&gt; AString
  117. Basedir ===&gt; Basedir
  118. baseDir ===&gt; BaseDir
  119. url ===&gt; Url</pre></td>
  120. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  121. </tr>
  122. <tr>
  123. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  124. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  125. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  126. </tr>
  127. </table>
  128. </div>
  129. <p>Note that the above transformation is lossy and as such the
  130. following XML names all map to the same Java name. The ant1.x mapping
  131. is similarly lossy and in practice this has not been an issue.</p>
  132. <div align="left">
  133. <table cellspacing="4" cellpadding="0" border="0">
  134. <tr>
  135. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  136. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  137. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  138. </tr>
  139. <tr>
  140. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  141. <td bgcolor="#ffffff"><pre>
  142. base-dir ===&gt; BaseDir
  143. Base-dir ===&gt; BaseDir
  144. baseDir ===&gt; BaseDir
  145. BaseDir ===&gt; BaseDir</pre></td>
  146. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  147. </tr>
  148. <tr>
  149. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  150. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  151. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  152. </tr>
  153. </table>
  154. </div>
  155. <p><i>NOTE: We should really resolve this and either disallow '-' characters
  156. or disallow uppercase or something. (PD)</i></p>
  157. </blockquote>
  158. </td></tr>
  159. </table>
  160. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  161. <tr><td bgcolor="#525D76">
  162. <font color="#ffffff" face="arial,helvetica,sanserif">
  163. <a name="Resolving Values"><strong>Resolving Values</strong></a>
  164. </font>
  165. </td></tr>
  166. <tr><td>
  167. <blockquote>
  168. <p>The first stage of mapping the XML representation to the task
  169. is resolving all text data. The text data that needs to be resolved
  170. include the values of attributes and the content.</p>
  171. <p>Resolution consists of expanding any property references in the text
  172. data. Property references are identified as starting with the token
  173. "${" and finishing with another "}" token. The text
  174. in between is the name of a property. The value of the property replaces
  175. the sequence of text starting with the "${" token and finishing
  176. with the "}" token.</p>
  177. <p>Note that the value of the property may not be a string. If the text data
  178. contains text (or other property references) to either side of the property
  179. reference then it must be <a href="converter.html">converted</a> to a
  180. String.</p>
  181. </blockquote>
  182. </td></tr>
  183. </table>
  184. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  185. <tr><td bgcolor="#525D76">
  186. <font color="#ffffff" face="arial,helvetica,sanserif">
  187. <a name="Modeller"><strong>Modeller</strong></a>
  188. </font>
  189. </td></tr>
  190. <tr><td>
  191. <blockquote>
  192. <p>Currently the representation of object are stored in a hierarchial
  193. tree of <code>org.apache.myrmidon.api.metadata.ModelElement</code>
  194. objects. Each ModelElement has a number of attributes and can have
  195. either content or sub-elements.</p>
  196. <p>In most cases it is the responsibility of the runtime to map
  197. the ModelElement onto an object. However in some cases it may be useful
  198. for the object to get access to it's own model and for it to explicitly
  199. manage it's own configuration. In this case the object should implement
  200. the <code>org.apache.myrmidon.api.metadata.Modeller</code> interface
  201. which will provide the mechanism for the object to receive its own
  202. representation and configure itself.</p>
  203. <p>Note that the Modeller mechanism should be avoided if possible
  204. as it adds considerable complexity to the implementing object.</p>
  205. </blockquote>
  206. </td></tr>
  207. </table>
  208. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  209. <tr><td bgcolor="#525D76">
  210. <font color="#ffffff" face="arial,helvetica,sanserif">
  211. <a name="Attributes"><strong>Attributes</strong></a>
  212. </font>
  213. </td></tr>
  214. <tr><td>
  215. <blockquote>
  216. <p>To map an XML attribute on to a Java object, the name of the
  217. attribute is mapped to a java name and prefixed with the string
  218. "set". The resulting string is then used to look up a
  219. method with a single parameter.</p>
  220. <p>For example, for the attribute "world" would result
  221. in a lookup of a method named "setWorld" with a single
  222. parameter.</p>
  223. <p>If multiple methods were matched during the lookup then an
  224. exception is thrown indicating ambiguity. Theres is an exception
  225. to this rule that allows 2 methods to be matched if one of the
  226. methods takes a <code>java.lang.String</code> parameter. The method
  227. that has the <code>java.lang.String</code> parameter is ignored and
  228. the other method would be chosen. This exception is allowed as it is
  229. common practice for a task to evolve from String parameters to more
  230. strongly typed parameters.</p>
  231. <p>The resolved text data of the attribute must be
  232. <a href="converter.html">converted</a> to the type of the matched
  233. methods parameter. For example, if the "setWorld" method
  234. took a parameter of type <code>java.io.File</code> then the resolved
  235. text data must be converted into a <code>java.io.File</code>. The
  236. conversion is done by the Converter architecture that is more fully
  237. described in the <a href="converter.html">Converter HOWTO</a>.</p>
  238. <p>After the value is converted to the correct type the method is
  239. invoked with the converted value.</p>
  240. </blockquote>
  241. </td></tr>
  242. </table>
  243. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  244. <tr><td bgcolor="#525D76">
  245. <font color="#ffffff" face="arial,helvetica,sanserif">
  246. <a name="Content"><strong>Content</strong></a>
  247. </font>
  248. </td></tr>
  249. <tr><td>
  250. <blockquote>
  251. <p>The XML representation of object can have either have nested
  252. elements or nested text (content) but not both. To add the content
  253. to an object a method named "content" with one parameter is looked
  254. up. The resolved text data for content is then
  255. <a href="converter.html">converted</a> to the type of the parameter
  256. and passed in via the method.</p>
  257. </blockquote>
  258. </td></tr>
  259. </table>
  260. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  261. <tr><td bgcolor="#525D76">
  262. <font color="#ffffff" face="arial,helvetica,sanserif">
  263. <a name="Element"><strong>Element</strong></a>
  264. </font>
  265. </td></tr>
  266. <tr><td>
  267. <blockquote>
  268. <p>Mapping an ModelElement onto a java object is a series of steps.
  269. If the ModelElement name ends with the string "-ref" then
  270. it is treated as a reference element - see the <em>Referrenced
  271. Elements</em> section. Otherwise, the element is first attempted to
  272. be mapped as a <em>Named Element</em> and if no match is found via
  273. that method it tries to treat the element as a <em>Typed Element</em>.</p>
  274. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  275. <tr><td bgcolor="#828DA6">
  276. <font color="#ffffff" face="arial,helvetica,sanserif">
  277. <a name="Named Elements"><strong>Named Elements</strong></a>
  278. </font>
  279. </td></tr>
  280. <tr><td>
  281. <blockquote>
  282. <p>To map a named ModelElement on to a Java object, the name of
  283. the element is mapped to a java name and prefixed with the string
  284. "add". The resulting string is then used to look up a
  285. method with a single parameter.</p>
  286. <p>For example, for the attribute "geometry" would result
  287. in a lookup of a method named "addGeometry" with a single
  288. parameter. If multiple methods were matched during the lookup then an
  289. exception is thrown indicating ambiguity. If no methods were found that
  290. match name then skip down to configuring "typed" elements.</p>
  291. <p>The type of the methods single parameter is then examined to determine
  292. what happens next. There are two valid situations, if neither of these are
  293. satisfied, then an exception is thrown.</p>
  294. <ul>
  295. <li>The parameters type is <code>org.apache.myrmidon.api.metadata.ModelElement</code></li>
  296. <li>The parameters type is a concrete class</li>
  297. </ul>
  298. <p>1. If the parameter has a type of <code>org.apache.myrmidon.api.metadata.ModelElement</code>
  299. then the un-modified model representation of element is passed to object by invoking
  300. the adder method.</p>
  301. <p>2. If the parameters type is concrete then an instance of the parameter is
  302. instantiated using the default constructor. This created object is then configured
  303. in the same manner as task using the elements representation as the model. After
  304. the object is configured it is passed into object by invoking the adder method.</p>
  305. </blockquote>
  306. </td></tr>
  307. </table>
  308. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  309. <tr><td bgcolor="#828DA6">
  310. <font color="#ffffff" face="arial,helvetica,sanserif">
  311. <a name="Referrenced Elements"><strong>Referrenced Elements</strong></a>
  312. </font>
  313. </td></tr>
  314. <tr><td>
  315. <blockquote>
  316. <p>A referenced element is one that has a name ending in
  317. "-ref" and has a single attribute "name"
  318. and no content or child elements.</p>
  319. <p>The value of the "name" attribute is the name of a property.
  320. The value of this property is retrieved from the TaskContext.</p>
  321. <p>Like with <em>Named Elements</em> the name of the element (minus
  322. the "-ref" part) is mapped to a java name and prefixed with the string
  323. "add". The resulting string is then used to look up a
  324. method with a single parameter. If multiple methods were matched during the lookup then an
  325. exception is thrown indicating ambiguity.</p>
  326. <p>The value retrieved from the TaskContext is then converted to the type
  327. of the methods parameter and the add method is invoked with the converted value.</p>
  328. <p>An example usage is the following;</p>
  329. <div align="left">
  330. <table cellspacing="4" cellpadding="0" border="0">
  331. <tr>
  332. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  333. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  334. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  335. </tr>
  336. <tr>
  337. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  338. <td bgcolor="#ffffff"><pre>
  339. &lt;my-task ...&gt;
  340. &lt;classpath-ref name=&quot;project.class.path&quot;/&gt;
  341. &lt;/my-task&gt;
  342. </pre></td>
  343. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  344. </tr>
  345. <tr>
  346. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  347. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  348. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  349. </tr>
  350. </table>
  351. </div>
  352. </blockquote>
  353. </td></tr>
  354. </table>
  355. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  356. <tr><td bgcolor="#828DA6">
  357. <font color="#ffffff" face="arial,helvetica,sanserif">
  358. <a name="Typed Elements"><strong>Typed Elements</strong></a>
  359. </font>
  360. </td></tr>
  361. <tr><td>
  362. <blockquote>
  363. <p>"Typed" elements can also be added to an object. A typed element
  364. is one in which the name of the element actually refers to a type rather than the
  365. name of the adder to call.</p>
  366. <p>For example, you may wish to allow a task to add arbitrary instances of the
  367. Condition role to a task. So instead of adding methods such as
  368. <code>addAnd(AndCondition)</code>, <code>addOr(OrCondition)</code> and
  369. <code>addXor(XorCondition)</code> you can instead add a single method
  370. <code>add(Condition)</code>. This vastly simplifies the amount of work required
  371. to write tasks that take conditions. More importantly it allows end-users to
  372. extend the number of elements selected by task. For instance if the user wanted
  373. a "nand" condition they could write the Nand type use it in their build
  374. file. For a discussion on roles and types see the <a href="types.html">Types
  375. HOWTO</a>.</p>
  376. <p>To use a Typed adder there must be a single method named "add" that
  377. has a single parameter. The parameter <em>MUST</em> be an abstract interface and
  378. must be registered as a role. The name of the element is then used to lookup the
  379. a type in the TypeManager with a role matching the interface name.</p>
  380. <p>For example if an element named "nand" was added to an object that had
  381. an adder with the signature <code>void add( Condition condition )</code> then
  382. the type named "nand" in the role "Condition" would be looked up.
  383. An instance of the type would then be created using the default constructor and the
  384. created object would be configured and then adder to object using adder.</p>
  385. </blockquote>
  386. </td></tr>
  387. </table>
  388. </blockquote>
  389. </td></tr>
  390. </table>
  391. </td>
  392. </tr>
  393. <!-- FOOTER -->
  394. <tr><td colspan="2">
  395. <hr noshade="" size="1"/>
  396. </td></tr>
  397. <tr><td colspan="2">
  398. <div align="center"><font color="#525D76" size="-1"><em>
  399. Copyright &#169; 2000-2002, Apache Software Foundation
  400. </em></font></div>
  401. </td></tr>
  402. </table>
  403. </body>
  404. </html>
  405. <!-- end the processing -->