JGenerator

Overview

JGenerator is responsible reading meta-data into a Dictionary, using one or more readers, then producing files using one or more writers. Meta-data can be read in from any source (e.g. a properties file or database) and can produce any source (e.g. Java or SQL file, compile, bundle, deploy code). The diagram below illustrates how JGenerator works.

JGenerator (com.javelin.generator.JGenerator)

JGenerator is the main class that executes. JGenerator goes through 2 execution steps.

  • Execute Readers
  • Execute Writers

A Reader can be any class that implements the DictionaryReader interface or any file the implements the main method.

A Writer can be any class that implements the DictionaryReader interface or any file the implements the main method.

Execution

To run JGenerator give it the name of a properties file, this can be done from the command line or programmatically:-

Executing JGenerator from the command line type: -

>java com.javelin.generator.JGenerator C:/myproject/my.properties

Executing JGenerator programmatically: -

JGenerator().run( "C:/myproject/my.properties" );

It is often useful to create a class called GenerateProject and calling the execution line from its main method.

The JGenerator executes the following steps:-

  • Execute the Readers in order.
  • Execute the Writers in order.

The diagram below illustrates an example configuration where the Dictionary is first read in from the database, then supplemented by properties, then validated. The Writers, write out Files, then compile them, then deploys them.


Advanced Execution

With JGen you can insert extra BDL properties on your command line. This means you can customize the BDL from different generate classes.

e.g.

public class GenerateProject
{
     public static void main( String[] args )
     {
        com.javelin.util.jdbc.JPool.setRelativeClass( GenerateProject.class );
        new JGenerator().runWithProperty(" /project/web/web-inf/classes/com/project/project.properties",
        " writer.2=$GENERATOR.packaging.JarPackager project \n
        reader.1=$GENERATOR.Filter writer.2-" );
      }
}

Note then Filter writer, where the propertyName-, removes the property, as you can see above.

The above line tells the BDL to only package things up, and puts in a Filter reader to nobble the second writer (.2), so it doesn't go any further than writer.1

This way you get to run a single writer and not the run the JarPackager, in a standalond manner.

If you run it normally

new JGenerator().run( " /project/web/web-inf/classes/com/project/project.properties");

Then the JarPackager is not run.

Boot Strapping

Another form of call to JGenerator can be made under special circumstances to bootstrap a properties file from a database source. For this form of execution call the following: -

JGenerator().run( <source>, <properties file> );

Where the source name the name of a database specified in the local jdbc.propeties file. This boot strapping process can be used to create a basic properties file to create a project from.

Reading External Projects

JGenerator can be used to import properties from external projects. This feature is used to import data to the dictionary for projects that straddle across several business areas.

Reading an external project is specified as follows:-

reader.<index>=com.javelin.generator.JGenerator <bdf file name>

For example:-

reader.0=com.javelin.generator.JGenerator C:/Javelin/jcommerce/jcommerce.properties

When an external properties file is read in its data is put into its specific database. This database, and its related properties file can then be referred to by the project. The relationships section of this tutorial shows how you can have a property in bean refer to a bean in another project or database by prefixing its context name.

The diagram below illustrates how JGenerator class is defined as both a DictionaryReader and DictionaryWriter, this means it can be used itself as a Reader and Writer. This allows external projects to be imported, to populate the Dictionary and optionally to write out Files.

Writing External Projects

JGenerator can be used to both read and write multiple project files, in a predefined order.

Writing an external project is specified as follows:-

writer.<index>=com.javelin.generator.JGenerator <bdf file name>

For example:-

writer.0=com.javelin.generator.JGenerator C:/Javelin/jcommerce/jcommerce.properties

A simple properties file can contain a list of readers and writers that simply read and write external properties files. This feature can be used to build an entire enterprise wide set of files from a single properties file.

Dependencies

JGenerator is dependent on the JPool package for database access.

Other forms of Generation may use external packages, such as the tools.jar for Java compilation.