net.java.dev.vcc.util
Class ServiceLoaderProxy<S>

java.lang.Object
  extended by net.java.dev.vcc.util.ServiceLoaderProxy<S>

public class ServiceLoaderProxy<S>
extends java.lang.Object

A proxy for ServiceLoader that uses either the native Java 6 service loader implementation or an internal implementation that works on Java 5.


Method Summary
static java.lang.ClassLoader getContextClassLoader()
          Method getContextClassLoader returns the contextClassLoader of the current thread.
 java.util.Iterator<S> iterator()
          Lazily loads the available providers of this loader's service.
static
<S> ServiceLoaderProxy<S>
load(java.lang.Class<S> service, java.lang.ClassLoader loader)
          Creates a new service loader for the given service type and class loader.
 void reload()
          Clear this loader's provider cache so that all providers will be reloaded.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

reload

public void reload()
Clear this loader's provider cache so that all providers will be reloaded.

After invoking this method, subsequent invocations of the iterator method will lazily look up and instantiate providers from scratch, just as is done by a newly-created loader.

This method is intended for use in situations in which new providers can be installed into a running Java virtual machine.


iterator

public java.util.Iterator<S> iterator()
Lazily loads the available providers of this loader's service.

The iterator returned by this method does not support removal. Invoking its remove method will cause an UnsupportedOperationException to be thrown.

Returns:
An iterator that lazily loads providers for this loader's service

load

public static <S> ServiceLoaderProxy<S> load(java.lang.Class<S> service,
                                             java.lang.ClassLoader loader)
Creates a new service loader for the given service type and class loader.

Parameters:
service - The interface or abstract class representing the service
loader - The class loader to be used to load provider-configuration files and provider classes, or null if the system class loader (or, failing that, the bootstrap class loader) is to be used
Returns:
A new service loader

getContextClassLoader

public static java.lang.ClassLoader getContextClassLoader()
Method getContextClassLoader returns the contextClassLoader of the current thread.

Returns:
the contextClassLoader (type ClassLoader) of the current thread.


Copyright © 2009. All Rights Reserved.