public class ConfigurationTree
extends java.lang.Object
Used for configuration bindings in guice context.
Configuration is introspected using jersey serialization api: this means only values visible for jersey serialization will be presented.
Each configuration property descriptor provides access to root and child paths, so tree-like traversals are possible (see find* methods below for examples).
Object itself could be injected as guice bean @Inject ConfigurationTree config. Note that it did not contains
root configuration instance, only properties tree.
Also, object is accessible inside guicey bundles
GuiceyEnvironment.configurationTree() and guice modules:
ConfigurationTreeAwareModule.
ConfigBindingModule,
GuiceyOptions.BindConfigurationByPath| Constructor and Description |
|---|
ConfigurationTree(java.util.List<java.lang.Class> rootTypes) |
ConfigurationTree(java.util.List<java.lang.Class> rootTypes,
java.util.List<ConfigPath> paths,
java.util.List<ConfigPath> uniqueTypePaths) |
| Modifier and Type | Method and Description |
|---|---|
java.util.List<ConfigPath> |
findAllByType(java.lang.Class<?> type)
Useful for searching multiple custom types.
|
java.util.List<ConfigPath> |
findAllFrom(java.lang.Class<? extends io.dropwizard.Configuration> confType)
Useful for getting all configurations for exact configuration class.
|
java.util.List<ConfigPath> |
findAllRootPaths()
For example, it would always contain logging, metrics and server paths from dropwizard configuration.
|
java.util.List<ConfigPath> |
findAllRootPathsFrom(java.lang.Class<? extends io.dropwizard.Configuration> confType)
The same as
findAllRootPaths(), but returns only paths started in provided configuration. |
ConfigPath |
findByPath(java.lang.String path)
Case insensitive exact match.
|
java.util.List<ConfigPath> |
getPaths()
Note that paths are computed using jackson serialization logic.
|
java.util.List<java.lang.Class> |
getRootTypes() |
java.util.List<ConfigPath> |
getUniqueTypePaths()
Such unique objects could be used for internal configurations instead of root configuration class
(very handy for generic extensions).
|
<T> T |
valueByPath(java.lang.String path)
class Config extends Configuration {
SubConfig sub = { // shown instance contents
String val = "something"
}
}. |
<T,K extends T> |
valueByType(java.lang.Class<T> type)
Behaviour is the same as
valuesByType(Class), but only first element is returned. |
<T,K extends T> |
valueByUniqueDeclaredType(java.lang.Class<T> type)
Search value by unique type declaration.
|
<T> java.util.List<? extends T> |
valuesByType(java.lang.Class<T> type)
Useful to resolve sub configuration objects.
|
public ConfigurationTree(java.util.List<java.lang.Class> rootTypes)
public ConfigurationTree(java.util.List<java.lang.Class> rootTypes,
java.util.List<ConfigPath> paths,
java.util.List<ConfigPath> uniqueTypePaths)
public java.util.List<java.lang.Class> getRootTypes()
Configuration) and custom interfacespublic java.util.List<ConfigPath> getPaths()
Paths are sorted by configuration class and path name (so more custom properties will be at the beginning and dropwizard properties at the end).
public java.util.List<ConfigPath> getUniqueTypePaths()
Note that custom type is unique only if it does not appear anywhere else (on any level). Exact type matching: e.g. if some extending type is declared somewhere it would be considered as different (as class is different, hierarchy not counted).
public ConfigPath findByPath(java.lang.String path)
path - path to find descriptor forpublic java.util.List<ConfigPath> findAllByType(java.lang.Class<?> type)
class Config {
SubConf field1;
// just to show that value type taken into account
Object field2 = new SubConfExt();
}
findAllByType(SubConf.class) == [filed1, field2] because filed1 is declared with required type and
field2 value is compatible with requested type.type - type to search forpublic java.util.List<ConfigPath> findAllFrom(java.lang.Class<? extends io.dropwizard.Configuration> confType)
class MyConf extends Configuration {
String val
SubConf sub
}
findAllFrom(MyConf) == [val, sub, sub.val1, sub.val2] - all property paths, started in
this class (all properties from Configuration are ignored).confType - configuration type to get all properties frompublic java.util.List<ConfigPath> findAllRootPaths()
findAllRootPathsFrom(Class)public java.util.List<ConfigPath> findAllRootPathsFrom(java.lang.Class<? extends io.dropwizard.Configuration> confType)
findAllRootPaths(), but returns only paths started in provided configuration.confType - configuration type to get all properties fromfindAllRootPaths()public <T> T valueByPath(java.lang.String path)
class Config extends Configuration {
SubConfig sub = { // shown instance contents
String val = "something"
}
}.
valueByPath("sub.val") == "something"
Note: keep in mind that not all values could be accessible (read class javadoc)
T - value typepath - yaml path (case insensitive)public <T> java.util.List<? extends T> valuesByType(java.lang.Class<T> type)
class Config extends Configuration {
SubOne sub1 = ...
SubTwo sub2 = ...
SubTwo sub2_1 = ...
SubTwoExt sub2_2 = ... // SubTwoExt extends SubTwo
}
valuesByType(SubOne.class) == [<sub1>]
valuesByType(SubTwo.class) == [<sub2>, <sub2_1>, <sub2_2>]
Note that type matching is not exact: any extending types are also accepted. Type is compared with declaration type (inside configuration class).
T - value typetype - type of required sub configuration objectsfor uniqe objects accesspublic <T,K extends T> K valueByType(java.lang.Class<T> type)
valuesByType(Class), but only first element is returned.
Note: uniqueness not guaranteed!
T - value typeK - actual expected sub type (may be the same)type - type of required sub configuration objectfor guaranteed uniqunesspublic <T,K extends T> K valueByUniqueDeclaredType(java.lang.Class<T> type)
class Config extends Configuration {
SubOne sub1 = ...
SubTwo sub2 = ...
SubTwoExt sub3 = ... // SubTwoExt extends SubTwo
}
valueByUniqueDeclaredType(SubOne.class) == <sub1>,
valueByUniqueDeclaredType(SubTwo.class) == <sub2>
valueByUniqueDeclaredType(SubTwoExt.class) == <sub3>
Note that direct declaration comparison used! For example, valuesByType(SubTwo) == [<sub2>, <sub3>]
would consider sub2 and sub3 as the same type, but valueByUniqueDeclaredType will not!
Type declaration is not unique if somewhere (maybe in some sub-sub configuration object) declaration with
the same type exists. If you need to treat uniqueness only by first path level, then write search
function yourself using findAllRootPaths() or findAllRootPathsFrom(Class).
T - value typeK - actual expected sub type (may be the same)type - required target declaration type