<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    agapple

    BlogJava 首頁 新隨筆 聯系 聚合 管理
      13 Posts :: 1 Stories :: 1 Comments :: 0 Trackbacks
    官方描述:http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html

    The META-INF directory

    The following files/directories in the META-INF directory are recognized and interpreted by the Java 2 Platform to configure applications, extensions, class loaders and services:
    • MANIFEST.MF
    The manifest file that is used to define extension and package related data.
    • INDEX.LIST
    This file is generated by the new "-i" option of the jar tool, which contains location information for packages defined in an application or extension.  It is part of the JarIndex implementation and used by class loaders to speed up their class loading process.
    • x.SF
    The signature file for the JAR file.  'x' stands for the base file name.
    • x.DSA
    The signature block file associated with the signature file with the same base file name. This file stores the digital signature of the corresponding signature file.
    • services/
    This directory stores all the service provider configuration files.

    這里指出了jar包的典型的目錄結構。簡單翻譯:

    META-INF目錄中的下列文件和目錄獲得Java 2平臺的認可與解釋,用來配置應用程序、擴展程序、類加載器和服務:
    • MANIFEST.MF:清單文件,用來定義與擴展和數據包相關的數據。
    • INDEX.LIST:這個文件由JAR工具的新“-i”選項生成,其中包含在一個應用程序或擴展中定義的數據包的地址信息。它是JarIndex的一部分,被類加載器用來加速類加載過程。
    • x.SF:JAR文件的簽名文件。x代表基礎文件名。
    • x.DSA:這個簽名塊文件與同名基礎簽名文件有關。此文件存儲對應簽名文件的數字簽名。
    • services/:這個目錄存儲所有服務提供程序配置文件。

    Service Provider

    Overview

    Files in the META-INF/services directory are service provider configuration files. A service is a well-known set of interfaces and (usually abstract) classes. A service provider is a specific implementation of a service. The classes in a provider typically implement the interfaces and subclass the classes defined in the service itself. Service providers may be installed in an implementation of the Java platform in the form of extensions, that is, jar files placed into any of the usual extension directories. Providers may also be made available by adding them to the applet or application class path or by some other platform-specific means.

    A service is represented by an abstract class. A provider of a given service contains one or more concrete classes that extend this service class with data and code specific to the provider. This provider class will typically not be the entire provider itself but rather a proxy that contains enough information to decide whether the provider is able to satisfy a particular request together with code that can create the actual provider on demand. The details of provider classes tend to be highly service-specific; no single class or interface could possibly unify them, so no such class has been defined. The only requirement enforced here is that provider classes must have a zero-argument constructor so that they may be instantiated during lookup.
     

    Provider-Configuration File

    A service provider identifies itself by placing a provider-configuration file in the resource directory META-INF/services. The file's name should consist of the fully-qualified name of the abstract service class. The file should contain a newline-separated list of unique concrete provider-class names. Space and tab characters, as well as blank lines, are ignored. The comment character is '#' (0x23); on each line all characters following the first comment character are ignored. The file must be encoded in UTF-8.
     

    Example

    Suppose we have a service class named java.io.spi.CharCodec. It has two abstract methods:

        public abstract CharEncoder getEncoder(String encodingName);
      public abstract CharDecoder getDecoder(String encodingName);

    Each method returns an appropriate object or null if it cannot translate the given encoding. Typical CharCodec providers will support more than one encoding.

    If sun.io.StandardCodec is a provider of the CharCodec service then its jar file would contain the file META-INF/services/java.io.spi.CharCodec. This file would contain the single line:

       sun.io.StandardCodec    # Standard codecs for the platform

    To locate an encoder for a given encoding name, the internal I/O code would do something like this:

       CharEncoder getEncoder(String encodingName) {
           Iterator ps = Service.providers(CharCodec.class);
           while (ps.hasNext()) {
               CharCodec cc = (CharCodec)ps.next();
               CharEncoder ce = cc.getEncoder(encodingName);
               if (ce != null)
                   return ce;
           }
           return null;
       }
     

    The provider-lookup mechanism always executes in the security context of the caller. Trusted system code should typically invoke the methods in this class from within a privileged security context.


    介紹:

    在META-INF/services目錄下保存的是service provider的配置文件。 服務在應用中會是一個接口(更多的是抽象類)。
    一個類服務器提供者實現了一個服務類。這類的服務提供類可以以擴展的形式發布到平臺上。所以,jar文件引入了擴展目錄,同樣你也可以將服務提供者加入classpath提供訪問。

    服務都是表現為一個積累,而一個服務提供者通常是集成或實現了服務定義類。服務提供類通常不會像代理類一樣為了正常提供服務而包含了請求者的許多信息。服務提供類一般傾向于高集成。
    對這類服務提供類的唯一強制性要求就是必須有一個無參的構造函數。

    provider 配置文件
    META-INF/services目錄作為provider配置文件的存放路徑。provider配置文件中必須是全類名(包含package)。配置文件可以存在space tab 換行等字符,#作為注釋。
    注意:provider配置文件必須是以UTF-8編碼。

     


    總結:
          service provider機制為程序的動態擴展提供了契機,在應用中你可以針對接口編程,通過RTTI技術可以比較完美的解決程序之間的耦合性。相比于spring DIP機制,這也是一個不錯的嘗試,至少它不需要耦合spring包。

    Blog : http://agapple.javaeye.com/  歡迎訪問
    posted on 2008-10-31 11:32 agapple 閱讀(771) 評論(0)  編輯  收藏 所屬分類: java
    主站蜘蛛池模板: 四虎免费永久在线播放| 真实国产乱子伦精品免费| 成人最新午夜免费视频| 亚洲的天堂av无码| 国产成人福利免费视频| 亚洲成av人片在线看片| 波多野结衣在线免费视频| 亚洲国产福利精品一区二区 | 青青草国产免费国产是公开| 在线成人a毛片免费播放| 亚洲精华国产精华精华液| 暖暖免费高清日本中文| 日本视频免费观看| 亚洲一区爱区精品无码| 久久这里只精品热免费99| 亚洲美女在线观看播放| 搡女人真爽免费视频大全| www亚洲精品久久久乳| 亚洲阿v天堂在线2017免费| 国产一区二区三区免费观在线| 美腿丝袜亚洲综合| 精品无码人妻一区二区免费蜜桃| 亚洲va精品中文字幕| 成人永久免费福利视频网站| 一区二区三区AV高清免费波多| 亚洲乱码一区二区三区在线观看 | 日亚毛片免费乱码不卡一区| 免费在线不卡视频| 国产婷婷成人久久Av免费高清 | 亚洲尹人九九大色香蕉网站| 免费A级毛片无码无遮挡内射| 日本系列1页亚洲系列| 精品国产亚洲一区二区三区| 国产成人福利免费视频| 四虎精品成人免费视频| 亚洲第一中文字幕| 黑人粗长大战亚洲女2021国产精品成人免费视频| 亚洲高清国产拍精品熟女| 亚洲精品成人片在线观看精品字幕 | 亚洲理论片中文字幕电影| 永久中文字幕免费视频网站|