> But I also need to write a custom sub-task in order to pre-filter
which
> classes get processed, and also possibly where the resultant files get
> placed.
>
> Is there a good example I should follow for this?
XDoclet's own source files. If you generate a per-class output then look
at EntityPkSubTask for example, or if you're outputting a single xml/etc
file look at EjbDotXmlSubTask. It's easy to understand, look at SubTask
and TemplateSubTask classes, you'll understand it totally.
> What base class should I extend? [my guess: TemplateSubTask]
Yup, you're using a template file, right?
> What methods are required for me to implement? [my guess: at least
> execute()
> and getSubTaskName, probably engineStarted]
Depends on what you're going to do, if you want to control which files
should be processed and something generated for then you have to
override matchesGenerationRules and return true if the class satisfies
the rules.
> I notice that InfoSubTask has this constructor:
> public InfoSubTask( DocumentDocletTask documentDocletTask )
See EjbDocletTask.getSubTasks() as an example. You see some tasks are
created in a special order (it's important to run entitypk before
dataobject for example, though I'm not sure this is still true!!). Note
that there's this special doclet class which covers other subtasks for
ejb, there's webdoclet for web and depending on the complexity you may
decide to have an antdoclet if you want to give it an identity of its
own. But you don't have to, you can use bare templatedoclet for example,
put a <template/> in it but with subTaskClassName attribute set
(<template subTaskClassName="ant.tasks.MySubTask"/>). TemplateSubTask
knows how to use your subtask class.
> How are sub-tasks constructed? They don't seem to require this kind
of
> constructor - but this gives me the task context so that I can log
through
> Ant's mechanisms. :) Oops... a bit of digging while typing this
message
> turns up this in DocletTask:
>
> Class subtask_class = Class.forName( holder.getSubTaskClassName()
);
> TemplateSubTask subtask = ( TemplateSubTask )
> subtask_class.newInstance();
>
> D'oh! *darn* - I guess default constructor it is, and I see where
> InfoSubTask is constructed differently. This is one area where you
guys
> could steal from Ant as far as dynamic construction goes. It would be
> slicker if the subtasks could have the DocumentDocletTask constructor
and
> it
> would be used instead of the no-arg constructor if it exists - then my
> custom subtask could tap into the Ant task context (yes, I understand
this
> couples some, but hey, I'm an Ant guy and I want to log some things
> without
> using log4j so that verbosity levels can be controlled with Ant
command-
> line
> switches! :).
This Class.forName stuff is only used for subTaskClassName, where
there's no other option than do a Class.forName because the class name
is a literal. Having a default constructor is not a big deal.
> - Do not process non-Task classes (i.e. no execute() method). How
would I
> do
> this in a custom subtask?
Well as you've described ofType is not enough. So work on the
getCurrentClass() in matchesGenerationRules() and search for a method
called execute()/blabla and so on. Use clazz.method() and iterate, if
you want to check superclasses too then put it inside a while loop and
operate on superclass() too. Plenty of such codes in sources....
> - Do not process inner classes. What code is needed for this?
Do a clazz.containingClass()==null.
> How do I integrate this into my build file? Here's what I've got so
far:
>
> <document sourcepath="../../src/main"
> destdir="${gen.dir}"
> classpathref="xdoclet.classpath">
> <fileset dir="${src.dir}">
> <include name="*.java"/>
> </fileset>
> <template templateFile="${xdoc.template}"
> destinationfile="{0}.xml" extent="concrete-type"/>
> </document>
>
> Do I just add subTaskClassName="..." to my <template> subtask to have
it
> use
> my custom subtask? [my guess: yes, this appears to be how it works]
Yes, but you can create an antdoclet instead of document if you like and
instantiate it right there.
> Thanks for any advice you can provide me. I think I'm on the right
path,
> but want to be sure by just tossing this out there and hearing
suggestions
> from folks.
This seems to be a very heavy subtask, you're loading and processing all
classes! At least for the first run it'll be slow, but after the first
run it should be fast because xdoclet will not try to regenerate for
unchanged classes, and needless to say you can do other filtering in
your subtask too.
Ara.
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
_______________________________________________
Xdoclet-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-devel