@ParametersAreNonnullByDefault public class Extensions extends Object
Using the typesafe config library,
several component.conf (along with application.conf etc.) will be loaded to form the system config
(see: Sirius.setupConfiguration()
). These files will be merged together, so that extensions
like the following wil be put into one extension list reachable as "examples":
File A:
examples {
A = {
key = "string"
otherKey = true
}
}
File B:
examples {
B = {
key = "string"
otherKey = true
}
}
This permits frameworks to provide extension hooks which can be extended by sub modules, without having the framework to "know" those modules. Using a loose coupled approach like this simplifies the task of building modular and extensible systems.
The extensions defined above can be obtained calling Extensions.getExtension("examples")
. Each
of those extensions can be read out calling ext.getValue("key").asString()
or
ext.getValue("otherKey").asBoolean()
Another way of loading extensions is to place an ExtensionList
annotation
on a field like:
@ExtensionList("examples")
private List<Extension> examples;
This will be detected by the ExtensionListAnnotationProcessor
as the
Injector
starts up and filled with the appropriate list.Extension
,
Value
,
Sirius.setupConfiguration()
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT
Name of the default entry for an extension
|
protected static Log |
LOG
The logger used by the extensions framework
|
Modifier and Type | Method and Description |
---|---|
static Extension |
getExtension(String type,
String id)
Returns the Extension for the given id of the given type
|
static Collection<Extension> |
getExtensions(String type)
Returns all extensions available for the given type
The order of the extensions can be defined, setting a property named priority.
|
public static final String DEFAULT
protected static final Log LOG
@Nullable public static Extension getExtension(String type, String id)
type
- the type of the extension to be returnedid
- the unique id of the extension to be returned@Nonnull public static Collection<Extension> getExtensions(String type)
The order of the extensions can be defined, setting a property named priority. If no value is
present PriorityCollector.DEFAULT_PRIORITY
is assumed.
type
- the type of the extensions to be returned.Copyright © 2016. All rights reserved.