国产精品一区二区精品_久久小视频_天堂va在线观看_99久久夜色精品国产亚洲96_日本手机在线视频_av成人免费

當(dāng)前位置:首頁 > 網(wǎng)站舊欄目 > 學(xué)習(xí)園地 > 設(shè)計(jì)軟件教程 > 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代碼 復(fù)制代碼
  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代碼 復(fù)制代碼
  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代碼 復(fù)制代碼
  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代碼 復(fù)制代碼
  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代碼 復(fù)制代碼
  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代碼 復(fù)制代碼
  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

安徽新華電腦學(xué)校專業(yè)職業(yè)規(guī)劃師為你提供更多幫助【在線咨詢
上一篇:tooltip + F2 下一篇:eclipse小技巧
相關(guān)熱詞搜索:
国产精品一区二区精品_久久小视频_天堂va在线观看_99久久夜色精品国产亚洲96_日本手机在线视频_av成人免费
<button id="0mgmq"><pre id="0mgmq"></pre></button>
  • <tr id="0mgmq"></tr>
  • <abbr id="0mgmq"><source id="0mgmq"></source></abbr> <button id="0mgmq"></button>
  • 最近看过的日韩成人| 久久亚洲一区| 国产欧美一区二区三区国产幕精品| 最新成人av网站| 亚洲欧美国产不卡| 精品国产电影| 亚洲综合首页| 永久域名在线精品| 久久综合狠狠| 日本一区二区三区四区高清视频| 亚洲国产精品一区在线观看不卡| 亚洲性人人天天夜夜摸| 国产精品免费一区二区三区观看| 999国内精品视频在线| 欧美精品久久| 亚洲精品麻豆| 精品一卡二卡三卡四卡日本乱码 | 久久久久久久久久久久久久一区| 国产一区在线免费| 伊人精品久久久久7777| 国产精品日韩二区| 秋霞毛片久久久久久久久| 国产精品成人观看视频免费| 午夜在线精品| 欧美日韩亚洲一区二区三区四区| 亚洲午夜精品久久久久久app| 99在线视频免费观看| 一区二区视频国产| 久久影院亚洲| 午夜精品一区二区三区四区| 久久一区中文字幕| 一区二区在线中文字幕电影视频| 亚洲中午字幕| 一区高清视频| 国产精品久久精品国产| 午夜激情一区| 国产欧美亚洲日本| 伊人久久大香线蕉av超碰演员| 成人一区二区在线| 狠狠88综合久久久久综合网| 国产伦精品一区二区三区视频孕妇| 欧美成人一区二区在线| 国产伦精品一区二区三区| 国内外成人免费视频| 欧美高清视频一区| 男女精品视频| 国产一区高清视频| 欧美 日韩 国产在线| 在线一区欧美| 欧美激情性爽国产精品17p| 高清国产在线一区| 亚洲高清免费| 在线看无码的免费网站| 韩国成人一区| 久久一区二区三区四区五区| 伊人精品视频| 一区二区不卡在线观看| 国产日产精品一区二区三区四区| 亚洲第一黄网| 亚洲综合五月天| 欧美国产二区| 成人av蜜桃| 噜噜噜久久亚洲精品国产品小说| 欧美午夜视频| 亚洲高清123| 欧美精品v日韩精品v国产精品| 久久综合九色综合欧美狠狠| 中文精品视频| 影音先锋中文字幕一区| 欧美va天堂在线| 日韩中文字幕一区| 精品国产一区二区三| 91手机在线播放| 麻豆九一精品爱看视频在线观看免费| 国内精品久久久久久久影视蜜臀| 亚洲一区二区三区四区中文| 日本一区二区三区视频在线播放| 狂野欧美一区| 久久婷婷麻豆| 美日韩精品视频| 国产精品欧美久久| 亚洲一区不卡| 亚洲综合三区| 国产女优一区| 噜噜噜躁狠狠躁狠狠精品视频| 国产亚洲精品v| 国产精品三上| 蜜桃av久久久亚洲精品| 久久av一区| 亚洲欧美国产精品桃花| 香蕉成人久久| 99久热re在线精品996热视频| 5g国产欧美日韩视频| 91传媒在线免费观看| 爱情岛论坛亚洲入口| 国产精品久久久久久久小唯西川| 成人av男人的天堂| 精品无码久久久久久久动漫| 欧美国产综合视频| 视频一区视频二区视频三区高| 天堂va久久久噜噜噜久久va| 天堂资源在线亚洲视频| 尤物一区二区三区| 亚洲午夜精品一区二区| 国产欧美日韩综合精品二区| 久久久久中文| 国产精品香蕉视屏| 蜜桃传媒视频麻豆一区| 偷拍视频一区二区| 国产在线精品二区| 免费观看成人高| 永久免费精品视频网站| 影音先锋久久资源网| 久久成人免费| 久久久久久久久久久久久9999| 五月天久久综合网| 国内精品久久久久久久果冻传媒 | 精品视频第一区| 亚洲a∨一区二区三区| 在线成人国产| 91精品国产综合久久久久久丝袜 | 欧美午夜一区| 先锋影音久久久| 欧美日韩一区综合| 一区视频在线| 官网99热精品| 女同一区二区| 久久综合婷婷| 亚洲三区在线观看| 亚洲一区日韩在线| 久久99精品久久久久久久青青日本| 视频在线99re| 亚洲视频导航| 欧美精品尤物在线| 日韩视频一区二区三区在线播放免费观看| 亚洲一区二区三区在线观看视频 | 伊人久久亚洲热| 99久久精品免费看国产一区二区三区 | 粉嫩av一区二区三区免费观看| 五月婷婷综合色| 国产精品免费看| 日韩福利影院| 久久成人免费| 一区高清视频| 99在线热播| 国产自产在线视频一区| 高清国产在线一区| 国产精品草草| 久久伊人一区| 国产一区二区三区久久| 清纯唯美一区二区三区| 亚洲一区欧美激情| 一本色道婷婷久久欧美 | 日韩av电影在线观看| 国产欧美日本| 欧美一区亚洲二区| 国产一区二区三区四区五区加勒比| 欧美日韩在线大尺度| 久久99精品国产一区二区三区| 亚洲欧洲日韩综合二区| 欧美日韩亚洲免费| 狂野欧美一区| 国产精品一区视频网站| 日韩午夜激情| 亚洲欧美国产不卡| 国产伦理久久久| 亚洲一区二区三区精品动漫| 午夜精品偷拍| 欧美一卡2卡3卡4卡无卡免费观看水多多 | 一区二区欧美日韩| 天堂一区二区三区| 国产精品一区二| 香蕉精品999视频一区二区| 午夜久久99| 日本成人黄色免费看| 亚洲一区精彩视频| 久久精品日产第一区二区三区乱码| 国产免费成人| 亚洲精品一区二区三区蜜桃久| 亚洲欧美日韩国产yyy| 国产欧美日韩综合一区在线观看| 亚洲综合激情| 在线日韩电影| 国语精品一区| 欧美另类视频在线| 亚洲国产一区二区精品视频| 久久精品国产第一区二区三区最新章节 | 一区二区三区四区五区在线| 欧美 日韩 国产在线| 涩涩涩999| 日本精品国语自产拍在线观看| 国产 高清 精品 在线 a| 噜噜噜噜噜久久久久久91| 亚洲乱亚洲高清| 亚洲国产网站| 在线观看成人一级片| 亚洲性人人天天夜夜摸| 国产综合色产| 伊人色综合久久天天五月婷| 好吊一区二区三区|