The project chain-conf offers a little helper for doing a comfortable configuration of the commons-chain
framework. It offers a facade for accessing a simple command or a chain of commands and configuring
the chains via several configuration methods.
At second the framework offers a dependency-check for configured commands. If a command or chain
The chain-conf project offers several methods to configure the chains:
The chain-conf framework offers a single point of entry the ChainFacade
-Object. This
facade holds a ChainConfiguration
-Interface which may have several implementations.
The checking algorithm is implemented in the ChainConfigurationBase
class.
In version 1.0 there ist only the posibility to configure the framework with xml files. The
ChainConfigurationBase
-class holds also a PropertyReader
which holds the configuration of the
chain-conf framework but it is optional.
For dependency checking the commands must be inherited from the DependCommand
-Object. Each
DependCommand
can register other commands by name or by classname which depends with this
command.
The chain-conf facade is the single point fo access to the framework.
public interface ChainFacade { void initFacade() throws ChainException; void destroy(); ChainConfiguration getConfiguration(); boolean execute(String commandString, Context context) throws ChainException; }
ChainFacade
objects can be directly instanciated with a factory method of the
implementation class. In further versions there will be a object factory to
create implementation classes.
ChainFacade facade = ChainFacadeImpl.getInstance();
After creating an instance the facade can be initialized with the initFacade()
-
method. The commands or chains can be executed by calling the execute()
-
method.
The configuration of the commands or chains is doing by describing the chains in a xml file.
The file must be loaded by a classloader and is default in the package org.strutsit.chain.config and
named chain-config.xml
. The package and the name can be changed with the
chain.properties
file. First a short example:
<chains> <command name="Test-Command" className="org.strutsit.chain.CommandForTestTrue"/> <command name="Test-Command2" className="org.strutsit.chain.CommandForTestFalse"/> <chain name="double"> <command className="org.strutsit.chain.CommandForTestFalse"/> <command className="org.strutsit.chain.CommandForTestTrue"/> </chain> <chain name="single"> <command className="org.strutsit.chain.CommandForTestTrue"/> <command className="org.strutsit.chain.CommandForTestFalse"/> </chain> <chain name="depend" checkDependencies="true"> <command className="org.strutsit.chain.CommandForTestFalse"/> <command className="org.strutsit.chain.CommandForTestTrueDepend"/> </chain> </chains>
This xml file describes two single commands (Test-Command and Test-Command2) that
can be executed. Also there is described two chains (single and depend). Each chain
contains to commands. If a command returns true, the attention handling of the
chain will be stopped. If you set the attribute checkDependencies
to
true, the framework will do a validation check for you.
To execute a chain simply do it with the methods of the facade:
// Creating a context for this operation Context context = new ContextBase(); ChainFacade facade = ChainFacadeImpl.getInstance(); try { facade.execute("double", context); } catch (ChainException e) { // do something }
With the chain-properties
you can configure some things of chain-conf. This file
must be accessible from the classloader. First you
can choose the way of configuring the framework. In version 0.5 you may only choose xml.
Then you can choose a package in the classpath where the framework can found the xml and which name this xml file has.
# Configuration for the chain-conf framework. If no configuration # file is found, xml-mode is assumed # Configuration mode: Maybe xml|prop|class chain.configuration=xml # Full qualified java class of the XML-Configuration chain.configuration.xml=org.strutsit.chain.configuration.ChainXMLConfiguration # Full qualified java class of the Chain-implementation. If no Dependencycheck # is need also the original class maybe used org.apache.commons.chain.impl.ChainBase chain.baseclass=org.strutsit.chain.configuration.ChainConfBase; # Name of the configuration item default is: # xml : /org/struts-it/chain/config/chain-config.xml # prop : /org/struts-it/chain/config/chain-config.properties # class : org.strutsit.chain.config.Configure.class configuration.name=/chain-config.xml
If a specific chain needs a predecessor to fulfill his command he can register a class that must be executed. For those chain-conf offers a DependCommand-Object. You can either register a full qualified classname or a commandname.
/** Registers the CommandForTestFalse as dependency * @see org.strutsit.chain.DependCommand#doRegister() */ public void doRegister() { this.registerClassName("org.strutsit.command.CommandForTestFalse"); }
For checking configuration you have to do one thing in the chain-conf.xml configuration file: Setting the checkDependencies flag of true.
<chains> <chain name="depend" checkDependencies="true"> <command className="org.strutsit.chain.CommandForTestFalse"/> <command className="org.strutsit.chain.CommandForTestTrueDepend"/> </chain> </chains>