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

當(dāng)前位置:首頁 > 網(wǎng)站舊欄目 > 學(xué)習(xí)園地 > 設(shè)計軟件教程 > 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)熱詞搜索:
亚洲人成网站在线播放2019 _日韩国产欧美精品_久久夜色精品国产欧美乱_在线视频福利一区
国产成人生活片| 国产成人av网| 欧美一区二区三区艳史| 亚洲三级一区| 动漫一区二区在线| 婷婷亚洲婷婷综合色香五月| 无码中文字幕色专区| 天天摸天天碰天天添| 天堂av在线中文| 日韩激情免费视频| 激情久久av| 国产日韩精品推荐| 成人av播放| 高清一区二区三区四区五区| 91国产高清在线| 久久精品日产第一区二区三区乱码| 国产l精品国产亚洲区久久| 精品国内亚洲在观看18黄| 国产精品免费看久久久无码| 国产精品久久久久久久av大片 | 狠狠色综合一区二区| 国产中文字幕视频在线观看| 高清国语自产拍免费一区二区三区| 91免费视频国产| 久久综合九色欧美狠狠| 久久久99免费视频| 在线精品日韩| 日韩欧美一区二区三区四区| 精品视频一区在线| 91精品国产综合久久香蕉| 日韩中文字幕在线精品| 欧美成人精品在线| 亚洲v日韩v综合v精品v| 欧美在线播放cccc| 成人久久一区二区三区| 久久久久久久久久久久久久一区| 国产精品成人一区二区| 午夜视频久久久| 蜜桃精品久久久久久久免费影院| 国产美女久久久| 色偷偷av一区二区三区| 久久99精品视频一区97| 人人澡人人澡人人看欧美| 国产欧美高清在线| 久久久久久久香蕉| 欧美精品xxx| 欧美亚洲国产精品| 国产精品.com| 欧美日韩国产成人在线观看| 日本精品一区二区三区在线| 国产伦精品一区二区三| 久久久久久久久久久福利| 精品国产成人av在线免| 热久久视久久精品18亚洲精品| 国产在线视频2019最新视频| 久久久亚洲综合网站| 色综合久综合久久综合久鬼88| 欧美亚洲一级片| 久久人人爽人人| 一本久道久久综合| 国产一区二区免费在线观看| 日韩一区二区精品视频| 欧美一级日本a级v片| 国产精品一区二区三区成人| 久久精品色欧美aⅴ一区二区| 懂色av粉嫩av蜜臀av| 国产精品稀缺呦系列在线| 国产精品免费一区二区三区四区| 日本一区视频在线观看| 国产美女精品久久久| 久久精品视频中文字幕| 日本欧美在线视频| 国产精品69久久久| 亚洲精品一区二区三区樱花| 国产精品亚洲自拍| 国产aaa精品| 国产日韩专区在线| 欧美另类在线播放| 国产一区免费| 久久成人亚洲精品| 国产中文欧美精品| 国产精品久久久久9999小说| 精品日本一区二区三区在线观看| 日韩在线观看成人| 欧美一区二区三区在线播放| 91免费视频国产| 亚洲国产一区二区在线| av免费观看国产| 亚洲熟妇无码一区二区三区导航| 成人精品久久一区二区三区| 宅男一区二区三区| 成人动漫在线观看视频| 一区不卡字幕| 97碰在线观看| 亚洲va久久久噜噜噜久久天堂| 99久久激情视频| 午夜精品一区二区在线观看的| …久久精品99久久香蕉国产| 欧美一级片免费在线| 国产成人高潮免费观看精品 | 亚洲精品在线观看免费| 国产精品av网站| 日韩精品一区二区免费| 久久精品在线视频| 国产一区二区三区乱码| 亚洲视频在线观看日本a| 国产精品99久久久久久www| 日韩精彩视频| 欧美xxxx综合视频| 99久久精品免费看国产一区二区三区 | 国产精品视频一区国模私拍| 欧美高清一区二区| 不卡av电影院| 91久久久久久国产精品| 日本福利视频导航| 国产精品美女呻吟| 国产伦精品一区二区三区免费视频| 一本色道久久综合亚洲二区三区 | 久久婷婷开心| 欧美亚洲视频一区二区| 欧美成人精品在线观看| 国产精品亚洲综合| 日韩国产精品一区二区| 欧美成年人视频网站| 久久人人97超碰精品888| 欧美成人综合一区| 在线观看成人av| 久久精品国产一区二区三区日韩| 免费看国产一级片| 午夜精品久久久久久久99热浪潮| 日韩亚洲精品视频| 国产精品自产拍高潮在线观看| 欧美一级片中文字幕| 久久的精品视频| 国产成人av在线播放| 国产在线999| 少妇性饥渴无码a区免费| 国产精品久久久久久久天堂| 91久久精品一区| 狠狠干视频网站| 天天综合五月天| 久久成人精品电影| 久久久久久久色| 波多野结衣成人在线| 免费在线a视频| 日本在线精品视频| 一区二区视频在线观看| 久热精品视频在线| 久久精品综合一区| 成人av男人的天堂| 国内精品久久国产| 视频一区二区三区在线观看| 九九精品视频在线观看| 久久激情视频久久| 久久精品网站视频| 97精品视频在线| 国产欧美日韩视频一区二区三区| 热久久这里只有精品| 亚洲精品中文字幕无码蜜桃| 久久亚洲国产精品成人av秋霞| 色阁综合伊人av| 国产成人a亚洲精v品无码| av无码精品一区二区三区| 国产日韩精品入口| 欧美韩国日本精品一区二区三区| 日本www在线播放| 亚洲高清123| 亚洲电影一二三区| 亚洲一区三区视频在线观看| 欧美激情精品久久久久久大尺度| 国产精品久久久久一区二区 | 欧美精品国产精品日韩精品| 国产精品成人av性教育| 国产精品无码免费专区午夜 | 久久九九有精品国产23| 色婷婷久久av| 久久久久久久久久久av| 久久人人爽人人爽人人av| 99精品一区二区三区的区别| 国产女大学生av| 国产一区二区高清视频| 国产资源在线视频| 精品一区国产| 国产中文字幕乱人伦在线观看| 精品一区在线播放| 国产一区玩具在线观看| 国产中文字幕免费观看| 国产中文字幕91| 国产美女高潮久久白浆| 国产伦精品一区二区三区视频孕妇 | 黄网站欧美内射| 欧美日产一区二区三区在线观看| 欧美一区少妇| 韩国精品一区二区三区六区色诱| 男人天堂av片| 国产在线拍偷自揄拍精品| 国产免费内射又粗又爽密桃视频 | 人人澡人人澡人人看欧美| 欧美一区亚洲二区| 免费在线观看的毛片|