On 18.06.2010, at 18:24, Loic Petit wrote:

> Hi,
> 
> It works like a charm by using a Dictionary (instead of a Map). Sorry for
> that, I should have seen this :)


Oups, sorry, it's a Dictionary, not a Map :-)

Regards,

clement

> Thanks a lot !
> 
> Regards
> 
> LP
> 
> 
> On Fri, Jun 18, 2010 at 5:57 PM, Clement Escoffier <
> clement.escoff...@gmail.com> wrote:
> 
>> Hi,
>> 
>> On 18.06.2010, at 17:02, Loic Petit wrote:
>> 
>>> Hi everyone,
>>> 
>>> I want to know if there is a "clean" way to do this thing.
>>> 
>>> I've got a class with the following form:
>>> 
>>> @Component
>>> @Provides
>>> class A {
>>>   @Requires
>>>   private B[] b;
>>> }
>>> 
>>> This component is then created by the iPojo API via its factory.
>>> What I would like to do: give a ldap filter on the creation of the
>> instance
>>> in order to have the array that matches the filter.
>>> 
>>> It is possible to do that offline by giving a filter in the annotation,
>> but
>>> it is impossible to have a dynamic one.
>>> 
>>> As an example, I use felix/ipojo to manipulate UPnPDevice. I have a
>> generic
>>> component that operate on all the devices that matches the ID given by
>> the
>>> property. Here is how I could do it.
>>> 
>>> class A {
>>>   @Requires
>>>   private UPnPDevice[] devices;
>>>   @Property
>>>   private String udn;
>>> 
>>>   public void foo() {
>>>        for all devices that matches the udn {
>>>             bar();
>>>        }
>>>   }
>>> }
>>> 
>>> But this is a bit silly as I subscribe for all kinds of devices and then
>> I
>>> do manually the filter while it is possible to subscribe to the context
>> that
>>> I want only that filter. The second way, of course, is to ignore iPojo
>> and
>>> subscribe on my own with a custom filter and also manage the list.
>>> 
>>> It's not the first time I encounter this problem and iPojo has all the
>> tools
>>> to do such thing. Do you know a "clean" way to do it ?
>> 
>> Each instance declaration can customize the dependency filters.
>> Let's imagine a component:
>> @Component
>> @Provides
>> class A {
>>  @Requires(id="B") // I give a name to this dependency
>>  private B[] b;
>> }
>> 
>> Then, in the instance declaration, you can set / override the dependency
>> filter:
>> <instance component="...A">
>>   <property name="requires.filters">  <!-- special property to customize
>> the filters -->
>>       <property name="B" value="(your_filter)"/>  <!-- the filter here -->
>>   </property>
>> </instance>
>> 
>> (More details on
>> http://felix.apache.org/site/service-requirement-handler.html#ServiceRequirementHandler-FilteredRequirement
>> )
>> 
>> Unfortunately, this mechanism is only possible if you declare the instance
>> using the XML formalism or the iPOJO Factory service (API). Indeed, the
>> config admin does not support maps (requires.filters is a map).
>> 
>> Regards,
>> 
>> Clement
>> 
>> 
>>> 
>>> LP
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscr...@felix.apache.org
>> For additional commands, e-mail: users-h...@felix.apache.org
>> 
>> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@felix.apache.org
For additional commands, e-mail: users-h...@felix.apache.org

Reply via email to