I am migrating from org.apache.felix.scr
annotations to org.osgi.service.component
annotations. I have a set of Components that inherit from a common abstract class. In the felix case, I can use a @Component
annotation with the option componentAbstract=true
on the super class, and then use @Reference
annotation in the super class. I cannot find how to migrate this to osgi annotations.
Is it possible to use Component annotations in a super class of a Component? And if so, what is then the appropriate way to handle the properties and metatype generation?
So, what I am looking for, is something like this
/* No component definition should be generated for the parent, as it is
abstract and cannot be instantiated */
@Component(property="parent.property=parentValue")
public abstract class Parent {
@Reference
protected Service aService;
protected activate(Map<String,Object> props) {
System.out.println("I have my parent property: "+props.get("parent.property"));
@Override
public abstract void doSomething();
}
/* For this class, the proper Component definition should be generated, also
including the information coming from the annotations in the parent */
@Component(property="child.property=childValue")
public class Child extends Parent {
@Activate
public activate(Map<String,Object> props) {
super.activate(props);
System.out.println("I have my child property: "+props.get("child.property"));
}
public void doSomething() {
aService.doSomething();
}
}