powered by ASAP

This chapter explains how to create a class that is suitable for the @Service annotation used by commands.

The @Service annotation can be used to mark a service that should be injected. A Connector is a special kind of service that takes care of communication with external applications.

1. Configure the Annotation Processor

The following shows the configuration of the annotation processor using Gradle.

dependencies {
  annotationProcessor "de.asap.pak.core:pak-serviceprocessor:${pakVersion}" (1)
}

compileJava { (2)
    options.compilerArgs.add("-Aversion=$project.version")
    options.compilerArgs.add("-Agroup=$project.group")
    options.compilerArgs.add("-Aname=$project.name")
    options.compilerArgs.add("-Arequires=de.asap.ExampleConnector:$project.version")
}
1 Add the annotation processor for the desired pak-version.
2 Pass the required options to the annotation processor.

2. Create a Connector

Listing 1. Example Connector Implementation
/**
* Implementation of IExampleConnector
*/
@PakService (1)
public class ExampleConnector implements IPakService { (2)


    public ISampleService getSampleService(){
        return new SampleService();
    }

}
1 The @PakService Annotation marks a Java-Class as Service, which can be used via the Service Interpreter.
2 It is mandatory to implement IPakService otherwise the annotation processor will not be accept the class as an C.

2.1. Hiding Implementation

Alternatively the implementation of the Connector can be hidden using an interface which will be implemented by the specific Connector class.

Listing 2. Example Connector Specification
/**
* IExampleConnector specification
*/
public interface IExampleConnector {

	/**
	 * @return the provided sample service
	 */
	ISampleservice getSampleService();

}

3. Requesting Credentials

Some external applications do require credentials to work properly. A Connector can request credentials by implementing the ICredentialRequester interface.

Listing 3. Example Connector with ICredentialRequester
/**
* Implementation of ExampleConnector with ICredentialRequester
*/
@PakService
public class ExampleConnector implements ICredentialRequester, IPakService { (1)

    @Override
	public void switchUser(final Credentials credentials) {
		// Implementation when needed
	}

	@Override
	public void changeCredentials(final CredentialFilter filter) {
		// Implementation when needed
	}

	@Override
	public void setCredentialsProvider(final ICredentialProvider provider) {
		// Implementation when needed
	}


}
1 ICredentialRequester needs to be implemented to request credentials.

4. Usage in a Command

How to use a Connector in commands can be be found here