亚洲人成网站在线播放2019 _日韩国产欧美精品_久久夜色精品国产欧美乱_在线视频福利一区

當前位置:首頁 > 網站舊欄目 > 學習園地 > 設計軟件教程 > 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

安徽新華電腦學校專業職業規劃師為你提供更多幫助【在線咨詢
上一篇:tooltip + F2 下一篇:eclipse小技巧
相關熱詞搜索:
亚洲人成网站在线播放2019 _日韩国产欧美精品_久久夜色精品国产欧美乱_在线视频福利一区
高清在线观看免费| 久久久久久美女| 日韩一二区视频| 午夜精品久久久久久99热软件| 一区二区视频在线观看| 色综合久久久888| 中文字幕免费在线不卡| 亚洲三区在线观看| 色之综合天天综合色天天棕色| 五月天在线免费视频| 这里只有精品66| 亚洲三区在线| 日本精品久久久久影院| 欧洲日韩成人av| 狠狠色伊人亚洲综合网站色| 国内精品视频久久| 国产日韩av网站| 91精品国产综合久久男男| 国产精品∨欧美精品v日韩精品| 久久综合狠狠综合久久综青草| 久久综合精品一区| 日韩视频在线观看免费| 国产精品伦子伦免费视频| 久久99久久久久久久噜噜| 亚洲三区在线| 日本不卡免费新一二三区| 欧美日韩国产不卡在线看| 国产综合福利在线| www婷婷av久久久影片| 久久久久久a亚洲欧洲aⅴ| 日韩中文字幕在线免费观看| 国产精品久久久久久免费观看| 欧美激情视频在线观看| 日韩在线第三页| 狠狠色综合网站久久久久久久| www污在线观看| 日韩在线高清视频| 在线观看国产一区| 欧美亚洲视频一区| 粉嫩av四季av绯色av第一区| 国产av人人夜夜澡人人爽麻豆| 国产精品日韩一区二区免费视频| 色综合久久久久久中文网| 日本免费高清一区| 国产区精品在线观看| 久久露脸国产精品| 精品中文字幕在线观看| 免费97视频在线精品国自产拍| 久久精品视频在线观看| 国产精品二区在线| 亚洲在线www| 欧美在线日韩在线| 粉嫩高清一区二区三区精品视频| 日韩在线观看网址| 宅男噜噜99国产精品观看免费| 日产日韩在线亚洲欧美| 国产日本欧美一区| 国产成人啪精品视频免费网| 亚洲在线免费观看| 麻豆av免费在线| 久久精品无码中文字幕| 欧美日韩aaaa| 欧美不卡1区2区3区| 国产成人在线一区二区| 亚洲直播在线一区| 国产性生活免费视频| 国产成人午夜视频网址| 日日夜夜精品网站| www.九色.com| 欧美激情视频网址| 欧美h视频在线| 久久久久久久国产精品| 少妇特黄a一区二区三区| 国产精品揄拍500视频| 国产精品免费成人| 日韩精品一区二区三区色偷偷| 91精品国产自产在线老师啪| 中国成人亚色综合网站| 国产日韩欧美综合| 国产精品久久久久久久久久久久冷 | 国产日韩欧美综合| 国产成人精品在线视频| 色综合电影网| 国产精彩视频一区二区| 亚洲永久在线观看| 超碰网在线观看| 在线观看免费91| www.av蜜桃| 亚洲天堂第一区| 成人羞羞国产免费| 欧美精品国产精品日韩精品| 国产一级二级三级精品| 国产精品国产三级国产aⅴ9色| 欧美日韩另类综合| 色吧影院999| 日韩精品福利片午夜免费观看| 久久九九视频| 日本黄网站色大片免费观看| 国产国语videosex另类| 少妇免费毛片久久久久久久久| 国产精品777| 日韩精品久久一区二区三区| 九九九九免费视频| 欧美精品123| 麻豆成人在线看| 国产免费高清一区| 亚洲一区二区三区777| 国产精品av一区| 天堂va久久久噜噜噜久久va| 色偷偷噜噜噜亚洲男人| 青青草成人在线| 国产精品免费区二区三区观看| 国产情侣av自拍| 亚洲欧洲三级| 久久久久久欧美精品色一二三四| 欧美日韩国产三区| 国产精品海角社区在线观看| 国产美女精品久久久| 亚洲国产欧美日韩| 国产成人精品国内自产拍免费看| 日韩久久久久久久久久久久| 久久精品一偷一偷国产| 国产日韩在线精品av| 中文字幕一区二区三区四区五区六区 | 欧美在线视频一区| 成人444kkkk在线观看| 国产精品亚洲不卡a| 日韩在线第一区| 久久久国产视频91| www.av中文字幕| 欧美交换配乱吟粗大25p| 久久99亚洲热视| 国产成人a亚洲精品| 国模精品一区二区三区色天香| 精品国产第一页| 国产不卡视频在线| 精品视频第一区| 性高潮久久久久久久久| 国产精品日韩欧美大师| 91久久久久久久久| 欧美不卡福利| 欧美一区二区三区四区在线| 国产精品毛片a∨一区二区三区|国| 91久久伊人青青碰碰婷婷| 男人天堂手机在线视频| 亚洲精品久久区二区三区蜜桃臀| 国产精品啪啪啪视频| 久久久视频在线| 国产一区二区三区乱码| 午夜精品一区二区三区视频免费看| 国产精品入口夜色视频大尺度| 2019日本中文字幕| 国产区亚洲区欧美区| 欧美日韩黄色一级片| 亚洲精品视频一区二区三区 | 国产在线精品自拍| 日本一道本久久| 中文字幕在线观看一区二区三区| 久久人人爽人人爽人人片亚洲| 91免费视频国产| 国产一区二区在线播放| 日本免费不卡一区二区| 综合一区中文字幕| 国产精品久久国产精品| 久久久久久亚洲| 久久日韩精品| 99精品视频播放| 国产精品揄拍500视频| 国产一区二区三区小说| 欧美激情亚洲天堂| 欧美做受高潮1| 日本高清不卡在线| 午夜精品理论片| 亚洲精品国产精品久久| 色综合久久天天综线观看| 久久这里有精品视频| 日韩视频在线免费| 精品国产视频在线| 北条麻妃在线一区二区| 日韩在线播放av| 色偷偷88888欧美精品久久久| 国产成人a亚洲精v品无码| 国产极品精品在线观看 | 99久久综合狠狠综合久久止| 国产精品亚洲综合天堂夜夜| 国产精品主播视频| 成人久久久久久久| av在线免费观看国产| 97精品伊人久久久大香线蕉| 国产精品自拍首页| 99中文字幕在线观看| 91久久国产婷婷一区二区| 91老司机精品视频| 久久久999视频| 久久久噜噜噜www成人网| 久久99欧美| 国产精品视频白浆免费视频| 国产精品黄视频| 亚洲最新免费视频| 色香蕉在线观看|