JB,
Thank you for the help.  

Below is the resulting Blueprint.xml.  Note: The reference is optional so the 
command will exist even if the service is not running. The command will need to 
check for null when using the service.


        <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.0.0";>
                <command name=“command/doSomething”>
                        <action class=“com.foo.MyCommand”>
                                <property name=“myService” ref=“Service”/>
                        </action>                       
                </command>
        </command-bundle>

        <reference id=“Service” interface=“com.foo.MyService” 
availability="optional"/>

Paul Spencer
On Jan 14, 2014, at 12:04 PM, Jean-Baptiste Onofré <[email protected]> wrote:

> Sorry Paul,
> 
> I missed part of your question.
> 
> The action class is like a bean, so you use property set on it.
> 
> Regards
> JB
> 
> On 01/14/2014 05:54 PM, Paul Spencer wrote:
>> 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;
>>   }
>> 
>> 
>> 
>> 
> 
> -- 
> Jean-Baptiste Onofré
> [email protected]
> http://blog.nanthrax.net
> Talend - http://www.talend.com

Reply via email to