Extension model
Overview
Module
- package:
org.eclipse.dirigible.sdk.extensions - source: extensions/
There is no extension annotation in the Java SDK. Extension points and contributions are expressed with the same building blocks as everything else - plain interfaces and @Component beans:
- An extension point is a plain Java interface that defines the contract every contribution must implement. No annotation is required.
- A contribution is a
@Componentthat implements that interface. Its@Componentname (thevalue(), or the decapitalized class name by default) is the contribution name.
Contributions are discovered the same way any group of beans is: inject them all as a collection, or look them up through Extensions.
Example Usage
java
import org.eclipse.dirigible.sdk.component.Component;
import org.eclipse.dirigible.sdk.component.Inject;
import java.util.List;
// 1. The extension point - a plain interface, no annotation
public interface OrderProcessor {
void process(Order order);
}
// 2. A contribution - a @Component implementing the interface;
// its @Component name ("fast-processor") is the contribution name
@Component("fast-processor")
public class FastOrderProcessor implements OrderProcessor {
public void process(Order order) {
// ...
}
}
// 3. Consume every contribution via collection injection (preferred)
@Component
public class OrderPipeline {
private final List<OrderProcessor> processors;
@Inject
public OrderPipeline(List<OrderProcessor> processors) {
this.processors = processors;
}
public void run(Order order) {
processors.forEach(p -> p.process(order));
}
}Discovering contributions
- Collection injection (preferred) - inject
List<OrderProcessor>(orSet<…>/Collection<…>) and the container supplies every@Componentassignable to the interface. See Component / @Inject. - Programmatic lookup - call
Extensions.find(OrderProcessor.class)to get the same list, orExtensions.findFirst(…)for the first one. Equivalent toBeans.getAll(…)for the contract type.
See also
Extensions- typedfind(Class)discovery (and the legacy string-keyedgetExtensions).- Component -
@Component/@Inject, including collection injection.