powered by ASAP

Java command annotations are used for the developing Java commands in PAK. This chapter describes the functionality of the @Pattern annotation. It also gives an example of how you can use this annotation in your implementation.

1. Basics

The @Pattern annotation restricts the allowed values of a variable to those that match the specified regex pattern. This annotation is evaluated at runtime and raises an exception at the latest.

This annotation is only applicable for variables that are annotated with @Persistent and of type String.

2. Properties

There are two properties defined for the @Pattern annotation that will be explained in the following.

  • value: The regex has to be assigned to this property. It defines which variable values are allowed to be set.

  • example: This property is used for the user documentation. You can define examples to show the user which values will be accepted by the regex.

3. Usage

Listing 1 shows how to use the @Pattern annotation with different regex values and the example property usage.

Listing 1. Usage of the @Pattern annotation
/**
 * @workflowDocu This command shows how to use the @Persistent annotation.
 */
@JavaCommand
@CommandGroup("Element")
public class GetElement {

	/**
	 * @workflowDocu List of labels to be added, separated by ","
	 */
	@Pattern(value = "\\w+(,\\w+)*", example = "elem1,elem2") (1)
	@Persistent
	private String commaSep;

	/**
	 * @workflowDocu Only allow numbers
	 */
	@Persistent
	@Pattern("\\d+") (2)
	private String numbers;

	[...]
}
1 Allow comma-separated Strings for variable commaSep
2 Only numbers are allowed for the values of variable number

Figure 1 shows the result of the @Pattern usage of Listing 1. As you can see, the regex as well as the example are provided in the documentation information popup.

GetElement Pattern UserInfo
Figure 1. Result in the Single Command Runner of the Workflow Executor

The frame of the variable remains red as long as no valid value is entered into the text variable, as can be seen in Figure 2. After the entered value matches the regex the red border disappears like in Figure 3.

GetElement Pattern Wrong
Figure 2. Wrong value
GetElement Pattern Correct
Figure 3. Correct value