<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    高老莊

    八戒的夢想:農婦,山泉,有點田
    posts - 4, comments - 14, trackbacks - 0, articles - 3
      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

    osgi 添加自定義命令

    Posted on 2010-01-22 17:34 高老莊 閱讀(605) 評論(0)  編輯  收藏 所屬分類: osgi

        在使用osgi實現時,可以使用諸如install,start,stop這樣的命令來管理bundle或者調用服務.有時我們可能想添加一些自定義命令.可以通過如下的步驟來實現
        1.編寫一個服務,實現如下的接口

    1public interface CommandProvider {
    2    /**
    3     Answer a string (may be as many lines as you like) with help
    4     texts that explain the command.
    5     */

    6    public String getHelp();
    7
    8}


    如果想定義hello方法,可以如下實現該接口:

     

    import java.util.Dictionary;
    import java.util.Properties;

    import org.eclipse.osgi.framework.console.CommandInterpreter;
    import org.eclipse.osgi.framework.console.CommandProvider;
    import org.osgi.framework.BundleActivator;
    import org.osgi.framework.BundleContext;
    import org.osgi.framework.Constants;
    public class Activator implements BundleActivator,CommandProvider  {
        BundleContext bundleContext
    =null;
        
    public void start(BundleContext context) throws Exception {
            System.out.println(
    "start" +context.getBundle().getLocation());
            bundleContext
    =context;
            context.registerService(CommandProvider.
    class.getName(), new AntherCommandProvider(), null);
            Dictionary dictionary
    =new Properties();
            dictionary.put(Constants.SERVICE_RANKING, 
    10);
            context.registerService(CommandProvider.
    class.getName(), this,dictionary);
            
        }


        
    public void stop(BundleContext context) throws Exception {
            System.out.println(
    "end" +context.getBundle().getLocation());
        }


        
    public String getHelp() {
            
    return "you are using the help command";
        }

        
        
    public void _helloa(CommandInterpreter intp)
        
    {
            intp.println(
    "helloa "+ this.getClass().getName());
        }

        
        
    public void _hello(CommandInterpreter intp) throws Exception {
            intp.println(
    "hello " + this.getClass().getName());
        }

    }


     

    import org.eclipse.osgi.framework.console.CommandInterpreter;
    import org.eclipse.osgi.framework.console.CommandProvider;

    public class AntherCommandProvider implements CommandProvider {

        
    public void _hello(CommandInterpreter intp)
        
    {
            intp.println(
    "hello "+ this.getClass().getName());
        }

        
    public String getHelp() {
            
    return null;
        }

    }


    其中,通過CommandInterpreter類型的nextArgument()方法可以迭代出所有的命令參數.
        2.注冊服務
            如果不將該接口注冊為服務,這個hello命令將不產生任何作用.注冊的服務名稱必須是org.eclipse.osgi.framework.console.CommandProvider.
           當系統中存在多個此接口的實現時,可以通過SERVICE_RANKING屬性來決定了命令執行的順序,既有最高值的服務將被優先執行.這種方式可以重載系統中已經存在的同名服務.
         3.執行命令
        請仔細體會輸出結果


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 狠狠综合久久综合88亚洲| 波多野结衣视频在线免费观看| 亚洲人成网7777777国产| 一级A毛片免费观看久久精品| 亚洲?V无码成人精品区日韩 | 免费午夜爽爽爽WWW视频十八禁| 在线aⅴ亚洲中文字幕| 69成人免费视频无码专区| 亚洲国产欧美日韩精品一区二区三区| 成年女人18级毛片毛片免费| 亚洲精品乱码久久久久久蜜桃图片| 精品免费国产一区二区| 国产亚洲福利一区二区免费看| 亚洲乱码国产一区网址| 99久久婷婷免费国产综合精品| 亚洲国产精品无码久久久不卡| 日本免费一区二区三区| 亚洲精品白色在线发布| 一个人在线观看视频免费| 亚洲欧美成人av在线观看| 免费人成年激情视频在线观看| 三级毛片在线免费观看| 自怕偷自怕亚洲精品| 成人爽A毛片免费看| 深夜福利在线视频免费| 亚洲成AV人片天堂网无码| 最近高清中文字幕免费| 亚洲性无码AV中文字幕| 亚洲黄片手机免费观看| 99re6在线视频精品免费下载| 亚洲精品午夜国产va久久| 亚洲美女高清一区二区三区| 无码成A毛片免费| 亚洲色成人网站WWW永久四虎| 久久亚洲国产精品123区| 18观看免费永久视频| 青青久久精品国产免费看| 亚洲第一成年男人的天堂| 日韩激情淫片免费看| 久久午夜夜伦鲁鲁片无码免费| 亚洲精品欧美综合四区|