NAME

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

SYNOPSIS

From an xml file such as:

<aBean>
	<java: option1="value1">
		<option2>value2</option2>
	</java:>
	<foo>10</foo>
	<bar>String</bar>
	<container>
		<baz>20</baz>
	</container>
</aBean>

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.

OPTIONS

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.

--template

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

--package

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

--class

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

--templatePath

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.

--genContainers

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

--containerTemplate

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

--containerNamePrefix

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

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.

--append

Text to insert in the generated class body.

--appendFile

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

--file[s]

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.

DESCRIPTION

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.

METHODS

new

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.

template

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

context

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

getInitializer

Returns an initializer string for a type.

variables

Returns a list of variable description hashes.

variableDeclarations($options_hashref)

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(", ") %]) { ... }

variableNames

Returns a list of variable names.

getVariables

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

scalar

Whether or not a java type is a Scalar type.

string

Whether or not a java type is a String type.

array

Whether or not a java type is an Array type.

arrayType

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.

encapsulatePrimitive

Translate int to Integer, long to Long, etc.

mapType

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

genClass

Generates a container class.

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

castJavaString

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

ENVIRONMENT

These are the environment variables used.

TEMPLATEPATH

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

CLASSPATH

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.

AUTHOR

Rafael Kitover (caelum@debian.org)

COPYRIGHT

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.

BUGS

Probably many.

The --templatePath option should actually work.

TODO

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?

SEE ALSO

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