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.

roles.html 17 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html lang="en">
  3. <!-- GENERATED FILE, DO NOT EDIT, EDIT THE XML FILE IN xdocs INSTEAD! -->
  4. <head>
  5. <META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  6. <title>Apache Ant - Roles</title>
  7. <link type="text/css" href="../../page.css" rel="stylesheet">
  8. <meta name="author" content="Antoine Levy-Lambert">
  9. <meta name="email" content="antoine@apache.org">
  10. </head>
  11. <body>
  12. <p class="navpath">
  13. <script src="../../breadcrumbs.js" language="JavaScript" type="text/javascript"></script>
  14. </p>
  15. <div class="logobar">
  16. <table width="100%" border="0" cellspacing="0" cellpadding="0">
  17. <tr>
  18. <td align="left"><img border="0" alt="Apache Ant site" src="../../images/group-logo.gif"></td>
  19. <td align="center" width="100%"><img alt="Apache Ant logo" border="0" src="../../images/project-logo.gif"></td>
  20. <td align="right">
  21. <form target="_blank" onsubmit="q.value = query.value + ' site:ant.apache.org'" action="http://www.google.com/search" method="get">
  22. <table summary="search" border="0" cellspacing="0" cellpadding="0" bgcolor="#4C6C8F">
  23. <tr>
  24. <td colspan="3"><img height="10" width="1" alt="" src="../../images/spacer.gif"></td>
  25. </tr>
  26. <tr>
  27. <td><img height="1" width="1" alt="" src="../../images/spacer.gif"></td>
  28. <td nowrap="nowrap" class="searchcaption">
  29. <input name="q" type="hidden">
  30. <input size="15" id="query" type="text">
  31. <img height="1" width="5" alt="" src="../../images/spacer.gif">
  32. <input name="Search" value="Search" type="submit">
  33. <br>
  34. the Apache Ant site
  35. </td>
  36. <td><img height="1" width="1" alt="" src="../../images/spacer.gif"></td>
  37. </tr>
  38. <tr>
  39. <td><img alt="" border="0" height="10" width="9" src="../../images/search-left.gif"></td>
  40. <td><img height="1" width="1" alt="" src="../../images/spacer.gif"></td>
  41. <td><img alt="" border="0" height="10" width="9" src="../../images/search-right.gif"></td>
  42. </tr>
  43. </table>
  44. </form>
  45. </td>
  46. </tr>
  47. </table>
  48. </div>
  49. <div class="tab">
  50. <table summary="tab bar" border="0" cellpadding="0" cellspacing="0">
  51. <tr>
  52. <td width="5"><img alt="" height="8" width="8" src="../../images/spacer.gif"></td><td valign="bottom">
  53. <table summary="non selected tab" style="height: 1.4em" border="0" cellpadding="0" cellspacing="0">
  54. <tr>
  55. <td valign="top" width="5" bgcolor="#B2C4E0"><img height="5" width="5" alt="" src="../../images/tab-left.gif"></td><td valign="middle" bgcolor="#B2C4E0"><a href="../../index.html"><font size="2" face="Arial, Helvetica, Sans-serif">Home</font></a></td><td valign="top" width="5" bgcolor="#B2C4E0"><img height="5" width="5" alt="" src="../../images/tab-right.gif"></td>
  56. </tr>
  57. </table>
  58. </td>
  59. <td width="5"><img alt="" height="8" width="8" src="../../images/spacer.gif"></td><td valign="bottom">
  60. <table summary="non selected tab" style="height: 1.4em" border="0" cellpadding="0" cellspacing="0">
  61. <tr>
  62. <td valign="top" width="5" bgcolor="#B2C4E0"><img height="5" width="5" alt="" src="../../images/tab-left.gif"></td><td valign="middle" bgcolor="#B2C4E0"><a href="../../projects/index.html"><font size="2" face="Arial, Helvetica, Sans-serif">Projects</font></a></td><td valign="top" width="5" bgcolor="#B2C4E0"><img height="5" width="5" alt="" src="../../images/tab-right.gif"></td>
  63. </tr>
  64. </table>
  65. </td>
  66. </tr>
  67. </table>
  68. </div>
  69. <div class="bluebar"></div>
  70. <div class="menucontainer">
  71. <div class="menu">
  72. <ul>
  73. </ul>
  74. </div>
  75. <img style="float: left" height="10" width="10" border="0" alt="" src="../../images/menu-left.gif">
  76. <img style="float: right" height="10" width="10" border="0" alt="" src="../../images/menu-right.gif">
  77. </div>
  78. <div class="lightbluebar">&nbsp;</div>
  79. <div class="main">
  80. <div class="content">
  81. <h1 class="title">Roles</h1>
  82. <h3 class="section">
  83. <a name="What is a role"></a>
  84. What is a role
  85. </h3>
  86. <p>
  87. I am quoting here Jose Alberto Fernandez 26.04.2003 22:05:
  88. Roles allow defining families of objects (members of a role) that can be
  89. used by tasks or inner elements developed separately.
  90. The developer of the object accepting a particular role as a subelement
  91. has no knowledge of the implementation of the object but much more
  92. importantly it has no knowledge of the XML element tag used to refer
  93. to this subelement in the XML file.
  94. </p>
  95. <p>
  96. In the antlib proposal, there are two preset roles :
  97. <ul>
  98. <li>task</li>
  99. <li>datatype</li>
  100. </ul>
  101. Examples of other roles are :
  102. <ul>
  103. <li>mapper</li>
  104. <li>filter</li>
  105. </ul>
  106. </p>
  107. <p>
  108. What does it all mean? It means we can now write a task, well typed, which
  109. can be accept different XML subelements depending on the declarations of
  110. other objects present on the build. The vendor specific elements of
  111. &lt;ejbjar&gt;, &lt;jspc&gt; and others are typical examples of where this capability
  112. can be very useful. Other parts of core could benefit of course.
  113. </p>
  114. <br />
  115. <h4 class="subsection">
  116. <a name="What do they do that is no possible in ANT"></a>
  117. What do they do that is no possible in ANT
  118. </h4>
  119. <p>
  120. They allow IntrospectionHelper to connect an XML subelement eventhough
  121. introspection cannot find a create or add/Configured method for it.
  122. It is a well typed methanism, the parent object will only be passed objects
  123. that it knows how to deal with. And the parent object does not need to have
  124. any knowledge of what currently available members are on the role.
  125. </p>
  126. <h3 class="section">
  127. <a name="roles versus DynamicConfigurator"></a>
  128. roles versus DynamicConfigurator
  129. </h3>
  130. <p>
  131. The closest thing in ANT today is DynamicConfigurator but its purpose
  132. is on the other way around. Given an elementTag with no matching method
  133. it is up to the parent object to try to make sense of it.
  134. If we were to use this mechanism to accomplish what roles try to do,
  135. it would require the parent object implementor to be aware of where
  136. to find the correct definition (remember it is a 3rd party implementation)
  137. and perform the creation. It will be also its responsibility to
  138. resolve type conflicts, name collisions, etc. This are all things
  139. that should be done by IntrospectionHelper directly.
  140. </p>
  141. <p>
  142. Also notice that Roles do not supersede DynamicConfigurator. On one hand roles
  143. let external implementations to be considered as possible subelements
  144. of a parent object, on the other hand, DynamicConfigurator allows a node
  145. to decide given its current state what is the meaning of a particular element.
  146. This cannot be done by roles in the general case, and that is good.
  147. </p>
  148. <h3 class="section">
  149. <a name="Implementation of roles in the proposal"></a>
  150. Implementation of roles in the proposal
  151. </h3>
  152. <p>this section quotes Jose Alberto Fernandez</p>
  153. <p>
  154. Here I may deviate from the exact code and add thoughts about where
  155. do I think it should go.
  156. </p>
  157. <h4 class="subsection">
  158. <a name="Usage of Roles"></a>
  159. Usage of Roles
  160. </h4>
  161. <p>
  162. The principle is very simple:
  163. </p>
  164. <br />
  165. <ol>
  166. <li>
  167. A role is defined by an interface. This interface is the parameter
  168. for a new special family of addConfigured(&lt;interface&gt;) methods.
  169. </li>
  170. <li>
  171. <p>
  172. When IntrospectionHelper fails to find a create/add method for the
  173. element, it will look at all the roles used in the addConfigured
  174. methods and on each of those roles will try to find an object declared
  175. with that element-tag name. If one and only one match is found then
  176. the instantiation is successful and the new object will be configured;
  177. otherwise it is an error and parsing stops.
  178. </p>
  179. <br />
  180. </li>
  181. <li>
  182. <p>
  183. The configured object may or may not implement the Role interface,
  184. if it does not, an Adaptor object may be instantiated as a proxy
  185. for the object. Which adaptor is used depends on how the implementation
  186. was declared.
  187. </p>
  188. <br />
  189. </li>
  190. <li>
  191. <p>
  192. The resulting object is passed as an argument to the addConfigured() method.
  193. </p>
  194. <br />
  195. </li>
  196. </ol>
  197. <h4 class="subsection">
  198. <a name="Declaration of roles"></a>
  199. Declaration of roles
  200. </h4>
  201. <p>
  202. A role definition associates a name with an (Interface,Adaptor) pair.
  203. The only reason for associating a name with the role is to ease notation when
  204. declaring members of a role.
  205. </p>
  206. <br />
  207. <p>
  208. Notice that the same interface or the same Adaptor may appear in multiple
  209. declarations. This only means that depending on the name used the adaptor
  210. of choice will be different.
  211. </p>
  212. <br />
  213. <p>
  214. There can only be one pair associated with each name.
  215. </p>
  216. <br />
  217. <h4 class="subsection">
  218. <a name="Declaration of implementations (members)"></a>
  219. Declaration of implementations (members)
  220. </h4>
  221. <br />
  222. <p>
  223. A class is declared as belonging to a role by specifying the name to be used
  224. when appearing in that role. The same class may belong to multiple roles
  225. and may specify the same or different names on each one.
  226. <br />
  227. </p>
  228. <p>
  229. The name used for the role during the declaration only determines which
  230. Adaptor will be available, if required.
  231. <br />
  232. </p>
  233. <p>
  234. Within a role-interface there can only be one object associated
  235. with each name.
  236. <br />
  237. </p>
  238. <h4 class="subsection">
  239. <a name="Scoping rules"></a>
  240. Scoping rules
  241. </h4>
  242. <br />
  243. <p>
  244. This is probably the more dificult aspect since given the way
  245. &lt;ant&gt; and &lt;antcall&gt; work it means possible redeclarations on every
  246. level of recursion. Whether declarations should just supercede
  247. one another or be smarter is something to look into.
  248. <br />
  249. </p>
  250. <h4 class="subsection">
  251. <a name="Syntax"></a>
  252. Syntax
  253. </h4>
  254. <br />
  255. <p>
  256. I have left out the issues of how the syntax looks like on purpose.
  257. <br />
  258. </p>
  259. <p>
  260. Syntax is just that and I am sure we can reach agreement somehow.
  261. It is also clear that we should provide tasks to define roles
  262. and declare members of roles direclty on the build.
  263. <br />
  264. </p>
  265. <h3 class="section">
  266. <a name="Making ant aware of tag/role/class associations"></a>
  267. Making ant aware of tag/role/class associations
  268. </h3>
  269. <p>
  270. The antlib proposal says :
  271. Let's declare explicitly that a tag can be used in a particular role and is implemented by a specific class.
  272. The declaration happens inside antlibs in the file META-INF/antlib.xml
  273. </p>
  274. <pre class="code">
  275. &lt;filter name=&quot;escapeunicode&quot; class=&quot;org.apache.tools.ant.filters.EscapeUnicode&quot;/&gt;
  276. </pre>
  277. <p>
  278. CM says :
  279. A normal typedef is enough to make ant aware of the existence of the class org.apache.tools.ant.filters.EscapeUnicode.
  280. Due to the fact that EscapeUnicode implements ChainableReader, the association between EscapeUnicode and the filter role does not need to be stated explicitly.
  281. </p>
  282. <h3 class="section">
  283. <a name="Method names in parent classes supporting roles"></a>
  284. Method names in parent classes supporting roles
  285. </h3>
  286. <p>
  287. There is a discussion about how methods to add nested elements of a specific roles in a parent class should be called, and what their signature should be like.
  288. </p>
  289. <p>
  290. CM :
  291. <source>
  292. addTYPE(TYPE)
  293. </source>
  294. for instance <source>addChainableReader(ChainableReader a)</source>
  295. </p>
  296. <p>
  297. PR:
  298. to add an element before its own attributes and nested elements are configured.
  299. <source>
  300. void add(TYPE)
  301. </source>
  302. to add an already configured element
  303. <source>
  304. void addConfigured(TYPE)
  305. </source>
  306. </p>
  307. <p>
  308. in the ant code of 1.6 :
  309. <source>public Object createDynamicElement(String name)</source>
  310. </p>
  311. <h3 class="section">
  312. <a name="Cardinality problems"></a>
  313. Cardinality problems
  314. </h3>
  315. <h4 class="subsection">
  316. <a name="One tag, several implementations"></a>
  317. One tag, several implementations
  318. </h4>
  319. <p>
  320. The &lt;weblogic&gt; element in &lt;ejbjar&gt;, &lt;jspc&gt;, &lt;serverdeploy&gt;, has different meanings.
  321. </p>
  322. <p>
  323. This is an argument to introduce roles in ant, and to associate an XML tag with a role and an implementation class.
  324. </p>
  325. <h4 class="subsection">
  326. <a name="Parent classes accepting one interface in different functions"></a>
  327. Parent classes accepting one interface in different functions
  328. </h4>
  329. <p>
  330. As an example, the dependset task accepts nested filesets for two different functions :
  331. <ul>
  332. <li>source</li>
  333. <li>target</li>
  334. </ul>
  335. </p>
  336. <p>Stefan Bodewig/Costin Manolache suggest :</p>
  337. <pre class="code">
  338. &lt;dependset&gt;
  339. &lt;zipfileset ant:type=&quot;srcfileset&quot;&gt;
  340. &lt;/dependset&gt;
  341. </pre>
  342. <h4 class="subsection">
  343. <a name="adapters"></a>
  344. adapters
  345. </h4>
  346. <p>
  347. The antlib proposal mentions adapter classes, which would be connected to roles.
  348. Costin Manolache says that adapter classes should be tied to components, not roles.
  349. The reason : two different components implementing the same interface (AKA role) can require different adapters.
  350. </p>
  351. <h3 class="section">
  352. <a name="role proposal"></a>
  353. role proposal
  354. </h3>
  355. <p>
  356. slightly modified version of something writte by Jose Alberto Fernandez
  357. </p>
  358. <pre class="code">
  359. &lt;role name=&quot;roleName&quot; className=&quot;....&quot; [adapter=&quot;....&quot;] /&gt;
  360. &lt;!-- I have added the possibility to declare a specific adapter per component to take into account what Costin said --&gt;
  361. &lt;component name=&quot;elementName&quot; role=&quot;roleName&quot; className=&quot;.....&quot; [adapter=&quot;....&quot;] /&gt;
  362. </pre>
  363. </div>
  364. </div>
  365. <p class="copyright">
  366. Copyright &copy; 2000-2003&nbsp;The Apache Software Foundation. All rights reserved.
  367. <script type="text/javascript" language="JavaScript"><!--
  368. document.write(" - "+"Last Published: " + document.lastModified);
  369. // -->
  370. </script>
  371. </p>
  372. </body>
  373. </html>