Karaf 2.3.3 Karaf 2.3.3
What is the Blueprint syntax to instantiate and initialize object properties when the command is executed? The XML below will define the command and contains a reference to the interface of the service the command will use. I would like the syntax to instantiate and initialize the property MyService for an MyCommand object when the command is executed by a user. *** * blueprint.xml *** <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.0.0"> <command name=“command/doSomething”> <action class=“com.foo.MyCommand" /> </command> </command-bundle> <reference id=“Service” interface=“com.foo.MyService” /> *** * MyCommand.java *** package com.foo; import org.apache.felix.gogo.commands.Command; import org.apache.karaf.shell.console.OsgiCommandSupport; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @Command(scope = “command”, name = “doSomething”, description = "Example Command") public class MyCommand extends OsgiCommandSupport { private MyService _myService; private static Logger _logger = LoggerFactory.getLogger(MyCommand.class); protected Object doExecute() throws Exception { _logger.info(“Command ‘command:doSomething’ executed and returned “ + _myService.doSomething()); return void; } MyService getMyService() { return _myService; } void setMyService( MyService service) { _myService = service; }