Hassan Syed
Hassan Syed

Reputation: 20485

OSGi Felix Dependency Manager Annotations and abstract classes

In a Dependency Manager based component model i'm trying to tuck away all the boilerplate of my components into Base classes. I have everything wired up in eclipse+bndtools and can successfully push @Init, @Start, @Stop into my base class but when I move my "named" @ServiceReference's up the compile plugin starts throwing errors.

For some further context this is what what my methods look like, as you can see I am using the init and start method dynamically so that I can get rid of as much boilerplate as possible.

@ServiceDependency(name = "commands" )
protected void setCommands(CommandList commands) {
    this.commands = commands;
}

@Init
Map init() {
    return new HashMap() {{
        put("commands.filter", Filter.property(Properties.COMMAND_LIST_ID, getCommandListId()));
        put("commands.required", "true");
    }};
}

@Start
Map start() {
    ...
    return new HashMap() {{
        put(Properties.COMMAND_LIST_LISTVIEW_ID, getCommandListViewId());
    }};
}

this is the stack trace eclipse prints out:

java.lang.Error: DM Annotation plugin failure
    at org.apache.felix.dm.annotation.plugin.bnd.AnnotationPlugin.analyzeJar(AnnotationPlugin.java:130)
    at aQute.bnd.osgi.Analyzer.doPlugins(Analyzer.java:588)
    at aQute.bnd.osgi.Analyzer.analyze(Analyzer.java:171)
    at aQute.bnd.osgi.Builder.analyze(Builder.java:344)
    at aQute.bnd.osgi.Analyzer.calcManifest(Analyzer.java:618)
    at aQute.bnd.osgi.Builder.build(Builder.java:81)
    at aQute.bnd.osgi.Builder.builds(Builder.java:1243)
    at aQute.bnd.build.ProjectBuilder.builds(ProjectBuilder.java:520)
    at aQute.bnd.build.Project.buildLocal(Project.java:1417)
    at org.bndtools.builder.NewBuilder.rebuild(NewBuilder.java:655)
    at org.bndtools.builder.NewBuilder.rebuildIfLocalChanges(NewBuilder.java:545)
    at org.bndtools.builder.NewBuilder.build(NewBuilder.java:199)
    at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:734)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:206)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:246)
    at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:299)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:302)
    at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:358)
    at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:381)
    at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143)
    at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:241)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)

At work we use Eclipse PDE + SCR(XML) and it works quite well with abstract class inheritance. Now that I revisit at the compendium spec it has this to say about the SCR annotations :

The Declarative Services Annotations are not inherited, they can only be used on a given class, anno- tations on its super class hierarchy or interfaces are not taken into account.


Wrapping my own dependency management ontop of programatic dependency-manager might seem appropriate. I will investigate / prototype to see how it works out.

Upvotes: 2

Views: 695

Answers (1)

Mohammad Hassany
Mohammad Hassany

Reputation: 983

i had the same problem,

the problem was that my class didn't annotated with @Component annotation. try add @Component to your current class that contain the codes you have noticed here.

i hope it helps

Upvotes: 1

Related Questions