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

1. Basics

The @PostConstruct annotation marks a method as post-construct operation of a class. This annotation is only relevant for command creation. The post-construct method is executed after all injections and other preparations have been executed. However, it is executed before the @Run method.

The name of the @PostConstruct method must not collide with the getter/setter name of a class variable. For further information please refer to the @Persistent documentation.

2. Usage

Listing 1 shows an example usage of the @PostConstruct annotation. It manipulates the input variable name by adding the postfix “_test” in case the input variable test = true.

Listing 1. Example usage of @PostConstruct
/**
 * @workflowDocu This command gets an element by its id.
 */
@JavaCommand
@CommandGroup("Element")
public class GetElement {

	/**
	 * @workflowDocu The element name
	 */
	@Persistent
	private String name;

	/**
	 * @workflowDocu Is the command a test
	 */
	@Persistent
	private boolean test;

	/**
	 * Convert the element name.
	 */
	@PostConstruct (1)
	public void convertInput() {
		if (test) {
		    this.name += "_test";
		}
	}

	[...]
}
1 Use of the @PostConstruct annotation