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

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

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

    高老莊

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

    osgi 添加自定義命令

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

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

    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方法,可以如下實現(xiàn)該接口:

     

    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()方法可以迭代出所有的命令參數(shù).
        2.注冊服務(wù)
            如果不將該接口注冊為服務(wù),這個hello命令將不產(chǎn)生任何作用.注冊的服務(wù)名稱必須是org.eclipse.osgi.framework.console.CommandProvider.
           當(dāng)系統(tǒng)中存在多個此接口的實現(xiàn)時,可以通過SERVICE_RANKING屬性來決定了命令執(zhí)行的順序,既有最高值的服務(wù)將被優(yōu)先執(zhí)行.這種方式可以重載系統(tǒng)中已經(jīng)存在的同名服務(wù).
         3.執(zhí)行命令
        請仔細(xì)體會輸出結(jié)果


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


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: jizz免费在线观看| 爱情岛亚洲论坛在线观看 | 美女羞羞喷液视频免费| 操美女视频免费网站| 毛片免费在线观看| 中文字幕视频免费| 久久久免费的精品| 久久国产色AV免费看| 免费人成视频在线观看网站| 日韩免费无码视频一区二区三区 | 人人公开免费超级碰碰碰视频| 国产在亚洲线视频观看| 亚洲天堂一区二区三区| 在线观看亚洲视频| 国产曰批免费视频播放免费s| 日韩中文字幕免费| 最近免费中文字幕mv电影| 蜜臀AV免费一区二区三区| 岛国片在线免费观看| 亚洲精品高清国产一线久久| 亚洲成色www久久网站夜月| 337p日本欧洲亚洲大胆色噜噜| 亚洲欧洲专线一区| a级毛片免费高清毛片视频| 777成影片免费观看| 国产hs免费高清在线观看| 亚洲av永久无码制服河南实里| 亚洲国产高清美女在线观看| 四虎影视在线看免费观看| 18禁成人网站免费观看| 亚洲精品成人片在线观看| 99久久99热精品免费观看国产| 亚洲AV中文无码乱人伦| 2019亚洲午夜无码天堂| 亚洲熟妇色自偷自拍另类| 麻豆安全免费网址入口| 国产网站免费观看| 天天综合亚洲色在线精品| 四虎免费在线观看| 亚洲综合色一区二区三区| 麻豆国产精品免费视频|