| ClassContext |
|
Class Context (com.javelin.beans.ClassContext) Class Context provides a Factory class for creating new instances of classes. A Class Context class is created for each context. The ClassContext class is created in the $PACKAGE package with the name $CONTEXTNAMEContext.java. For example the Northwind Context has a context file called NorthwindContext.java. The actual class that is written out must be declared, like any another class, by a property in the context properties: - NorthwindContext=public class $PACKAGE.$CONTEXTNAMEContext extends com.javelin.beans.AbstractClassContext Every Class Context must obey a naming pattern convention. Remembering that in the JBeans design for every bean there is a Bean interface, with a Bean implementation, a BeanValidator, a Home interface with a Home implementation and a Session interface with a Session implementation. The Class Context has the following set of methods is created: - The Object based methods are used for special classes that are Objects. Objects are small (non-bean) objects such as a Frequency, that do not have a primary key, and when they are persisted they are folded into the bean.
For every bean the following methods are created.
N.B. The key based methods can pass in a user name, thread or other key. These methods will then create a singleton instance of the Home or Session for that key. |
|
Abstract Class Context Writer (com.javelin.beans.AbstractClassContextWriter) The Abstract Class Context Writer is a super class for the Class Context. The Abstract Class Context has the following utilities: -
|
|
Properties The Class Context file has pluggable Properties class. The Properties class essentially changes the implementation that is created for the Bean, Home or Session interface. The Properties class is a simple Properties class that binds a named interface to a named class. For example to bind the AccountInterface to an AccountBean the Jdbc Properties class states: - put( "com.javelin.jcommerce.Account.Bean", "com.javelin.jcommerce.lazy.LazyAccountBean"
); The Properties file can be written out by different Properties Writers. Each Properties Writer writes out a different Properties class into a named directory. Each Properties class writes out a different sets of set of bindings. The default Properties class used at run time is determined by a property in the context file: - ContextProperties=$PACKAGE.jdbc.JdbcContextProperties Or the properties can be set programmatically, for example: - NorthwindContext.setDefaultProperties( new JdbcContextProperties() ); The following Properties Writers have been written: -
For each Properties file written out it must be declared, like any other class,in the properties file. For example: - JdbcContextProperties=public class $PACKAGE.jdbc.JdbcContextProperties
extends java.util.Properties Context specific code can be run at start up. This code can be used to set system wide defaults for each specific Properties class. This code is declared using an indexed property. This will be added like normal custom methods, by not specifying a corresponding method property, the code is added to the constructor. For example to sets up the timezone, ssl and the default jdbc.properties file for the JdbcContextProperties file, do the following: JdbcContextProperties.code.0=System.getProperties().put(
"user.timezone", "Europe/London" ); |
|
Overriding the Bindings Occasionally it may be desirable to override a particular bean method, or subclass a bean implementation. It is possible to override the context bindings so that a different instance of the class is created. All the JBean classes have been designed to have their functionality overridden where it is sensible to do so. If a completely new set of bindings are needed an option is to explicitly set the context Properties class on the Class Context, as described above (either programmatically or in the context properties). Another option, for one off changes, is to change the initialization code, for example: - JdbcContextProperties.code.2=properties.put( "com.javelin.jcommerce.Account.Bean", "com.myproject.MyAccountBean " ); Another option is to change the bindings using special properties. The ClassProperties class is responsible for binding the JBeans interface names to implementations. The binding patterns are as follows: - <ClassName>.<Type>Implementation=<packageName>.<ClassName> <ClassName>.objectImplementation=<packageName>.<ObjectClassName> To override the bindings in the ClassProperties do the following: - Address.objectImplementation=com.xyz.MyAddress |
|
Stopping Writing Writing can be stopped at many levels This property stops any class being written: - write=false This property stops a class related to a table being written: - <ClassName>.write=false For example: - Address.write=false Specific classes can also be not written: - CJBAddress.write=false
|