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.xml 9.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <?xml version="1.0"?>
  2. <document>
  3. <properties>
  4. <index value="2"/>
  5. <author email="antoine@apache.org">Antoine Levy-Lambert</author>
  6. <title>Roles</title>
  7. </properties>
  8. <body>
  9. <section name="What is a role">
  10. <p>
  11. I am quoting here Jose Alberto Fernandez 26.04.2003 22:05:
  12. Roles allow defining families of objects (members of a role) that can be
  13. used by tasks or inner elements developed separately.
  14. The developer of the object accepting a particular role as a subelement
  15. has no knowledge of the implementation of the object but much more
  16. importantly it has no knowledge of the XML element tag used to refer
  17. to this subelement in the XML file.
  18. </p>
  19. <p>
  20. In the antlib proposal, there are two preset roles :
  21. <ul>
  22. <li>task</li>
  23. <li>datatype</li>
  24. </ul>
  25. Examples of other roles are :
  26. <ul>
  27. <li>mapper</li>
  28. <li>filter</li>
  29. </ul>
  30. </p>
  31. <p>
  32. What does it all mean? It means we can now write a task, well typed, which
  33. can be accept different XML subelements depending on the declarations of
  34. other objects present on the build. The vendor specific elements of
  35. &lt;ejbjar&gt;, &lt;jspc&gt; and others are typical examples of where this capability
  36. can be very useful. Other parts of core could benefit of course.
  37. </p>
  38. <br/>
  39. <subsection name="What do they do that is no possible in ANT">
  40. <p>
  41. They allow IntrospectionHelper to connect an XML subelement eventhough
  42. introspection cannot find a create or add/Configured method for it.
  43. It is a well typed methanism, the parent object will only be passed objects
  44. that it knows how to deal with. And the parent object does not need to have
  45. any knowledge of what currently available members are on the role.
  46. </p>
  47. </subsection>
  48. </section>
  49. <section name="roles versus DynamicConfigurator">
  50. <p>
  51. The closest thing in ANT today is DynamicConfigurator but its purpose
  52. is on the other way around. Given an elementTag with no matching method
  53. it is up to the parent object to try to make sense of it.
  54. If we were to use this mechanism to accomplish what roles try to do,
  55. it would require the parent object implementor to be aware of where
  56. to find the correct definition (remember it is a 3rd party implementation)
  57. and perform the creation. It will be also its responsibility to
  58. resolve type conflicts, name collisions, etc. This are all things
  59. that should be done by IntrospectionHelper directly.
  60. </p>
  61. <p>
  62. Also notice that Roles do not supersede DynamicConfigurator. On one hand roles
  63. let external implementations to be considered as possible subelements
  64. of a parent object, on the other hand, DynamicConfigurator allows a node
  65. to decide given its current state what is the meaning of a particular element.
  66. This cannot be done by roles in the general case, and that is good.
  67. </p> </section>
  68. <section name="Implementation of roles in the proposal">
  69. <p>this section quotes Jose Alberto Fernandez</p>
  70. <p>
  71. Here I may deviate from the exact code and add thoughts about where
  72. do I think it should go.
  73. </p>
  74. <subsection name="Usage of Roles">
  75. <p>
  76. The principle is very simple:
  77. </p>
  78. <br/>
  79. <ol>
  80. <li>
  81. A role is defined by an interface. This interface is the parameter
  82. for a new special family of addConfigured(&lt;interface&gt;) methods.
  83. </li>
  84. <li>
  85. <p>
  86. When IntrospectionHelper fails to find a create/add method for the
  87. element, it will look at all the roles used in the addConfigured
  88. methods and on each of those roles will try to find an object declared
  89. with that element-tag name. If one and only one match is found then
  90. the instantiation is successful and the new object will be configured;
  91. otherwise it is an error and parsing stops.
  92. </p>
  93. <br/>
  94. </li>
  95. <li>
  96. <p>
  97. The configured object may or may not implement the Role interface,
  98. if it does not, an Adaptor object may be instantiated as a proxy
  99. for the object. Which adaptor is used depends on how the implementation
  100. was declared.
  101. </p>
  102. <br/>
  103. </li>
  104. <li>
  105. <p>
  106. The resulting object is passed as an argument to the addConfigured() method.
  107. </p>
  108. <br/>
  109. </li>
  110. </ol>
  111. </subsection>
  112. <subsection name="Declaration of roles">
  113. <p>
  114. A role definition associates a name with an (Interface,Adaptor) pair.
  115. The only reason for associating a name with the role is to ease notation when
  116. declaring members of a role.
  117. </p>
  118. <br/>
  119. <p>
  120. Notice that the same interface or the same Adaptor may appear in multiple
  121. declarations. This only means that depending on the name used the adaptor
  122. of choice will be different.
  123. </p>
  124. <br/>
  125. <p>
  126. There can only be one pair associated with each name.
  127. </p>
  128. <br/>
  129. </subsection>
  130. <subsection name="Declaration of implementations (members)">
  131. <br/>
  132. <p>
  133. A class is declared as belonging to a role by specifying the name to be used
  134. when appearing in that role. The same class may belong to multiple roles
  135. and may specify the same or different names on each one.
  136. <br/>
  137. </p>
  138. <p>
  139. The name used for the role during the declaration only determines which
  140. Adaptor will be available, if required.
  141. <br/>
  142. </p>
  143. <p>
  144. Within a role-interface there can only be one object associated
  145. with each name.
  146. <br/>
  147. </p>
  148. </subsection>
  149. <subsection name="Scoping rules">
  150. <br/>
  151. <p>
  152. This is probably the more dificult aspect since given the way
  153. &lt;ant&gt; and &lt;antcall&gt; work it means possible redeclarations on every
  154. level of recursion. Whether declarations should just supercede
  155. one another or be smarter is something to look into.
  156. <br/>
  157. </p>
  158. </subsection>
  159. <subsection name="Syntax">
  160. <br/>
  161. <p>
  162. I have left out the issues of how the syntax looks like on purpose.
  163. <br/>
  164. </p>
  165. <p>
  166. Syntax is just that and I am sure we can reach agreement somehow.
  167. It is also clear that we should provide tasks to define roles
  168. and declare members of roles direclty on the build.
  169. <br/>
  170. </p>
  171. </subsection>
  172. </section>
  173. <section name="Making ant aware of tag/role/class associations">
  174. <p>
  175. The antlib proposal says :
  176. Let's declare explicitly that a tag can be used in a particular role and is implemented by a specific class.
  177. The declaration happens inside antlibs in the file META-INF/antlib.xml
  178. </p>
  179. Example :
  180. <source><![CDATA[
  181. <filter name="escapeunicode" class="org.apache.tools.ant.filters.EscapeUnicode"/>
  182. ]]></source>
  183. <p>
  184. CM says :
  185. A normal typedef is enough to make ant aware of the existence of the class org.apache.tools.ant.filters.EscapeUnicode.
  186. Due to the fact that EscapeUnicode implements ChainableReader, the association between EscapeUnicode and the filter role does not need to be stated explicitly.
  187. </p>
  188. </section>
  189. <section name="Method names in parent classes supporting roles">
  190. <p>
  191. 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.
  192. </p>
  193. <p>
  194. CM :
  195. <source>
  196. addTYPE(TYPE)
  197. </source>
  198. for instance <source>addChainableReader(ChainableReader a)</source>
  199. </p>
  200. <p>
  201. PR:
  202. to add an element before its own attributes and nested elements are configured.
  203. <source>
  204. void add(TYPE)
  205. </source>
  206. to add an already configured element
  207. <source>
  208. void addConfigured(TYPE)
  209. </source>
  210. </p>
  211. <p>
  212. in the ant code of 1.6 :
  213. <source>public Object createDynamicElement(String name)</source>
  214. </p>
  215. </section>
  216. <section name="Cardinality problems">
  217. <subsection name="One tag, several implementations">
  218. <p>
  219. The &lt;weblogic&gt; element in &lt;ejbjar&gt;, &lt;jspc&gt;, &lt;serverdeploy&gt;, has different meanings.
  220. </p>
  221. <p>
  222. This is an argument to introduce roles in ant, and to associate an XML tag with a role and an implementation class.
  223. </p>
  224. </subsection>
  225. <subsection name="Parent classes accepting one interface in different functions">
  226. <p>
  227. As an example, the dependset task accepts nested filesets for two different functions :
  228. <ul>
  229. <li>source</li>
  230. <li>target</li>
  231. </ul>
  232. </p>
  233. <p>Stefan Bodewig/Costin Manolache suggest :</p>
  234. <source><![CDATA[
  235. <dependset>
  236. <zipfileset ant:type="srcfileset">
  237. </dependset>
  238. ]]></source>
  239. </subsection>
  240. <subsection name="adapters">
  241. <p>
  242. The antlib proposal mentions adapter classes, which would be connected to roles.
  243. Costin Manolache says that adapter classes should be tied to components, not roles.
  244. The reason : two different components implementing the same interface (AKA role) can require different adapters.
  245. </p>
  246. </subsection>
  247. </section>
  248. <section name="role proposal">
  249. <p>
  250. slightly modified version of something writte by Jose Alberto Fernandez
  251. </p>
  252. <source><![CDATA[
  253. <role name="roleName" className="...." [adapter="...."] />
  254. <!-- I have added the possibility to declare a specific adapter per component to take into account what Costin said -->
  255. <component name="elementName" role="roleName" className="....." [adapter="...."] />
  256. ]]></source>
  257. </section>
  258. </body>
  259. </document>