Make the configuration

It is time to put everything together in the configuration file, command-chain.xml

All alias (outgoing transitions) used by JSP's is associated to a command-chains in the Action URLs mapping section. This mapping makes a loose coupling between the JSP's and the command-chains, and thus several alias can be used for the same command-chain.

In the example the alias login is associated with the command-chain handleLogin.

Example 10.14. command-chain.xml, action URLs mappings

            <actions>
                <action name="login"            chain="handleLogin" />
                <action name="logout"           chain="handleLogout" />

                <action name="main"             chain="main" />

                <!-- CREATE -->
                <action name="add"              chain="handleAddComponent"/>
                <action name="create"           chain="handleCreateComponent"/>
                <action name="createManifest"   chain="handleCreateManifest"/>
                <action name="createAnnotation" chain="handleCreateAnnotation"/>
                
                

In the command definition section is the implementation of a command associated with a name and initialization parameters. This is convenient when the command is used with the same parameters in several command-chains. Defining all commands is not nessesary, but I find the command-chain definition section to become more readable using shorter names for the commands, but again it is a matter of taste. This is optional as a command implementation can be defined inline in a command-chain definition.

Example 10.15. command-chain.xml, a command definition

                <command-def name="ReadModel"
                             class="se.kmr.scam.client.http.command.ReadModel">
                   <init-param name="depth" value="0"/>
                   <init-param name="maxDepth" value="1"/>
                   <init-param name="includeAnnotations" value="false"/>
                </command-def>
                
                

The header of command-chain definitions section defines a default command-chain, an error handler command-chain and the default command chain executor class. The default command-chain is executed when no alias is provided in the request. The error handler is executed in case of an, unhandled, exception occures in the command chain executor.

Example 10.16. command-chain.xml, a command-chain definition header

                <chain-defs default="main"
                            errorhandler="error"
                            defaultclass="se.kmr.scam.client.http.CommandChainImpl">


                    <!-- LOCAL: Base chain -->
                    <chain name="_baseChain" class="se.kmr.scam.client.http.CommandChainImpl">
                         <command-ref ref="SyncManifest"/>
                    </chain>
                    
                

This example includes the definition of the _baseChain command-chain. Since no alias is associated with this name can this command-chain not be requested directly. The class attribute value overides the value of the default class defined in the header.

Example 10.17. command-chain.xml, a command-chain definition

                    <chain name="handleCreateManifest" extends="_baseChain">
                        <command-ref ref="CreateManifest"/>
                        <command-ref ref="CreateDefaultModel"/>
                        <command-ref ref="StoreModel"/>
                        <include chain="_editView"/>
                    </chain>
                    
                

An alternative to define the same sequence of command in several command-chains is to include other command-chains. The include directive will append commands from the referenced command-chain into current command-chain definition. The command-chain definition attribute extends conveniently prepends the referenced command-chain into the current command-chain .