The PAK-Core harbors the core functionality of the PAK-framework. It enables the creation, fetching and execution of Commands. Every component within the core-module, plays a vital part in PAK. This chapter describes the functionality of the ICommandServiceProvider interface.

1. Basics

ICommandServiceProvider is extending the ICommandService interface, which makes it a CommandService. This Service can therefore be injected by using the @CommandService annotation and works only in Java Commands. It’s an interface for fetching CommandServices.

2. Usage

There are two methods within the ICommandServiceProvider interface:

  • getCommandRestService(), returns an instance of ICommandRestService, if it is available within the Context. If not, null is returned.

  • find(Class<T extends ICommandService> clazz), finds other custom registered Services, extending ICommandService within the Context. Returns null, if the Service does not exist.

3. Register

Don’t forget to register the implementing class of ICommandServiceProvider to the PAK-framework. This: Guide will show you how.

Listing 1 shows how to inject and use ICommandRestService

Listing 1. Example Java Command, injecting and using @ICommandRestService
/**
* @workflowDocu Sample-command, using ICommandRestService
*/
@JavaCommand
@CommandGroup("CommandService")
public class ServiceProviderCommand {

	@CommandService (1)
	ICommandServiceProvider commandServiceProvider;

	/**
	 * @workflowDocu Store response in this map
	 */
	@Persistent(scope = FieldScope.WRITE_ONLY)
	Map<String, Object> resultMap;

	@Run
	public void run() {

		final IEndpointClientService endpointClientService = this.commandServiceProvider.getCommandRestService()
				.createEndpointClientServiceFor("myRequesterId"); (2)
		[...]
}
}
1 Use of @CommandService, to inject ICommandServiceProvider.
2 Build an instance of IEndpointClientService, by getting an instance of ICommandRestService from ICommandServiceProvider, using the method getCommandRestService().