FSM Tool includes Ant tasks for seamlessly integrating code generation with existing build infrastructure.

Below are:

Declaring the Ant tasks

The FSM Tool Ant tasks are:

  • fsmtool:make-multi-fsm-sbb — generates an SBB Java class to host one or more generated Java classes for each state-machine specification.

  • fsmtool:generate-fsm — generates SBB Java class for the state-machine specification.

  • fsmtool:generate-dot — generates a GraphViz compatible dot file that visualises the state machine diagram.

The FSM Tool Ants task must be declared in the Ant build.xml file using a <taskdef> tag. The FSM Tool ships with the fsmtool.jar file, which contains the Ant tasks. You need to install it in a path referenced by the <taskdef>. In the "Hello World" example, the jar file is in the ${basedir}/lib directory. To declare the tasks, add an fsmtool namespace attribute to the <project> tag, and then use the <taskdef> to pick up all task declarations from the antlib.xml file (which is contained in the fsmtool.jar).

<project name="{product-name} Example Service" default="help" basedir="." xmlns:fsmtool="antlib:com.opencloud.sce.fsmtool.ant">
...
    <target name="init" depends="management-init">

        <path id="fsmtool.classpath">
            <fileset dir="${basedir}/../libs" includes="*.jar"/>
        </path>
        <taskdef uri="antlib:com.opencloud.sce.fsmtool.ant"
                 resource="com/opencloud/sce/fsmtool/ant/antlib.xml"
                 classpathref="fsmtool.classpath"/>
        ...
    </target>
...
</project>

Ant task parameters

The make-multi-fsm-sbb, generate-fsm and generate-dot tasks use the following attributes.

make-multi-fsm-sbb

Attribute Description Type
sbbClassName

Class name for the generated SBB class.

Required

package

Package name for the output.

Required

destDir

Destination directory for the generated classes; for example:

${basedir}/src/helloworld/com/opencloud/slee/services/fsmtool/helloworld

Required

tracerName

The prefix used for trace messages.

Required

Element Description Type
fsmtool:fsm

FSM specification details.

One or more required

The fsmtool:fsm element has the following attributes:

Attribute Description Type

specification

Filename of the FSM specification from which to generate code; for example:

${basedir}/src/helloworld/com/opencloud/slee/services/
fsmtool/helloworld/FsmToolExampleStateMachineSbb.fsm
Required

fsmClassname

Class name for the generated FSM class.

Required

fsmFullClassname

Package path and class name for the generated FSM class.

generate-fsm

Attribute Description Type
fsmSpecificationFilename

Filename of the FSM specification from which to generate code; for example:

${basedir}/src/helloworld/com/opencloud/slee/services/
fsmtool/helloworld/FsmToolExampleStateMachineSbb.fsm

Required

fsmTemplateFilename

Path and filename of the template to use for code generation; for example:

templates/fsm.stg
Note If the file cannot be found in the given path and filename combination on the filesystem, the task automatically checks if the file exists as aresource contained in the fsmtool.jar. The standard fsm.stg template is a resource in the fsmtool.jar. Set fsmTemplateFilename="templates/fsm.stg" to use it.

Required

package

Package name for the output.

Required

fileType

Suffix for the generated file. For fsm.stg, must be set to java.

Required

class

Class name for the generated code.

Required

superClass

A Java class which will be the super class of the generated state-machine SBB. If set, a fully qualified class name is required.

Optional

outputRootDirectory

The root directory used to write the generated class file. The package subdirectory structure will be created automatically.

Required

tracerName

The prefix used for trace messages.

Required

generate-dot

Attribute Description Type
fsmSpecificationFilename

Filename of the FSM specification from which to generate code; for example:

${basedir}/src/helloworld/com/opencloud/slee/services/
fsmtool/helloworld/FsmToolExampleStateMachineSbb.fsm

Required

fsmDotTemplateFilename

Path and filename of the template to use for the dot-file generation; for example:

${basedir}/templates/fsm.dot
Note If the file cannot be found in the given path and filename combination on the filesystem, the task automatically checks if the file exists as aresource contained in the fsmtool.jar. The standard dot.stg template is a resource in the fsmtool.jar. Set fsmTemplateFilename="templates/dot.stg" to use it.

Required

outputFile

Path and filename to write the resulting state-machine dot-diagram code to.

Required

Examples for code-generation templates

Below are examples of FSM Tool Ant task definitions using the fsm.stg and dot.stg templates, from the "Hello World" sample application.

fsm-for-multi-per-sbb.stg and multi-fsm-sbb.stg

Using the fsm-for-multi-per-sbb.stg and multi-fsm-sbb.stg templates to generate the state-machine and hosting SBB Java class files:

<fsmtool:make-multi-fsm-sbb
          sbbClassName="FsmToolMultiFsmExampleStateMachineSbb"
               package="com.opencloud.slee.services.fsmtool.multifsmsbb"
               destDir="${basedir}/generated/multifsmsbb/com/opencloud/slee/services/fsmtool/multifsmsbb"
            tracerName="multifsmsbb">

     <fsmtool:fsm specification="${basedir}/src/multifsmsbb/com/opencloud/slee/services/fsmtool/multifsmsbb/MessageFSM.fsm"
                   fsmClassname="MessageFSM"
               fsmFullClassname="com.opencloud.slee.services.fsmtool.multifsmsbb.MessageFSM"/>

     <fsmtool:fsm specification="${basedir}/src/multifsmsbb/com/opencloud/slee/services/fsmtool/multifsmsbb/TimerFSM.fsm"
                   fsmClassname="TimerFSM"
               fsmFullClassname="com.opencloud.slee.services.fsmtool.multifsmsbb.TimerFSM"/>

</fsmtool:make-multi-fsm-sbb>

fsm.stg

Using the fsm.stg template to generate the state-machine SBB Java class file:

<fsmtool:generate-fsm
        fsmSpecificationFilename="${basedir}/src/helloworld/com/opencloud/slee/services/fsmtool/helloworld/FsmToolExampleStateMachineSbb.fsm"
        fsmTemplateFilename="templates/fsm.stg"
        package="com.opencloud.slee.services.fsmtool.helloworld"
        class="FsmToolExampleStateMachineSbb"
        fileType="java"
        outputRootDirectory="${basedir}/generated/helloworld"
        traceName="helloworld"/>

dot.stg

Using the dot.stg template to generate a GraphViz dot-format file from the state-machine specification:

<fsmtool:generate-dot
        fsmSpecificationFilename="${basedir}/src/helloworld/com/opencloud/slee/services/fsmtool/helloworld/FsmToolExampleStateMachineSbb.fsm"
        fsmDotTemplateFilename="templates/dot.stg"
        outputFile="${basedir}/doc/javadoc/helloworld/com/opencloud/slee/services/fsmtool/helloworld/FsmToolExampleStateMachineSbb.dot"/>
Previous page Next page