Exemplo n.º 1
0
 /**
  * Creates a new service loader for the given service type, using the extension class loader.
  *
  * <p>This convenience method simply locates the extension class loader, call it
  * <tt><i>extClassLoader</i></tt>, and then returns
  *
  * <blockquote>
  *
  * <pre>
  * ServiceLoader.load(<i>service</i>, <i>extClassLoader</i>)</pre>
  *
  * </blockquote>
  *
  * <p>If the extension class loader cannot be found then the system class loader is used; if there
  * is no system class loader then the bootstrap class loader is used.
  *
  * <p>This method is intended for use when only installed providers are desired. The resulting
  * service will only find and load providers that have been installed into the current Java
  * virtual machine; providers on the application's class path will be ignored.
  *
  * @param service The interface or abstract class representing the service
  * @return A new service loader
  */
 public static <S> ServiceLoader<S> loadInstalled(Class<S> service) {
   ClassLoader cl = ClassLoader.getSystemClassLoader();
   ClassLoader prev = null;
   while (cl != null) {
     prev = cl;
     cl = cl.getParent();
   }
   return ServiceLoader.load(service, prev);
 }
Exemplo n.º 2
0
 /**
  * Creates a new service loader for the given service type, using the current thread's {@linkplain
  * java.lang.Thread#getContextClassLoader context class loader}.
  *
  * <p>An invocation of this convenience method of the form
  *
  * <blockquote>
  *
  * <pre>
  * ServiceLoader.load(<i>service</i>)</pre>
  *
  * </blockquote>
  *
  * is equivalent to
  *
  * <blockquote>
  *
  * <pre>
  * ServiceLoader.load(<i>service</i>,
  *                    Thread.currentThread().getContextClassLoader())</pre>
  *
  * </blockquote>
  *
  * @param service The interface or abstract class representing the service
  * @return A new service loader
  */
 public static <S> ServiceLoader<S> load(Class<S> service) {
   ClassLoader cl = Thread.currentThread().getContextClassLoader();
   return ServiceLoader.load(service, cl);
 }