Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Fixed
-
iPOJO-1.6.0
-
None
Description
I tried to dynamically update the "filter" value of a "@Requires" annotation.
The problem is that I'm using ConfigAdmin service to create my instances (for persistence need) and ConfigAdmin doesn't support Dictionary class...
The improvement is to have an Array of key/value pairs where keys are the identity of the dependencies and the values are the filter of each dependency. This Array could be transformed into a Dictionary object at the begining of the "configure()" method of the "DependencyHandler" class.
Imagine you have a class with following dependencies:
@Requires(id="myFirstDep")
private A a;
@Requires(id=" mySecondDep ")
private B b;
Build the following property to inject in the instance:
conf.put("requires.filters", new String[]
{"myFirstDep", "(property1=value1)", "mySecondDep", "(property2=value2)"});
And the transformation from the Array to the Dictionary could be:
private Dictionary getRequiresFilters(Object requiresFiltersValue) throws ConfigurationException
{
if (requiresFiltersValue != null && requiresFiltersValue.getClass().isArray())
{
String[] filtersArray = (String[]) requiresFiltersValue;
if (filtersArray.length % 2 != 0)
Dictionary requiresFilters = new Hashtable();
for (int i = 0; i < filtersArray.length; i += 2)
return requiresFilters;
}
return (Dictionary) requiresFiltersValue;
}