org.objectweb.jonathan.tools

Class Kcf2java


public class Kcf2java
extends java.lang.Object

Kcf2java (formerly called XML2Kernel) is a utility that compiles an XML configuration file into a java class, and possibly compiles it and adds the compiled file to a jar archive. This utility expects that the javac and jar commands are available locally.

The name of the java class to generate should be specified as the "generated" attribute of the configuration element; the class used to create the actual bootstrap configuration should be specified using the "bootstrap" attribute, like in : ...

Usage: java org.objectweb.jonathan.tools.Kcf2java [options] configuration-file where options are:

Kcf2java has already a built-in configuration decoder, and already knows the following default tag compilers:

A custom tag compiler has to implement the TagCompiler interface and to be provided as a line like the next one in the Kcf2java properties file:
CUSTOM_XML_TAG_TO_COMPILE my.custom.tag.Compiler

Method Summary

static void
compile(InputStream _is, String _src_dir, boolean _add_package_path_to_src_dir, Properties _custom_properties, boolean _verbose, boolean _compile)
Compilation method to be used when Kcf2java is embedded in some application.
static void
main(String[] args)
The main method.
static String
normalize(String str)
Normalizes the provided string, by trimming and handling backslashes
static String
writeComponent(XMLElement _current_component, String _element_name, String _configuration_var_name, Writer _writer, String _configuration_name)
Compiles the provided component using the provided writer.

Method Details

compile

public static void compile(InputStream _is,
                           String _src_dir,
                           boolean _add_package_path_to_src_dir,
                           Properties _custom_properties,
                           boolean _verbose,
                           boolean _compile)
            throws JonathanException
Compilation method to be used when Kcf2java is embedded in some application.

Parameters:
_is - an InputStream to the configuration to compile;
_src_dir - the directory where the source files should be generated;
_add_package_path_to_src_dir - true if Kcf2java should generate the file taking into account the package name of the class to generate, false if the file should be generated directly in _src_dir
_custom_properties - the properties representing custom tag decoders;
_verbose - indicates whether error messages and warnings should be output to stderr
_compile - indicates whether the generated Java file should be compiled.

Throws:
JonathanException - if something goes wrong.


main

public static void main(String[] args)
The main method.

Parameters:
args - see the description of the Kcf2java class.


normalize

public static String normalize(String str)
Normalizes the provided string, by trimming and handling backslashes

Parameters:
str - the string to normalize

Returns:
the normalized string


writeComponent

public static String writeComponent(XMLElement _current_component,
                                    String _element_name,
                                    String _configuration_var_name,
                                    Writer _writer,
                                    String _configuration_name)
            throws IOException
Compiles the provided component using the provided writer.

Parameters:
_current_component - the component to compile
_element_name - its name in the current configuration
_configuration_var_name - the variable name of the current configuration (may be null)
_writer - the writer to which the compiled version is output
_configuration_name - the absolute name of the current configuration

Returns:
the name of the variable used in the Java compiled file to represent the compiled component