Filter ComponentFactories by properties [message #671550] |
Wed, 18 May 2011 09:38 |
|
Hi,
actually i am trying to filter component factory definitions by their specific properties. But it seems that the only properties which can be used to filter provided component factories are component.name and component.factory.
That is my factory component definition:
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0"
factory="org.redvaadin.addon.apparea.eos.services.factory.component.IPartWrapper"
name="org.redvaadin.addon.apparea.eos.services.impl.wrapper.factory.framework">
<implementation class="org.redvaadin.addon.apparea.eos.services.impl.wrapper.framework.FrameworkPartWrapper"/>
<service>
<provide interface="org.osgi.service.component.ComponentFactory"/>
</service>
<property name="org.redvaadin.addon.apparea.eos.parttype"
type="String"
value="org.redvaadin.addon.apparea.eos.parttype.IFrameworkAreaPart"/>
</scr:component>
A different bundle references this ComponentFactory service:
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0"
factory="org.redvaadin.addon.apparea.core.services.IAppAreaBuilder"
name="org.redvaadin.addon.apparea.eos.services.impl.builder">
<implementation class="org.redvaadin.addon.apparea.eos.services.impl.builder.AppareaBuilder"/>
<service>
<provide interface="org.osgi.service.component.ComponentFactory"/>
</service>
<reference bind="bindPartWrapperComponentFactory"
cardinality="0..1"
interface="org.osgi.service.component.ComponentFactory" name="frameworkWrapperComponentFactory"
policy="dynamic"
target="(&(component.factory=org.redvaadin.addon.apparea.eos.services.factory.component.IPartWrapper)
(org.redvaadin.addon.apparea.eos.parttype=org.redvaadin.addon.apparea.eos.parttype.IFrameworkAreaPart))"
unbind="unbindPartWrapperComponentFactory"/>
</scr:component>
The filter arguments seem to match:
// from provided service
factory="org.redvaadin.addon.apparea.eos.services.factory.component.IPartWrapper"
<property name="org.redvaadin.addon.apparea.eos.parttype"
type="String"
value="org.redvaadin.addon.apparea.eos.parttype.IFrameworkAreaPart"/>
// from referenced definition
target="(&(component.factory=org.redvaadin.addon.apparea.eos.services.factory.component.IPartWrapper)
(org.redvaadin.addon.apparea.eos.parttype=org.redvaadin.addon.apparea.eos.parttype.IFrameworkAreaPart))"
But the factory will be never bound to the specified target.
So i tried the "services" command from the OSGi console. But no results had been returned by the filter defined above as the target of the referenced service.
osgi> services (&(component.factory=org.redvaadin.addon.apparea.eos.services.factory.component.IPartWrapper)
(org.redvaadin.addon.apparea.eos.parttype=org.redvaadin.addon.apparea.eos.parttype.IFrameworkAreaPart))
No registered services.
So i tried the remove the component.factory filter.
osgi> services (org.redvaadin.addon.apparea.eos.parttype=org.redvaadin.addon.apparea.eos.parttype.IFrameworkAreaPart)
No registered services.
But if i am using the component.factory filter for its own, everything works pretty fine.
osgi> services (component.factory=org.redvaadin.addon.apparea.eos.services.factory.component.IPartWrapper)
// comment by Florian
---> 8 registered factories found with different org.redvaadin.addon.apparea.eos.parttype properties.
In the next step i have removed the component.factory entry from the component definition xml. So the component was not a component factory anymore.
Then i used the filter for my parttype property again:
osgi> services (org.redvaadin.addon.apparea.eos.parttype=org.redvaadin.addon.apparea.eos.parttype.IFrameworkAreaPart)
// comment by Florian
---> 8 registered factories found with different org.redvaadin.addon.apparea.eos.parttype properties.
Amazing, all services could be found.
So i suppose, that ComponentFactory services can not be filtered by its properties.
Can anybody confirm my assumption? Or did i understand something really wrong?
Many thanks in advance for your kind help,
Florian Pirchner
|
|
|
Re: Filter ComponentFactories by properties [message #671557 is a reply to message #671550] |
Wed, 18 May 2011 10:02 |
|
I have been debugging this issue and recognized, that the property
org.redvaadin.addon.apparea.eos.parttype=org.redvaadin.addon.apparea.eos.parttype.IFrameworkAreaPart
is not contained in the available filterproperties of the ServiceReference.
Thats all available properties. So i seem my assumption is likely be possible.
{component.factory=org.redvaadin.addon.apparea.eos.services.factory.component.IPartWrapper, component.name=org.redvaadin.addon.apparea.eos.services.impl.wrapper.factory.actionbar, service.id=57}
|
|
|
Re: Filter ComponentFactories by properties [message #671665 is a reply to message #671557] |
Wed, 18 May 2011 16:05 |
|
Think i have solved the issue:
org.eclipse.equinox.internal.ds.InstanceProcess
/**
* Register the Component Factory
*
* @param scp
*/
private void registerComponentFactory(ServiceComponentProp scp) {
if (factoryRegistrations.get(scp) != null) {
//the service factory is already registered
return;
}
ComponentFactory factory = new ComponentFactoryImpl(scp);
ServiceComponent sc = scp.serviceComponent;
BundleContext bc = scp.bc;
// if the factory attribute is set on the component element then
// register a
// component factory service
// for the Service Component on behalf of the Service Component.
Hashtable properties = new Hashtable(2);
properties.put(ComponentConstants.COMPONENT_NAME, sc.name);
properties.put(ComponentConstants.COMPONENT_FACTORY, sc.factory);
ServiceRegistration reg = bc.registerService(ComponentFactory.class.getName(), factory, properties);
factoryRegistrations.put(scp, reg);
}
Only ComponentConstans name and factory are passed to the properties of the factory.
|
|
|
|
|
Re: Filter ComponentFactories by properties [message #671831 is a reply to message #671720] |
Thu, 19 May 2011 06:29 |
|
Thanks a lot for your help. I think i missunderstood the way Component Factories are working.
But it would be a really nice feature that the ComponentFactory service could be filtered by the properties defined by the factory definition. The same way like "normal" services can be filtered.
Why does DS spec. prevent it?
Thanks,
Florian
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04568 seconds