Java Command Annotations – @JavaCommand
Java command annotations are used for developing Java commands in PAK.
This chapter describes the functionality of the @JavaCommand
annotation.
It also gives an example of how you can use this annotation in your implementation.
1. Basics
@JavaCommand
provides two ways of command-developing. One is class-based and
the other enables the user to turn methods from already existing code into commands.
2. Properties
There is a String property called displayname
defined for the @JavaCommand
annotation.
Usually, the command name is derived from the class name.
However, if a value is assigned to the displayname
property the PAK BPMN Editor and Workflow Executor display this value as command name instead of the class name.
The usage of that property is shown in Listing 2.
The default value is an empty String which means that the class name is displayed in the PAK BPMN Editor and Workflow Executor.
The class name is split with spaces between capital letters, while sequential uppercase letters are not split.
Therefore, class name GetElementByJSON
, for example, results in the command name „Get Element By JSON“.
3. Usage
@JavaCommand
has to either mark a class or a method as a command.
3.1. @JavaCommand on Class-Level
In the following example in Listing 1, line 4 the @JavaCommand
annotation is used.
This approach is based on a JavaCommand-Code-Template, useful for developing new command projects.
As the default for the displayname
property is an empty String and nothing else is defined for that property, the command name in Listing 1 will be derived by the class name, i.e. „Get Element“.
/**
* @workflowDocu This command gets an element by its id.
*/
@JavaCommand (1)
@CommandGroup("Element")
public class GetElement {
[..]
}
1 | Use of the @JavaCommand annotation with default value of displayname |
In contrast to the example before, Listing 2 sets the displayname
property to „Get Existing Element“.
This customized command name will then be displayed in the BPMN Editor and Workflow Executor.
displayname
/**
* @workflowDocu This command gets an element by its id.
*/
@JavaCommand(displayname = "Get Existing Element") (1)
@CommandGroup("Element")
public class GetElement {
[..]
}
1 | Use of the @JavaCommand annotation with displayname set to „Get Existing Element“ |
3.2. @JavaCommand on Method-Level
When @JavaCommand
is positioned above a method, the annotated method will be converted into a command if the class
containing the method is annotated with @JavaCommandService
.
This is a very basic explanation on how the command-definition on method-level works. For a more detailed explanation on how to process methods, consider checking out the HowTo Create Commands from Legacy Code .
|
@JavaCommandService (1)
public class AnyExistingClass {
[...]
(2)
/**
* This command simply returns the word 'hello'
*
* @return Docu for my write variable
*/
@JavaCommand (3)
@Persistent (4)
public String getHello() {
return "hello";
}
}
1 | The class containing the command needs to be marked with @JavaCommandService . |
2 | The JavaDoc block above the method-body holds the workflow documentation for the command, as well as for the variables within the command. |
3 | @JavaCommand marks the method as a command. |
4 | The @Persistent above the method body marks the returned value as a variable of the command with the scope WRITE. |