Quote:
Originally Posted by AlexandreSH
greeterfactory.xml
<component name="example.greeterfactory"><implementation class="org.example.GreeterFactory"/>
<service><provide interface="org.osgi.service.component.ComponentFactory"/> </service> </component>
The GreeterFactory class is here:
public class GreeterFactory implements ComponentFactory {public ComponentInstance newInstance(Dictionary properties) {// here I take "greeter.class" property from properties and use the ClassLoader.getSystemClassLoader().loadClass(class ID) to load and construct the appropriate class: Greeter g = new ...
g.setName((String)properties.get("greeter.name"));
return null; // the first problem - how do I Construct ComponentInstance? } }
|
In DS, when you declare a factory component (with the factory attribute), you are telling DS to register a ComponentFactory service on your behalf. DS provides the ComponentFactory object. Not you. When someone calls newInstance on the ComponentFactory object, a new instance of the declared implementation class (BaseGreeter) in this case will be declared.
It sounds like you are trying to do cannot be done using inheritance like you are trying. You will need to use a delegation model such that BaseGreeter will inspect its component properties for the desired specific class, construct an instance of that class and delegate the greet method to that instance.