Java Command Annotations – @JavaCommandService
Java command annotations are used for developing Java commands in PAK.
This chapter describes the functionality of the @JavaCommandService
annotation.
It also gives an example of how you can use this annotation in your implementation.
1. Basics
The @JavaCommandService
annotation can be used for classes that hold methods, which shall be processed into commands.
In order to mark a method as a command, the class holding the corresponding method needs
to be marked with @JavaCommandService
, to be recognized by the annotation processor.
2. Usage
@JavaCommandService
marks all methods inside a class as a command by default, if certain methods are marked with @JavaCommand
, then only
these methods are turned into commands.
This is a very basic explanation on how @JavaCommandService works. For a more detailed explanation on how to process methods,consider checking out the HowTo Creating Commands from Legacy Code. |
2.1. Processing of All Methods within the Class
If all methods within a class need to be processed, then only the class has to be annotated with @JavaCommandService
.
The in-and outputs of these commands are specified by the methods return-type (output) and its parameters (inputs).
@JavaCommandService (1)
public class CommandClass {
[...]
public String myCommand1(String myReadVariable1, String myReadVariable2) {
return myReadVariable1 + myReadVariable2;
}
public int myCommand2(String myReadVariable) {
return myReadVariable.length();
}
}
1 | Usage of @JavaCommandService: @JavaCommandService on class-level, all methods inside the class-scope are turned into a command. |
Listing 1 produces two commands (myCommand1, myCommand2).
2.2. Processing of Certain Methods within the Class
If only a certain selection of methods needs to be processed, it’s required to mark those methods with @JavaCommand
.
@JavaCommandService (1)
public class CommandClass {
[...]
@JavaCommand (2)
@Persistent
public String myCommand(@Persistent String stringVariable) {
return stringVariable + "hello";
}
// simple dummy method, not a command
public int retNum(int number) {
return number;
}
}
1 | Usage of @JavaCommandService: @JavaCommandService on class-level, in contrast to Listing 1 only the methods marked with @JavaCommand are turned into commands. |
2 | Usage of @JavaCommand: Usage of @JavaCommand on method-base, meaning only this method is meant to be a command. |
Listing 2 produces only one command (myCommand).