麻豆传媒视频在线,国产91精品不卡视频,欧美jizz19性欧美,污视频网站在线观看,91涩漫在线观看,伊人发布在线,九色porny丨首页在线,福利视频一区,久久av网址,久久人人视频

當前位置:首頁 > 網(wǎng)站舊欄目 > 學習園地 > 設計軟件教程 > How to design your own extension-point for Eclipse

How to design your own extension-point for Eclipse
2010-01-14 23:01:01  作者:  來源:
Eclipse allow you to extend its functionalities by implementing its extension-point. We often write a Eclipse plugin which implement some of Eclipse's existing extension-points, e.g. if we want to contribute a popup menu for Eclipse, we need implement org.eclipse.ui.popupMenus extension-point, and follow the org.eclipse.ui.popupMenus's API contract which defined by org.eclipse.ui.popupMenus extension-point schema, then Eclipse will do things as we wish.

So what happened here? Why Eclipse know how to process your popup menu contribution? How to add a pretty new functionality to Eclipse, which can't find or defined by Eclipse's existing extension-point? The answer is: contribute a extension-point for Eclipse by yourself.

Here I will use a example to explain how to define a extension-point by yourself, suppose I want to write a view that will show services status which deploy in a container like tomcat, spring, websphere etc., and customer can add any unknown containers support by implement my new extension-point for this view.

1. The requirements

I want to get service from container, also I need support unknown container type, so a client will be needed, i.e. I can user that client to get what I want to show in my view. So here I will define a client extension-point and this client will follow the interface contract below:

Java代碼 復制代碼
  1. public interface IClient {   
  2.     public void setHost(String host);   
  3.     public void setPort(int port);   
  4.     public void createClient();   
  5.        
  6.     public List<IService> listServices();       
  7. }  


The three methods at beginning will set connection information for client and create a client instance, then listServices() will get service back

2. Define client extension-point
You can use PDE extension-point schema editor do this, here's my client schema:

Java代碼 復制代碼
  1. <?xml version='1.0' encoding='UTF-8'?>   
  2. <!-- Schema file written by PDE -->   
  3. <schema targetNamespace="com.example.services">   
  4. <annotation>   
  5.       <appInfo>   
  6.          <meta.schema plugin="com.example.services" id="clients" name="Clients"/>   
  7.       </appInfo>   
  8.       <documentation>   
  9.          this extension-point will be used to connect different container   
  10.       </documentation>   
  11.    </annotation>   
  12.   
  13.    <element name="extension">   
  14.       <complexType>   
  15.          <sequence minOccurs="1" maxOccurs="unbounded">   
  16.             <element ref="client"/>   
  17.          </sequence>   
  18.          <attribute name="point" type="string" use="required">   
  19.             <annotation>   
  20.                <documentation>   
  21.                      
  22.                </documentation>   
  23.             </annotation>   
  24.          </attribute>   
  25.          <attribute name="id" type="string">   
  26.             <annotation>   
  27.                <documentation>   
  28.                      
  29.                </documentation>   
  30.             </annotation>   
  31.          </attribute>   
  32.          <attribute name="name" type="string">   
  33.             <annotation>   
  34.                <documentation>   
  35.                      
  36.                </documentation>   
  37.                <appInfo>   
  38.                   <meta.attribute translatable="true"/>   
  39.                </appInfo>   
  40.             </annotation>   
  41.          </attribute>   
  42.       </complexType>   
  43.    </element>   
  44.   
  45.    <element name="client">   
  46.       <complexType>   
  47.          <attribute name="id" type="string" use="required">   
  48.             <annotation>   
  49.                <documentation>   
  50.                      
  51.                </documentation>   
  52.             </annotation>   
  53.          </attribute>   
  54.          <attribute name="name" type="string" use="required">   
  55.             <annotation>   
  56.                <documentation>   
  57.                      
  58.                </documentation>   
  59.             </annotation>   
  60.          </attribute>   
  61.          <attribute name="clientType" type="string" use="required">   
  62.             <annotation>   
  63.                <documentation>   
  64.                      
  65.                </documentation>   
  66.             </annotation>   
  67.          </attribute>   
  68.          <attribute name="class" type="string" use="required">   
  69.             <annotation>   
  70.                <documentation>   
  71.                      
  72.                </documentation>   
  73.                <appInfo>   
  74.                   <meta.attribute kind="java" basedOn="com.example.services.client.IClient"/>   
  75.                </appInfo>   
  76.             </annotation>   
  77.          </attribute>   
  78.       </complexType>   
  79.    </element>   
  80.   
  81.    <annotation>   
  82.       <appInfo>   
  83.          <meta.section type="since"/>   
  84.       </appInfo>   
  85.       <documentation>   
  86.          2007/09  
  87.       </documentation>   
  88.    </annotation>   
  89.   
  90.    <annotation>   
  91.       <appInfo>   
  92.          <meta.section type="examples"/>   
  93.       </appInfo>   
  94.       <documentation>   
  95.          <pre>   
  96. <extension   
  97.          point="com.example.services.clients">   
  98.       <client   
  99.             class="com.example.services.TomcatClient"  
  100.             clientType="tomcat"  
  101.             id="com.example.services.TomcatClient"  
  102.             name="Tomcat Client"/>   
  103. </extension>   
  104. </pre>   
  105.       </documentation>   
  106.    </annotation>   
  107.   
  108.    <annotation>   
  109.       <appInfo>   
  110.          <meta.section type="apiInfo"/>   
  111.       </appInfo>   
  112.       <documentation>   
  113.          extension of this extension-point must implement <samp>com.example.services.client.IClient</samp>   
  114.       </documentation>   
  115.    </annotation>   
  116.   
  117.    <annotation>   
  118.       <appInfo>   
  119.          <meta.section type="implementation"/>   
  120.       </appInfo>   
  121.       <documentation>   
  122.          see com.example.services plugin for a implementation example   
  123.       </documentation>   
  124.    </annotation>   
  125.   
  126.    <annotation>   
  127.       <appInfo>   
  128.          <meta.section type="copyright"/>   
  129.       </appInfo>   
  130.       <documentation>   
  131.          alexgreenbar   
  132.       </documentation>   
  133.    </annotation>   
  134.   
  135. </schema>  


3. Extension-point handle classes

When my view need get services status back, I need load all contributed extension, and instance client which know how to get service status back, here's code:

Java代碼 復制代碼
  1. //describe every client contribution   
  2. public class ClientsEntry {   
  3.     private final static String ATTR_TYPE = "clientType";   
  4.     private final static String ATTR_CLAZZ = "class";   
  5.   
  6.     private IConfigurationElement element;   
  7.        
  8.     private String type;   
  9.   
  10.     public ClientsEntry(IConfigurationElement aElement) {   
  11.         element = aElement;   
  12.            
  13.         type = element.getAttribute(ATTR_TYPE);   
  14.     }   
  15.     
  16.     public String getType() {   
  17.         return type;   
  18.     }   
  19.        
  20.     public IClient createClient() throws CoreException {   
  21.         return (IClient)element.createExecutableExtension(ATTR_CLAZZ);   
  22.     }   
  23.   
  24. }  




Java代碼 復制代碼
  1. //ClientsRegistry manage all client contribution, use singleton pattern   
  2. public class ClientsRegistry {   
  3.     private final static Logger LOG = Logger.getLogger(ClientsRegistry.class.getName());   
  4.        
  5.     private final static String EXTENSION_POINT_ID = "com.example.services.clients";   
  6.            
  7.     private final static ClientsRegistry INSTANCE = new ClientsRegistry();   
  8.        
  9.     private List<ClientsEntry> entries = new ArrayList<ClientsEntry>();   
  10.        
  11.     private ClientsRegistry() {   
  12.         //   
  13.     }   
  14.        
  15.     public static ClientsRegistry getInstance() {   
  16.         return INSTANCE;   
  17.     }   
  18.        
  19.     private void load(){   
  20.         entries.clear();   
  21.            
  22.         IExtensionRegistry registry = Platform.getExtensionRegistry();   
  23.         IExtensionPoint point = registry.getExtensionPoint(EXTENSION_POINT_ID);   
  24.         for (IExtension extension : point.getExtensions()){   
  25.             for (IConfigurationElement element : extension.getConfigurationElements()){   
  26.                 entries.add(new ClientsEntry(element));   
  27.             }   
  28.         }   
  29.     }   
  30.        
  31.     public List<ClientsEntry> getEntries() {   
  32.         load();   
  33.         return entries;   
  34.     }   
  35.        
  36.     public IClient getClient(String type) {   
  37.         IClient client = null;   
  38.            
  39.         load();   
  40.         for (ClientsEntry entry : entries) {   
  41.             if (entry.getType().equalsIgnoreCase(type)) {   
  42.                 try {   
  43.                     client = entry.createClient();   
  44.                 } catch (CoreException e) {   
  45.                     LOG.log(Level.FINE, "can't instance client extension: ", e);   
  46.                     client = null;   
  47.                     continue;   
  48.                 }                   
  49.                 break;                   
  50.             }               
  51.         }   
  52.   
  53.         return client;   
  54.     }   
  55.   
  56. }  


4. A example client extension

Java代碼 復制代碼
  1. <extension   
  2.          point="com.example.services.clients">   
  3.       <client   
  4.             class="com.example.services.TomcatClient"  
  5.             clientType="tomcat"  
  6.             id="com.example.services.TomcatClient"  
  7.             name="Tomcat Client"/>   
  8. </extension>  


5. Use client extension

In the view code:
Java代碼 復制代碼
  1. String newClientType = "tomcat"  
  2. IClient client = ClientRegistry.getInstance().getClient(newClientType);   
  3. client.setHost("localhost");   
  4. client.setPort(8080);   
  5. client.createClient();   
  6. List<IService> allServices = client.listServices();  


6. Summary

So write a extension-point is not so hard? It's pretty easy actually! Could you imagine all the powerful functionalities of Eclipse are based on this extension mechanism?

- ClientsEntry, ClientsRegistry can be reused, they are similar with code in Eclipse itself that process extension-point
- the most important thing is design your extension-point API contract and select a suitable opportunity to load your extension, apply lazy loading when possible

安徽新華電腦學校專業(yè)職業(yè)規(guī)劃師為你提供更多幫助【在線咨詢
上一篇:tooltip + F2 下一篇:eclipse小技巧
相關(guān)熱詞搜索:
欧美在线三级电影| 久久免费视频在线观看| 中文字幕一区三区| 久久久精品黄色| 91麻豆国产精品久久| 91视频精品在这里| 国产日韩欧美精品一区| 一区精品在线播放| 午夜久久久久久久久| 婷婷丁香激情综合| 在线观看成人免费视频| 91精品国模一区二区三区| 欧美成人免费网站| 国产亚洲欧美aaaa| 久久久天堂国产精品女人| 欧洲美女7788成人免费视频| 国产精品成人v| 精品国产一区二区三区四区阿崩| 国产欧美在线观看| 蜜桃视频免费网站| 第一页在线观看| wwwww在线观看免费视频| 伊人手机在线| 国产高清亚洲| 日韩理论电影| 国产亚洲毛片| 99久久综合99久久综合网站| 亚洲欧美另类小说| 欧美日韩一区在线观看| 日韩国产激情在线| 午夜精品视频在线| 宅男深夜国产| 日韩精品卡一| 精品一区二区三区免费看| 精品国产aⅴ| 日韩中文字幕不卡| 国产亚洲婷婷免费| 色激情天天射综合网| 精品亚洲夜色av98在线观看 | 亚洲日本在线天堂| 欧美日韩一级视频| 日韩在线观看成人| 国产欧美精品久久久| 在线观看免费黄色| 精品国产一区二区三区性色av| 91精品久久久久久久久久不卡| 国产最新精品精品你懂的| 亚洲色图制服丝袜| 亚洲第一黄色网| 国产精品精品久久久| gogogogo高清视频在线| 国产ts一区| 欧美aaaaaa午夜精品| 成人欧美一区二区三区黑人麻豆| 欧美一区二区三区日韩| 97精品国产97久久久久久免费 | 性色一区二区| 久久综合给合久久狠狠狠97色69| 亚洲成人av一区| 亚洲欧美中文字幕| 国产黄色高清在线| 国产v综合v| 99国产成+人+综合+亚洲欧美| 日本一区二区高清| 日韩国产一区三区| 一级黄色av| 精品三级国产| 麻豆精品视频在线观看| 日韩欧美成人免费视频| 欧美激情亚洲综合一区| 久久日韩视频| 久久国产亚洲精品| 日本一区二区三区久久久久久久久不 | 国产精品成人**免费视频| 好看的日韩av电影| 亚洲欧洲另类国产综合| 亚洲人成网站色ww在线| 色播在线视频| 成人精品毛片| 国产精品亚洲午夜一区二区三区| 色诱视频网站一区| 91精品国产91久久| 在线免费三级电影网站| 国产精品嫩草99av在线| 福利视频第一区| 欧美专区国产专区| 日产精品一区| 久久99精品久久久| 在线不卡一区二区| 日本午夜视频| 另类在线视频| 国产欧美一区二区精品性色| 中文字幕免费精品一区| 免费黄网站在线| 国内精品福利| 色狠狠一区二区| 成人观看高清在线观看免费| 欧美经典影片视频网站| 91免费国产在线| 日韩在线播放av| 激情国产在线| 久久av中文字幕片| 亚洲国产欧美自拍| 黄色在线免费网站| 国产精品视频| 欧美一区二区视频免费观看| 少妇性bbb搡bbb爽爽爽欧美| 欧美电影一区| 日韩欧美国产成人| 色琪琪丁香婷婷综合久久| 国产欧美一区二区精品久久久| 亚洲美女免费视频| 国产精品精品国产| 亚洲人和日本人hd| 五月激情综合色| 欧美成人影院在线播放| 欧美超碰在线| 在线中文字幕一区| 色鬼7777久久| 亚洲影音一区| 精品视频一区在线视频| free性欧美16hd| 国产成人a级片| 美女福利精品视频| 精品国产一区二区三区性色av| 国产精品你懂的在线| 国产精品久久久久久久久| 伊人久久大香线蕉av不卡| 日韩欧美中文在线| 国产大学生校花援交在线播放 | 亚洲国产精品一区二区www在线| 国产精品黄视频| 日韩欧美高清| 欧美亚洲高清一区二区三区不卡| 亚洲成人福利| 老牛国产精品一区的观看方式| 日韩成人久久久| 欧美日韩美女| 亚洲视频免费观看| 国产最顶级的黄色片在线免费观看| 欧美xxx在线观看| 精品国产一区二区三区不卡| www成人免费观看| 久久久久久久久久看片| 国产精品一区二区三区成人| 99久久婷婷国产综合精品电影√| 91精品在线一区二区| 福利网站在线观看| 中国av一区二区三区| 啊灬啊灬啊灬啊灬高潮在线看| 国产欧美午夜| 久久福利网址导航| 国产伦一区二区三区| 日韩欧美在线综合网| 欧美韩国亚洲| 亚洲一区二区三区小说| 黄色影院在线播放| 国产传媒久久文化传媒| 欧美一级淫片播放口| 欧美不卡视频| 少妇高潮久久久久久潘金莲| 粉嫩av一区二区| 91精品国产品国语在线不卡| 成人日韩在线| 色8久久人人97超碰香蕉987| 男人天堂亚洲天堂| 亚洲手机成人高清视频| 成人欧美亚洲| 亚洲国产精品激情在线观看| 麻豆国产在线播放| 26uuu欧美日本| 最近97中文超碰在线| 国产很黄免费观看久久| 成人国内精品久久久久一区| 在线视频亚洲| 97视频免费观看| 99精品免费| 欧美在线影院在线视频| 国产精品久久久亚洲一区| 久久免费视频在线| 在线观看不卡| 91精品国产色综合久久不卡98口| 亚洲视频精品| 欧美亚洲激情在线| 久热精品视频| 国产精品偷伦视频免费观看国产| 国产一区二区三区久久| 庆余年2免费日韩剧观看大牛| 老色鬼久久亚洲一区二区| 国产欧美日韩高清| 国产91色综合久久免费分享| 亚洲s色大片在线观看| 久久欧美中文字幕| 最新国产在线观看| 亚洲另类色综合网站| 爱啪啪综合导航| 欧美人妇做爰xxxⅹ性高电影| 97久久亚洲| 久久精品视频在线| 久久一区精品|