Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » Filter ComponentFactories by properties(Filtering component factories by its properties does not seem to work)
Filter ComponentFactories by properties [message #671550] Wed, 18 May 2011 09:38 Go to next message
Florian Pirchner is currently offline Florian PirchnerFriend
Messages: 94
Registered: July 2009
Member

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="(&amp;(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="(&amp;(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 Go to previous messageGo to next message
Florian Pirchner is currently offline Florian PirchnerFriend
Messages: 94
Registered: July 2009
Member

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 Go to previous messageGo to next message
Florian Pirchner is currently offline Florian PirchnerFriend
Messages: 94
Registered: July 2009
Member

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 #671693 is a reply to message #671665] Wed, 18 May 2011 17:30 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

You have a solution? Or you mean you have found out why?

If you can define the properties as part of the SCR, doesn't it make sense that they can be used to filter (just like regular service properties). If you think so, you can open a bug at https://bugs.eclipse.org/bugs/enter_bug.cgi?product=Equinox&component=Framework and request it (if you go that route, please post the bug back here).

PW


Re: Filter ComponentFactories by properties [message #671720 is a reply to message #671665] Wed, 18 May 2011 19:21 Go to previous messageGo to next message
BJ Hargrave is currently offline BJ HargraveFriend
Messages: 60
Registered: July 2009
Member
Or you could read the DS spec. From 112.2.4 Factory Component:

SCR must register a Component Factory service on behalf of the component as soon as the component factory is satisfied. The service properties must be:

* component.name The name of the component.
* component.factory The factory identifier.

The service properties of the Component Factory service must not include the component properties.
Re: Filter ComponentFactories by properties [message #671831 is a reply to message #671720] Thu, 19 May 2011 06:29 Go to previous messageGo to next message
Florian Pirchner is currently offline Florian PirchnerFriend
Messages: 94
Registered: July 2009
Member

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
Re: Filter ComponentFactories by properties [message #671957 is a reply to message #671831] Thu, 19 May 2011 13:00 Go to previous messageGo to next message
BJ Hargrave is currently offline BJ HargraveFriend
Messages: 60
Registered: July 2009
Member
Because the properties of a factory component instance are not known until you call the factory to create the instance. The factory is the factory. It is not the component. The properties are for the component. Once you create a component instance with the factory, the component may be registered as a service with the component's properties. It would be confusing if the component instance and the factory have the same (or similar) properties.
Re: Filter ComponentFactories by properties [message #672159 is a reply to message #671957] Fri, 20 May 2011 06:11 Go to previous messageGo to next message
Florian Pirchner is currently offline Florian PirchnerFriend
Messages: 94
Registered: July 2009
Member

Thanks for the informations!

Florian
Re: Filter ComponentFactories by properties [message #674313 is a reply to message #671550] Thu, 26 May 2011 13:40 Go to previous message
Florian Pirchner is currently offline Florian PirchnerFriend
Messages: 94
Registered: July 2009
Member

Hi,

I have been writing a blog post about this subject.

http://floriansblog.wordpress.com/2011/05/26/something-you-cant-do-with-componentfactories/

Kind regards,
Florian
Previous Topic:Equinox implemented OSGi specification version ?
Next Topic:Subversive command line install
Goto Forum:
  


Current Time: Tue Apr 23 14:35:40 GMT 2024

Powered by FUDForum. Page generated in 0.04236 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top