src/java.base/share/classes/java/util/ServiceLoader.java

Print this page




  29 import java.io.IOException;
  30 import java.io.InputStream;
  31 import java.io.InputStreamReader;
  32 import java.net.URL;
  33 import java.security.AccessController;
  34 import java.security.AccessControlContext;
  35 import java.security.PrivilegedAction;
  36 import java.util.ArrayList;
  37 import java.util.Enumeration;
  38 import java.util.Iterator;
  39 import java.util.List;
  40 import java.util.NoSuchElementException;
  41 
  42 
  43 /**
  44  * A simple service-provider loading facility.
  45  *
  46  * <p> A <i>service</i> is a well-known set of interfaces and (usually
  47  * abstract) classes.  A <i>service provider</i> is a specific implementation
  48  * of a service.  The classes in a provider typically implement the interfaces
  49  * and subclass the classes defined in the service itself.  Service providers
  50  * can be installed in an implementation of the Java platform in the form of
  51  * extensions, that is, jar files placed into any of the usual extension
  52  * directories.  Providers can also be made available by adding them to the
  53  * application's class path or by some other platform-specific means.
  54  *
  55  * <p> For the purpose of loading, a service is represented by a single type,
  56  * that is, a single interface or abstract class.  (A concrete class can be
  57  * used, but this is not recommended.)  A provider of a given service contains
  58  * one or more concrete classes that extend this <i>service type</i> with data
  59  * and code specific to the provider.  The <i>provider class</i> is typically
  60  * not the entire provider itself but rather a proxy which contains enough
  61  * information to decide whether the provider is able to satisfy a particular
  62  * request together with code that can create the actual provider on demand.
  63  * The details of provider classes tend to be highly service-specific; no
  64  * single class or interface could possibly unify them, so no such type is
  65  * defined here.  The only requirement enforced by this facility is that
  66  * provider classes must have a zero-argument constructor so that they can be
  67  * instantiated during loading.
  68  *
  69  * <p><a name="format"> A service provider is identified by placing a
  70  * <i>provider-configuration file</i> in the resource directory
  71  * <tt>META-INF/services</tt>.</a>  The file's name is the fully-qualified <a
  72  * href="../lang/ClassLoader.html#name">binary name</a> of the service's type.




  29 import java.io.IOException;
  30 import java.io.InputStream;
  31 import java.io.InputStreamReader;
  32 import java.net.URL;
  33 import java.security.AccessController;
  34 import java.security.AccessControlContext;
  35 import java.security.PrivilegedAction;
  36 import java.util.ArrayList;
  37 import java.util.Enumeration;
  38 import java.util.Iterator;
  39 import java.util.List;
  40 import java.util.NoSuchElementException;
  41 
  42 
  43 /**
  44  * A simple service-provider loading facility.
  45  *
  46  * <p> A <i>service</i> is a well-known set of interfaces and (usually
  47  * abstract) classes.  A <i>service provider</i> is a specific implementation
  48  * of a service.  The classes in a provider typically implement the interfaces
  49  * and subclass the classes defined in the service itself.
  50  * Providers can be made available by adding them to the


  51  * application's class path or by some other platform-specific means.
  52  *
  53  * <p> For the purpose of loading, a service is represented by a single type,
  54  * that is, a single interface or abstract class.  (A concrete class can be
  55  * used, but this is not recommended.)  A provider of a given service contains
  56  * one or more concrete classes that extend this <i>service type</i> with data
  57  * and code specific to the provider.  The <i>provider class</i> is typically
  58  * not the entire provider itself but rather a proxy which contains enough
  59  * information to decide whether the provider is able to satisfy a particular
  60  * request together with code that can create the actual provider on demand.
  61  * The details of provider classes tend to be highly service-specific; no
  62  * single class or interface could possibly unify them, so no such type is
  63  * defined here.  The only requirement enforced by this facility is that
  64  * provider classes must have a zero-argument constructor so that they can be
  65  * instantiated during loading.
  66  *
  67  * <p><a name="format"> A service provider is identified by placing a
  68  * <i>provider-configuration file</i> in the resource directory
  69  * <tt>META-INF/services</tt>.</a>  The file's name is the fully-qualified <a
  70  * href="../lang/ClassLoader.html#name">binary name</a> of the service's type.