Hi all,

As you might know, I've been experimenting with dynamic loading of optional
modules lately, and I've come up with a solution that seems to work ok. I'd
like to know what I'll explain how it works.

There is a new xdoclet.loader package which contains all the logic for
handling dynamic loading. Some of the classes in this package
(ModuleFinder/XDocletXmlParser) introspect jar files located in the same
directory as xdoclet.jar and look for a META-INF/xdoclet.xml "deployment
descriptor" in each of the jars it finds. If an xdoclet.xml file is found,
XDocletXmlParser looks for the following information:

-what subtasks the module contains, and what parent task they belong to.
-what tag handler the module contains, and the namespace they map to.

Everything is orchestrated by the Bootstrapper class (which is a task and
will replace <taskdef> for xdoclet tasks), and as the jars are introspected
it registers the classes (XDoclet core tasks like EjbDocletTask and
WebDocletTask) with the BootstrapClassLoader. This class loader is used as a
parent for an AntClassLoader, which will be used to load XDoclet classes.
Whenever BootstrapperClassLoader is asked to loadClass a class, it will
check if the requested class is one of the parent tasks that should be
instrumented to add createBlaBla methods.

The BootstrapperClassLoader uses BCEL (Jakarta's fantastic Byte Code
Engineering Library) to instrument the parent task classes during loading.
All it does is to dynamically insert createBlaBla methods so that Ant will
accept <blabla> sub elements to parent tasks (like <ejbdoclet>).

So far so good for optional subtasks. The other part is to register tag
handlers contained within the optional modules. Since XDoclet can be invoked
in a different VM, the tag handlers must be registered in the DocletMain
class. The registered subtasks "survive" the intra-vm transfer because the
subtasks are serialised in DocletContext. In XDocletMain's start method the
ModuleFinder.findModules() is called again, and this will register the tag
handlers. The actual registration is done inside XDocletModule, which
receives callbacks from XDocletXmlParser. XDoclet and Ant are now ready fit
for fight.

All the resources (dtds, templates and Message.properties) are located in a
resources folder beneath the classes. I suggest we put tag handlers and
subtasks in the same package (as done with WebLogic stuff). The best
argument I can think of for doing it this way is to keep related stuff close
together on the file system. I don't like to browse too much around for
related stuff.

I don't know if I have succeeded in describing how it works. It isn't as
complicated as it sounds. Take a peek under xdoclet.loader and the sample
weblogic module implementation, as well as the samples/build.xml arounf the
<ejbdoclet> task. It should give a fair picture for those of you who
understand code better than prose.

As ususal, I have been ego. Some of the other developers have made me aware
that I should share my thoughts and doings more with you guys. Therefore,
consider it all a fictual idea. Just let me know what you think.

Peace,
Aslak


_______________________________________________
Xdoclet-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-devel

Reply via email to