public interface ConfigurationDependency extends Dependency, ComponentDependencyDeclaration
Also, only managed services are supported, not factories. If you need support for factories, then
you can use
DependencyManagerCompat.createFactoryConfigurationAdapterService(String, String, boolean)
.
There are a couple of things you need to be aware of when implementing the
updated(Dictionary)
method:
ConfigurationException
or any other exception when you
get a configuration that is invalid. In this case, the dependency will not change:
if it was not available, it will still not be. If it was available, it will remain available
and implicitly assume you keep working with your old configuration.The callback invoked when a configuration dependency is updated can supports the following signatures:
Support for a custom Configuration type is a new feature that allows you to specify an interface that is implemented
by DM and such interface is then injected to your callback instead of the actual Dictionary.
Using such configuration interface provides a way for creating type-safe configurations from a actual Dictionary
that is
normally injected by Dependency Manager.
The callback accepts in argument an interface that you have to provide, and DM will inject a proxy that converts
method calls from your configuration-type to lookups in the actual map or dictionary. The results of these lookups are then
converted to the expected return type of the invoked configuration method.
As proxies are injected, no implementations of the desired configuration-type are necessary!
The lookups performed are based on the name of the method called on the configuration type. The method names are "mangled" to the following form: [lower case letter] [any valid character]*. Method names starting with get or is (JavaBean convention) are stripped from these prefixes. For example: given a dictionary with the key "foo" can be accessed from a configuration-type using the following method names: foo(), getFoo() and isFoo().
If the property contains a dot (which is invalid in java method names), then dots (".") can be converted using the following conventions:
The return values supported are: primitive types (or their object wrappers), strings, enums, arrays of
primitives/strings, Collection
types, Map
types, Class
es and interfaces. When an interface is
returned, it is treated equally to a configuration type, that is, it is returned as a proxy.
Arrays can be represented either as comma-separated values, optionally enclosed in square brackets. For example: [ a, b, c ] and a, b,c are both considered an array of length 3 with the values "a", "b" and "c". Alternatively, you can append the array index to the key in the dictionary to obtain the same: a dictionary with "arr.0" => "a", "arr.1" => "b", "arr.2" => "c" would result in the same array as the earlier examples.
Maps can be represented as single string values similarly as arrays, each value consisting of both the key and value separated by a dot. Optionally, the value can be enclosed in curly brackets. Similar to array, you can use the same dot notation using the keys. For example, a dictionary with
"map" => "{key1.value1, key2.value2}"
and a dictionary with
"map.key1" => "value1", "map2.key2" => "value2"
result in the same map being returned.
Instead of a map, you could also define an interface with the methods getKey1() and getKey2 and use
that interface as return type instead of a Map
.
In case a lookup does not yield a value from the underlying map or dictionary, the following rules are applied:
Class
es and enum values yield null
;
STATE_AVAILABLE_OPTIONAL, STATE_AVAILABLE_REQUIRED, STATE_NAMES, STATE_OPTIONAL, STATE_REQUIRED, STATE_UNAVAILABLE_OPTIONAL, STATE_UNAVAILABLE_REQUIRED
Modifier and Type | Method and Description |
---|---|
ConfigurationDependency |
add(PropertyMetaData properties)
Adds a MetaData regarding a given configuration property.
|
ConfigurationDependency |
needsInstance(boolean needsInstance)
Specifies if the component instance should be instantiated when this dependency is started.
|
ConfigurationDependency |
setCallback(java.lang.Object instance,
java.lang.String callback)
Sets the name of the callback method that should be invoked when a configuration
is available.
|
ConfigurationDependency |
setCallback(java.lang.Object instance,
java.lang.String callback,
boolean needsInstance)
Sets the name of the callback method that should be invoked when a configuration
is available.
|
ConfigurationDependency |
setCallback(java.lang.Object instance,
java.lang.String callback,
java.lang.Class<?> configType)
Sets the name of the callback method that should be invoked when a configuration
is available.
|
ConfigurationDependency |
setCallback(java.lang.Object instance,
java.lang.String callback,
java.lang.Class<?> configType,
boolean needsInstance)
Sets the name of the callback method that should be invoked when a configuration
is available.
|
ConfigurationDependency |
setCallback(java.lang.String callback)
Sets the name of the callback method that should be invoked when a configuration
is available.
|
ConfigurationDependency |
setCallback(java.lang.String callback,
java.lang.Class<?> configType)
Sets the name of the callback method that should be invoked when a configuration
is available.
|
ConfigurationDependency |
setConfigType(java.lang.Class<?>... configType)
Sets the configuration property type(s) that are passed to the updated callback parameters
|
ConfigurationDependency |
setDescription(java.lang.String description)
A human readable description of the PID this configuration is associated
with.
|
ConfigurationDependency |
setHeading(java.lang.String heading)
The label used to display the tab name (or section) where the properties
are displayed.
|
ConfigurationDependency |
setLocalization(java.lang.String path)
Points to the basename of the Properties file that can localize the Meta
Type informations.
|
ConfigurationDependency |
setPid(java.lang.String pid)
Sets the
service.pid of the configuration you are depending on. |
ConfigurationDependency |
setPropagate(boolean propagate)
Sets propagation of the configuration properties to the service
properties.
|
ConfigurationDependency |
setPropagate(boolean propagate,
boolean overrideServiceProperties)
Sets propagation of the configuration properties to the service
properties.
|
ConfigurationDependency |
setRequired(boolean required)
Sets the required flag which determines if this configuration dependency is required or not.
|
getAutoConfigName, getProperties, isAutoConfig, isAvailable, isPropagated, isRequired, overrideServiceProperties
getFilter, getName, getSimpleName, getState, getType
ConfigurationDependency setCallback(java.lang.String callback)
ManagedService.updated(Dictionary) throws ConfigurationException
.
By default, if this method is not called, the callback name is "updated".
The callback is invoked on the instantiated component.
callback
- the name of the callback methodConfigurationDependency setCallback(java.lang.Object instance, java.lang.String callback)
ManagedService.updated(Dictionary) throws ConfigurationException
.
the callback is invoked on the callback instance, and the component is not yet instantiated at the time the callback is invoked.
instance
- the object to invoke the callback oncallback
- the name of the callback methodConfigurationDependency setCallback(java.lang.Object instance, java.lang.String callback, boolean needsInstance)
ManagedService.updated(Dictionary) throws ConfigurationException
.
the callback is invoked on the callback instance, and if needsInstance
is true,
the component is instantiated at the time the callback is invoked
instance
- the object to invoke the callback on.callback
- the name of the callback methodneedsInstance
- true if the component must be instantiated before the callback is invoked on the callback instance.ConfigurationDependency setCallback(java.lang.String callback, java.lang.Class<?> configType)
ManagedService.updated(Dictionary) throws ConfigurationException
with the difference that
instead of a Dictionary it accepts an interface of the given configuration type.The callback is invoked on the instantiated component.
callback
- the name of the callback methodconfigType
- the configuration type that the callback method accepts.ConfigurationDependency setCallback(java.lang.Object instance, java.lang.String callback, java.lang.Class<?> configType)
ManagedService.updated(Dictionary) throws ConfigurationException
with the difference that
instead of a Dictionary it accepts an interface of the given configuration type.The callback is invoked on the callback instance, and at this point the component is not yet instantiated.
instance
- the object to invoke the callback on.callback
- the name of the callback methodconfigType
- the configuration type that the callback method accepts.ConfigurationDependency setCallback(java.lang.Object instance, java.lang.String callback, java.lang.Class<?> configType, boolean needsInstance)
ManagedService.updated(Dictionary) throws ConfigurationException
with the difference that
instead of a Dictionary it accepts an interface of the given configuration type. the callback is invoked on the callback instance, and if needsInstance
is true,
the component is instantiated at the time the callback is invoked
instance
- the object to invoke the callback on.callback
- the name of the callback methodconfigType
- the configuration type that the callback method accepts.needsInstance
- true if the component must be instantiated before the callback is invoked on the callback instance.ConfigurationDependency setPid(java.lang.String pid)
service.pid
of the configuration you are depending on.ConfigurationDependency setPropagate(boolean propagate)
setPropagate(true, false)
method.propagate
- true if configuration properties should be propagated to the component service properties. Configuration
starting with a dot won't be propagated (because such property is considered as private, see Configuration Admin spec).setPropagate(boolean, boolean)
ConfigurationDependency setPropagate(boolean propagate, boolean overrideServiceProperties)
propagate
- true if the configuration properties must be propagated to the component service properties. Configuration
starting with a dot won't be propagated (because such property is considered as private, see Configuration Admin spec).overrideServiceProperties
- true if propagated configuration properties should override the component service properties
having the same property nameConfigurationDependency setHeading(java.lang.String heading)
ConfigurationDependency setDescription(java.lang.String description)
ConfigurationDependency setLocalization(java.lang.String path)
setLocalization("person")
will match person_du_NL.properties
in the root bundle directory.ConfigurationDependency add(PropertyMetaData properties)
ConfigurationDependency setRequired(boolean required)
required
- the required flagConfigurationDependency needsInstance(boolean needsInstance)
false
ConfigurationDependency setConfigType(java.lang.Class<?>... configType)
configType
- the configuration type(s) that the callback method accepts.