Context Properties

ContextProperties (com.javelin.generator.dictionary.ContextProperties)

JGenerator reads properties from a class called ContextProperties. This is a java.util.Properties class with helpful methods on it.

The JGenerator populates the ContextProperties from either a database (using the JdbcReader) or a properties file (using the PropertiesReader). A properties file is always necessary to tell the JGenerator which readers and writers to execute.

JGenerator uses a powerful macro parser called the MacroPropertiesParser to make specification of properties easier. See Macro Parser for more details.

The ContextProperties class has the following functionality: -

  • Property Accessors.
  • Utilities for <table>.<column>.<key> patterns.
  • Class Name Parsing Utilities.

Default Properties

A set of default properties exists that defines a common set of properties across all projects. Default properties are defined in a defaultbdl.properties file in the com.javelin.generator package.

The properties specified in the defaultdbl.properties file are read in by the code generator at initialization. These defaults can be overridden by the context properties file. Some of the default properties are listed below.

The Default Project Properties require that 3 mandatory macro properties are defined in the context properties file.

  • $CONTEXTNAME : The name of the current context.
  • $ROOT : The path to generate the code to.
  • $PACKAGE : The name of the 'default' package.
  • $JBEANS: The ClassPath to the JBeans

In a project file these properties must be defined, for example:-

$CONTEXTNAME=Northwind
$ROOT=C:/javelin/northwind
$PACKAGE=com.javelin.northwind
$JBEAN=C:/javelin/jbeans

PathName

The default.pathName property refers to the directory where the JSP,web, EJB, SQL is created, this is defaulted to

default.pathName=$ROOT/web

This can be overridden to a specific directory, to create different versions, and different 'uber-roots'etc. For example: -

default.pathName=$ROOT/northwind

For different types of files (e.g. SQL) this can be overridden.

For example:-

sql.PathName=$ROOT/northwind
ejb.PathName=$ROOT/northwind
web.PathName=$ROOT/northwind
classes.PathName=$ROOT/northwind/WEB-INF/classes

Class Name Patterns

The JGenerator needs to know the fully qualified name of every class. Rather than define every class for every table the macro property parser defines a pattern for each type of class to be created. These class name patterns are defined in the defaultbdl.properties file.

A writer in JGenerator will not create a class if that class name is not found in the properties file.

These class name patterns are then used by the various Writers to write out the class names into their correct packages, and create the correct import statements etc. Declaring the class name pattern in the properties file doesn't mean that the class will be created, just that all the writers that refer to those classes can access those class name patterns.

Each class name pattern is defined using a macro the default properties file. This macro can then be expanded for each specific class.

For example the following macros define 3 class name patterns: -

$INTERFACE=public interface $PACKAGE.$THIS extends $BEANS.Bean java.lang.Cloneable
$BEANCLASS=public class $PACKAGE.$THIS extends $BEANS.AbstractBean implements $PACKAGE
$VALIDATOR=public class $PACKAGE.$THIS extends $BEANS.AbstractBeanValidator

These patterns can then be expanded by the macro property parser to create instances of the fully qualified class name using the $CREATE macro (see below for more details).

Creator Properties

Defining a class pattern in the default properties file doesn't mean that the class name will be expanded. To expand a class name for a particular class the $CREATE macro is used.

The $CREATE macro can define one or more patterns to be expanded for a particular class. In the context properties file this macro can be expanded using the syntax: -

$CREATE <Creator Macro> <Table Name>

For example 3 class names can be expanded for the Address class as follows: -

$CREATE $INTERFACE,$BEANCLASS,$VALIDATOR Address

This macro will be expanded to the following classes: -

Account=public interface Account extends JBean, Cloneable
AccountBean=public class AccountBean extends AbstractBean implements Account
AccountValidator=public class AccountValidator extends AbstractValidator

For example, this defines a macro called $BEANCREATOR which defines all set of classes necessary to create a set of JBeans and their interfaces.

Because the macro parser allows recursive expansion groups of class name patterns can be expressed as a single macro to ensure that groups of classes are created together.

For example: -

$BEANCREATOR=\
$SELF=$INTERFACE,\
$SELFBean=$BEANCLASS.$SELF,\
$SELFHome=$HOME,\
$SELFSession=$SESSION,\
$SELFValidator=$VALIDATOR,\
$SELFKey=$KEYCLASS,\
$SELFHolder=$HOLDER.$SELF

For example to define all the Bean classes for the Account table, simple call: -

$CREATE $BEANCREATOR Account

This macro then (cleverly) expands to: -

Account=public interface Account extends JBean
AccountBean=public class AccountBean extends AbstractBean implements Account
AccountHome=public class AccountHome extends BeanHome
AccountSession=public class AccountSession extends BeanSession
AccountValidator=public class AccountValidator extends AbstractValidator
AccountKey=public class AccountKey extends AbstractValidator
AccountHolder=public class Accountholder

The following macro sets have been defined: -

  • $CREATOR - create CJ B, Jdbc, Memory class definitions
  • $BEANCREATOR - create bean classes and interfaces.
  • $MEMORYCREATOR - create the classes for 1-tier implementation
  • $JDBCCREATOR - create the classes for 2-tier implementation
  • $EJBCREATOR - create the classes for EJB 3-tier implementation
  • $CJBCREATOR - create the classes for JBeans 3-tier implementation
  • $ENUMCREATOR - create an Enumerated Type
  • $BEANTYPECREATOR - create an abstract Bean Type

Logging

Logging uses the default logging facility. Documented in the java.util.logging directory. The logger uses the name of the source.

By default the logging is WARNING. To change the level of the logging you can either update the jre/lib/logging properties file by adding:

<source>.level=SEVERE

Alternatively you can set it in the Context directly.

GymContext.code.0=Logger.getLogger( "gym" ).setLevel( Level.SEVERE );