powered by ASAP

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

1. Basics

The @Named annotation is an extension for the @Service annotation. It defines a specific (named) instance of a service that should be injected. Thus, several services of the same type can be used in one command.

This annotation can only be used in combination with the @Service annotation.

2. Properties

There is a String property value defined for the @Named annotation. It defines the name for the service to be injected.

3. Usage

Listing 1 shows how to use the @Named annotation.

Listing 1. Example usage of the @Named annotation
/**
 * @workflowDocu This command gets an element by its id.
 */
@JavaCommand
@CommandGroup("Element")
public class GetElement {
	/**
	 * The build context service injected for this command
	 */
	@Named("builderContext") (1)
	@Service
	private IContext builderContext;

	/**
	 * The interpreter context service injected for this command
	 */
	@Service
	@Named("interpreterContext") (2)
	private IContext interpreterContext;

	[...]
}
1 Definition of the service with name builderContext
2 Definition of the service with name interpreterContext