Mitool

          [//TODO]
          posts - 1, comments - 1, trackbacks - 0, articles - 1

          Dictionary OSGi Service模板Custom端使用

          Posted on 2010-11-14 13:02 Mitool 閱讀(572) 評論(0)  編輯  收藏 所屬分類: OSGi
          Eclispe 插件工程中提供了Dictionary OSGi Service 模板,寫了一下Custom端使用的代碼。

          1. Dictionary OSGi Service 模板
          按照Eclipse向導生成。注意Export相應包。

          2. Custom 端使用
          新建插件工程,Import字典服務Exprot的包。

          代碼片段:
          package demo.dictionary.custom;

          import org.osgi.framework.BundleActivator;
          import org.osgi.framework.BundleContext;
          import org.osgi.framework.ServiceReference;

          import demo.dictionary.DictionaryService;

          public class Activator implements BundleActivator {
              ServiceReference serviceReference 
          = null;

              
          public void start(BundleContext context) throws Exception {
                  serviceReference 
          = context.getServiceReference(DictionaryService.class.getName());
                  
                  
          if(null != serviceReference){
                      DictionaryService dictionaryService 
          = (DictionaryService)context.getService(serviceReference);
                     

                      System.out.println("check word:" + dictionaryService.check("word"));
                      System.out.println(
          "check osgi:" + dictionaryService.check("osgi"));
                      System.out.println(
          "check equinox:" + dictionaryService.check("equinox"));
                      System.out.println(
          "check eclipse:" + dictionaryService.check("eclipse"));
                  }
              }

              
          public void stop(BundleContext context) throws Exception {
                  serviceReference 
          = null;
              }
          }


          3. Custom 端使用
          如果沒輸出顯示,可在console中 update custom 插件。

          結果:


          4.工程文件下載
          demo.dictionary.custom.rar


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


          網站導航:
           
          主站蜘蛛池模板: 黑山县| 石城县| 新巴尔虎左旗| 桑植县| 新化县| 芦溪县| 金山区| 沙坪坝区| 辽阳市| 六安市| 封丘县| 威远县| 贡嘎县| 客服| 桓仁| 若羌县| 汽车| 曲松县| 监利县| 延寿县| 天津市| 丹巴县| 阜阳市| 河北省| 道孚县| 建宁县| 米泉市| 进贤县| 永寿县| 淮安市| 南部县| 柳林县| 光山县| 阿图什市| 大厂| 姜堰市| 昆山市| 德安县| 上蔡县| 新乡市| 茌平县|