Template::Plugin::Java - Generate Java Classes from XML description files and templates.


From an xml file such as:

                <java: option1="value1">

Through the program "tjava":

tjava [options] [file.xml ...]

Via a template, such as:

        [% USE Java %]
        package $package;
        public class $class {
        [% FOREACH Java.variables %]
        $type $name = $initializer;
        [% END %]
        //... etc

To generated Java source code in the appropriate directory as determined by the package of the .xml file's directory, specified package option if any, and CLASSPATH.


Any options may be given besides those listed, these are passed directly to the Templates being processed in the stash (the variable table at time of processing). They can be given in the <java:> ... </java:> section of an XML file (in which case, don't use the -- dashes) as attributes or elements, or on the command line.


Name of the template to process. No extension is assumed by default unlike in the previous version.


Destination package to put the generated classes, otherwise will be determined from how the current directory relates to the CLASSPATH.


Class name to use, otherwise will infer from the root tag of the XML file.


Colon separated path where the templates can be found, overrides the environment variable TEMPLATEPATH. This doesn't work right now, so use the TEMPLATEPATH environment variable.


If set to 0, classes for subcontainers will not be generated. This is generally not useful.


By default set to Container, this is the default template, as well as the template used for sub-containers.


By default, if generating class Foo that needs to have a sub container wrapped in tag <bar>, it's name will be FooBar. This is safe and won't cause collisions with different classes having sub containers of the same name (until some sort of dependency checking code is introduced). To turn this off, set it to the empty string "".


Interface to add to list of implemented interfaces, can be supplied multiple times. Make sure you append any necessary code to implement any of these interfaces.


Text to insert in the generated class body.


Will insert text read from the file specified into the generated class body. This option and the --append option are mutually exclusive.


The XML file(s) to parse. This is useful for when the Plugin is instantiated from a custom script, not via tjava or inside a template.

Any other option will be placed into the stash for the templates to use, making tjava very useful with your custom templates.

Anything that's not an option will be assumed to be a file.


Template::Plugin::Java is a plugin module for the Template toolkit that makes it easier to write templates for generating Java source code, ultimately for transforming XML descriptions into Java language sources.

It can be used either directly on the command line, or loaded from a Template with a [% USE Java %] statement, or in many other ways. It tries to be intelligent and figure out what context you are using it in.

I'll write more eventually, for now see the examples in the distribution.



This, the constructor, does everything necessary to create a new instance of the Java plugin, based on context. If not given a context, takes control of the command line and then parses any options and files given. This is what the "tjava" utility does.


Sets the Template of the instance (and therefore the context) when called with a parameter, returns it otherwise.


Sets the Template::Context of the instance when called with a parameter, returns it otherwise.


Returns an initializer string for a type.


Returns a list of variable description hashes.


Returns a list of <type> <name> strings such as: String foo int bar ...

These can be used in a template in this way: function ([% Java.variableDeclarations.join(", ") %]) { ... }


Returns a list of variable names.


Returns a hashref of variables, taking a raw variables hash. Takes an optional variable type string.


Whether or not a java type is a Scalar type.


Whether or not a java type is a String type.


Whether or not a java type is an Array type.


Figures out the type of elements a Vector will take. Parameters: name, arrayref TODO: This should be an aggregate, not merely the type of the first element.


Translate int to Integer, long to Long, etc.


Maps a perl scalar or reference to a Java type. Parameters: name of element, value of element.


Generates a container class.

Parameters: name of tag to create container from, hashref to gen from. Returns: name of class generated.


Casts a java String to another type using the appropriate code. Parameters: name of variable to cast, type to cast to.


These are the environment variables used.


Colon separated path to where templates can be found. Overridden by the --templatePath command line option.


Used for many things, like inferring the package of the current directory, where to put generated files that are in other packages, and other evil things I have not yet thought of.


Rafael Kitover (


This program is Copyright (c) 2000 by Rafael Kitover. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


Probably many.

The --templatePath option should actually work.


A very great deal. Including more documentation. DBClass doesn't work in tt 1.x. Non-sense options in java: contexts should be somehow handled?


perl(1), Template(3), Template::Plugin::Java::Utils(3), Template::Plugin::JavaSQL(3) Template::Plugin::Java::Constants(3),