Skip to content
Pierre T. edited this page May 19, 2015 · 1 revision

The request API is one of the most important feature of plugins. It allows to build requests which will be computed by the kernel. The kernel will scan the classpath to find the requested resources.

You can create a classpath scan request in a plugin, using the classpathScanRequestBuilder() method inherited from AbstractPlugin.

Types of request

Type Description

specifiation

Requests classes based on specification. {Kametic Specification} is used as implementation of the specification pattern.

annotationType

Requests classes annotated by a given annotation.

annotationRegex

Requests classes annotated by an annotation matching the regex.

subtypeOf

Request classes which directly extends or implements a given class.

descendentTypeOf

Request all the classes which descend from a given class.

subTypeOfRegex

Request classes which directly extends or implements a class matching the regex.

typeOfRegex

Request classes which have a name matching the regex.

resourcesRegex

Request resources whose path match the regex. For instance, all the files under META-INF/configuration ending with the .props extension.

Register the request

Then register the requests as follows.

@Override
public Collection<ClasspathScanRequest> classpathScanRequests() {
    return classpathScanRequestBuilder()
        .subtypeOf(DiagnosticInfoCollector.class)
        .annotationType(Install.class).build();
}

Gets the results

The results of the requests will be available in the initContext of the init() method.

@Override
public InitState init(InitContext initContext) {
    Map<Class<? extends Annotation>, Collection<Class<?>>> scannedClassesByAnnotationClass =     initContext.scannedClassesByAnnotationClass();
    for (Class<?> candidate : scannedClassesByAnnotationClass.get(Install.class)) {
        ...
    }

    ...

    return InitState.INITIALIZED;
}

Ignore class in the scan

All the class annotated by the nuun @Ignore annotation or any annotation ending with Ignore.

Content

Clone this wiki locally