Hyperion – Section 2 – No XML and pure annotation driven

Honestly I don’t like XML when developing metadata driven applications, as that would separate the code of a piece of logic into two different files. While this defect can be bridged with the use of design tools, just as what .NET WF and jBPM does, both of them provide visualized workflow definition tool. While my framework will keep it simple, without introducing any graphical tools to assist designing the workflow. Therefore, I choose using annotation instead of XML as the metadata language when designing workflows.

In a state workflow definition, one of the core concept is activity. e.g. in commercialized workflows, we have code activity, “if…else…” activity, while loop activity, invoke web service activity, etc. Some activities hold the business logic, while some others are only used for linking other activities to form a whole procedure, just like the “if…else…” activity. In Hyperion, all these activities are simplified into one type, which is the “code activity”, as I believe everything that can be achieved by predefined activities can also be written in code. So why we still need workflow definition? That’s because we still need to handle state transitions.

The code activity itself is just a method written in the workflow definition class. Transitions between states are defined by tagging Transition or Transitions annotation on the code activity method. There are mainly two types of transitions, static transition and dynamic transition, which will be discussed in details in the following sections.

Below are the basic elements of the workflow at design-time and run-time:

Design-Time Run-Time
Workflow Definition A class that extends WorkflowDefinition base class, tagged with Workflow annotation An instance of the workflow definition class
Workflow State A class that extends WorkflowDefinition base class, tagged with Workflow annotation An instance of the workflow definition class
Workflow Transition A method in the workflow definition class, tagged with Transition or Transitions annotation An instance of WorkflowTransition class that holds the metadata of the transition, including a java.lang.reflect.Method instance which can point back to the transition definition method
Workflow Instance N/A An instance of WorkflowInstance class that holds the workflow context, parameters, etc.

An example of a simple workflow definition is as below:

@Workflow(id = "bfc0c860-e52e-421e-95b6-1fbd5b9d710e", initialState = States.Initialized.class)
public class SimpleWorkflow extends WorkflowDefinition {
    @Transition(fromStates = States.WorkInProgress.class, toStates = States.WorkCompleted.class)
    public void complete(final WorkflowInstance workflowInstance) {
    @Transition(fromStates = States.Initialized.class, toStates = States.WorkInProgress.class)
    public void start(final WorkflowInstance workflowInstance) {

Leave a Reply

Your email address will not be published. Required fields are marked *