|
TrueZIP Kernel 7.0-rc2 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectde.schlichtherle.truezip.util.ServiceLocator
@ThreadSafe @DefaultAnnotation(value=edu.umd.cs.findbugs.annotations.NonNull.class) public final class ServiceLocator
Provides utility methods for convenient class, resource and service location which is designed to work in both OSGi and JEE environments.
If the class loader provided to the constructor is the current thread's context class loader, then the methods of this class will locate classes, resources or services by using this class loader only. Otherwise, the given class loader is used first. Second, the current thread's context class loader is used.
When loading a class, the search stops on the first hit, so if the given class loader finds the class, the current thread's context class loader is not used.
When enumerating resources and services, the results of both class loaders are concatenated, so a resource or a service may get enumerated twice! If this is not acceptable, you should create a set from the enumeration results.
| Field Summary | |
|---|---|
private ClassLoader |
l1
|
| Constructor Summary | |
|---|---|
ServiceLocator()
Equivalent to new ServiceLocator(null). |
|
ServiceLocator(ClassLoader loader)
Constructs a new service locator which uses the given class loader first to locate classes, resources or services on the class path. |
|
| Method Summary | ||
|---|---|---|
Class<?> |
getClass(String name)
Loads a class according to the algorithm described in the class Javadoc. |
|
Enumeration<URL> |
getResources(String name)
Enumerates resources according to the algorithm described in the class Javadoc. |
|
|
getService(Class<S> service,
Class<? extends S> def)
Returns a new service provider implementation instance. |
|
|
getServices(Class<S> service)
Enumerates all service provider implementation instances. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private final ClassLoader l1
| Constructor Detail |
|---|
public ServiceLocator()
new ServiceLocator(null).
public ServiceLocator(@CheckForNull
ClassLoader loader)
null, then the system class loader is used.
loader - the nullable class loader to locate classes, resources and
services.| Method Detail |
|---|
public <S> Iterator<S> getServices(Class<S> service)
ServiceLoader.load(java.lang.Class, java.lang.ClassLoader).
This method should be preferred over getService(java.lang.Class if more than
one meaningful implementation of a service provider interface is
expected at run time.
, java.lang.Class extends S>)
S - The type of the service provider specification.service - the service provider specification.
ServiceConfigurationError - if an exception occurs.
@Nullable
public <S> S getService(Class<S> service,
@CheckForNull
Class<? extends S> def)
system property with
the service provider interface class name as the key and the given
service provider implementation class name as the default value.
The service provider implementation class is then loaded using
getClass(java.lang.String) and finally instantiated by calling its no-arg
constructor.
This method should be preferred over getServices(java.lang.Class if
)
null as the result or providing a default
service provider implementation is acceptable.
S - The type of the service provider specification.service - the service provider specification.def - the default service provider implementation.
null
if no service provider implementation is known.
ServiceConfigurationError - if locating, instantiating or casting
the service fails for some reason.public Class<?> getClass(String name)
name - The fully qualified name of the class to locate.
ServiceConfigurationError - if locating the class fails for some
reason.public Enumeration<URL> getResources(String name)
name - The fully qualified name of the resources to locate.
ServiceConfigurationError - if locating the resources fails for
some reason.
|
TrueZIP Kernel 7.0-rc2 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||