好男人天堂网,久久精品国产这里是免费,国产精品成人一区二区,男人天堂网2021,男人的天堂在线观看,丁香六月综合激情

當前位置:首頁 > 網站舊欄目 > 學習園地 > 設計軟件教程 > 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小技巧
相關熱詞搜索:
一级女性大黄生活片免费| 可以免费看毛片的网站| 亚洲不卡一区二区三区在线| 国产91精品一区| 天天色成人网| 国产精品12| 亚飞与亚基在线观看| a级毛片免费全部播放| 青青久热| 久久99这里只有精品国产| 999久久66久6只有精品| 美女免费精品高清毛片在线视| 国产亚洲精品成人a在线| 成人av在线播放| 国产精品12| 欧美一级视频免费观看| 韩国毛片免费| 美国一区二区三区| 九九精品影院| 国产美女在线观看| 国产不卡高清在线观看视频| 国产一区二区精品| 国产麻豆精品免费密入口| 黄色福利片| 日韩一级精品视频在线观看| 精品久久久久久综合网| 国产综合成人观看在线| 香蕉视频亚洲一级| 国产一区二区精品在线观看| 精品视频在线观看一区二区三区| 青草国产在线| 日韩专区亚洲综合久久| 好男人天堂网 久久精品国产这里是免费 国产精品成人一区二区 男人天堂网2021 男人的天堂在线观看 丁香六月综合激情 | 国产麻豆精品免费密入口| 国产伦久视频免费观看视频| 色综合久久久久综合体桃花网| 欧美激情一区二区三区中文字幕| 久久久久久久久综合影视网| 青青青草影院 | 亚洲女人国产香蕉久久精品| 日韩在线观看视频免费| 国产一区二区精品尤物| 九九精品在线播放| 精品视频在线观看视频免费视频| 欧美a级片免费看| 精品国产亚一区二区三区| 午夜在线亚洲| 亚欧视频在线| 精品视频在线观看视频免费视频| 久久久久久久久综合影视网| 高清一级淫片a级中文字幕 | 韩国毛片 免费| 亚州视频一区二区| 一级女性全黄久久生活片| 九九精品影院| 一级毛片视频免费| 99久久精品国产高清一区二区 | 毛片高清| 欧美1区| 高清一级淫片a级中文字幕 | 精品久久久久久中文字幕一区| 国产伦久视频免费观看视频| a级黄色毛片免费播放视频| 一级片片| 国产美女在线观看| 一级女性全黄久久生活片| 国产麻豆精品hdvideoss| 久久99中文字幕| 麻豆午夜视频| 四虎影视久久久免费| 国产伦精品一区三区视频| 国产成人欧美一区二区三区的| 欧美激情伊人| 二级特黄绝大片免费视频大片| 国产不卡在线观看视频| 中文字幕一区二区三区精彩视频| 美女免费精品高清毛片在线视| 高清一级淫片a级中文字幕 | 精品久久久久久免费影院| 国产美女在线观看| 黄色短视屏| 韩国三级香港三级日本三级| 亚欧视频在线| a级黄色毛片免费播放视频| 九九国产| 久草免费在线视频| 日本乱中文字幕系列| 91麻豆tv| 日本免费乱人伦在线观看 | 欧美日本韩国| 欧美激情影院| 日本免费区| 中文字幕一区二区三区精彩视频| 99久久精品国产片| 久久精品大片| 国产伦精品一区二区三区在线观看| 国产一区免费在线观看| 色综合久久天天综合| 美女免费精品高清毛片在线视| 国产视频久久久久| 久久精品成人一区二区三区| 韩国毛片免费| 国产综合成人观看在线| 精品国产一区二区三区免费| 久久国产一久久高清| 国产成人女人在线视频观看| 国产伦久视频免费观看视频| 精品久久久久久综合网| 国产不卡福利| 日韩专区亚洲综合久久| 欧美激情伊人| 精品视频在线观看视频免费视频| 欧美日本韩国| 精品国产亚一区二区三区| 99色精品| a级毛片免费观看网站| 九九久久国产精品大片| 午夜激情视频在线播放| 亚洲爆爽| 国产原创中文字幕| 成人a大片在线观看| 日韩女人做爰大片| 精品视频在线看| 精品在线免费播放| 欧美夜夜骑 青草视频在线观看完整版 久久精品99无色码中文字幕 欧美日韩一区二区在线观看视频 欧美中文字幕在线视频 www.99精品 香蕉视频久久 | 韩国三级香港三级日本三级la| 夜夜操网| 精品视频在线观看免费| 黄视频网站在线免费观看| 麻豆网站在线看| 午夜欧美成人香蕉剧场| 天天色成人| 免费一级片在线| 国产伦久视频免费观看 视频| 色综合久久久久综合体桃花网| 99热精品在线| 亚洲wwwwww| 国产国语对白一级毛片| 欧美激情一区二区三区在线播放| 91麻豆国产福利精品| 色综合久久手机在线| 亚洲第一页乱| 国产视频一区二区在线播放| 国产高清在线精品一区二区| 精品视频在线观看一区二区三区| 日本乱中文字幕系列| 欧美激情一区二区三区在线| 国产综合成人观看在线| 成人在免费观看视频国产| 九九精品在线播放| 99色精品| 美女免费精品视频在线观看| 亚洲 激情| 成人影院一区二区三区| 一本伊大人香蕉高清在线观看| 99色视频在线观看| 国产成人女人在线视频观看| 九九久久99| 国产精品1024永久免费视频| 中文字幕97| 日本在线不卡免费视频一区| 日日爽天天| 好男人天堂网 久久精品国产这里是免费 国产精品成人一区二区 男人天堂网2021 男人的天堂在线观看 丁香六月综合激情 | 亚洲精品影院久久久久久| 国产视频网站在线观看| 精品国产亚洲人成在线| 一本高清在线| 国产福利免费视频| 韩国三级视频网站| 国产高清视频免费观看| 99久久网站| 99热视热频这里只有精品| 一本高清在线| 色综合久久手机在线| 国产美女在线观看| 国产麻豆精品免费视频| 精品国产一区二区三区久| 久久久久久久久综合影视网| 国产高清在线精品一区a| 精品国产三级a| 91麻豆精品国产自产在线 | 国产亚洲免费观看| 日韩av东京社区男人的天堂| 91麻豆爱豆果冻天美星空| 日本在线不卡免费视频一区| 国产伦精品一区三区视频| 日本特黄特色aaa大片免费| 黄视频网站在线看| 国产高清在线精品一区二区| 国产伦久视频免费观看 视频| 91麻豆爱豆果冻天美星空| 日日夜夜婷婷| 国产视频一区二区在线观看| 久久国产精品只做精品| 日本伦理黄色大片在线观看网站| 久久福利影视| 久久国产精品永久免费网站| 日韩专区亚洲综合久久| 四虎久久影院| 一级女性全黄久久生活片|