public abstract class ResourceLoader extends Object
Defines a general access point of loading any text resources and services.
Specification: All external subclasses must have a public no-arg constructor.
| Modifier and Type | Field and Description |
|---|---|
static String |
EXTERNAL_RESOURCE_LOADER
Name of system property responsible for getting an external instance as fully qualified class name.
|
static String |
USE_OF_CLASSLOADER_ONLY
Name of system property controlling if the use of classloader should be enforced instead
of trying an URI-construction first.
|
| Modifier and Type | Method and Description |
|---|---|
static ResourceLoader |
getInstance()
Applications should never use the constructor but this static method to achieve a general instance.
|
InputStream |
load(Class<?> moduleRef,
String path,
boolean noCache)
Loads a resource as input stream based on the classloader of given module reference.
|
abstract InputStream |
load(URI uri,
boolean noCache)
Loads given URI-resource as input stream.
|
abstract URI |
locate(String moduleName,
Class<?> moduleRef,
String path)
Constructs an URI for given module resource.
|
<S> void |
registerService(Class<S> serviceInterface,
S implementation)
Registers an external service provider.
|
abstract <S> Iterable<S> |
services(Class<S> serviceInterface)
Finds a collection of service providers available for given service provider interface.
|
public static final String EXTERNAL_RESOURCE_LOADER
Name of system property responsible for getting an external instance as fully qualified class name.
Time4J will throw an Error if the configuration entry is wrong.
public static final String USE_OF_CLASSLOADER_ONLY
Name of system property controlling if the use of classloader should be enforced instead of trying an URI-construction first.
The value is either "true" or "false" (default). This property will be
ignored on Android platforms. Applications in an OSGi-environment should set the property value
to true.
public static ResourceLoader getInstance()
Applications should never use the constructor but this static method to achieve a general instance.
ResourceLoaderpublic abstract URI locate(String moduleName, Class<?> moduleRef, String path)
Constructs an URI for given module resource.
Attention: Some implementations might yield an uri without verifying if the uri resource really exists.
moduleName - name of related time4j-modulemoduleRef - module-specific class referencepath - path to text resourcenull if unable to locate the resourcepublic abstract InputStream load(URI uri, boolean noCache)
Loads given URI-resource as input stream.
Callers are responsible for closing the result stream.
uri - uniform resource identifier as result of locate-method (optional)noCache - avoid caching?null if the resource could not be openedlocate(String, Class, String)public final InputStream load(Class<?> moduleRef, String path, boolean noCache) throws IOException
Loads a resource as input stream based on the classloader of given module reference.
Callers are responsible for closing the result stream.
moduleRef - module-specific class referencepath - path to text resource (must be understandable by class loaders)noCache - avoid caching?IOException - if the stream cannot be opened or if this method is called on Android platformspublic abstract <S> Iterable<S> services(Class<S> serviceInterface)
Finds a collection of service providers available for given service provider interface.
S - generic service typeserviceInterface - service provider interfacepublic <S> void registerService(Class<S> serviceInterface, S implementation)
Registers an external service provider.
This method is mainly intended to register an extra time zone repository in the context of OSGi where the service loader mechanism does not work. Important: Calling this method must be done before executing any other Time4J-code. Example for registering the tzdata-module (v3.0 or later):
ResourceLoader.getInstance().registerService(
ZoneModelProvider.class,
new net.time4j.tz.repo.TimezoneRepositoryProviderSPI());
Note: The example can be shortened by the expression net.time4j.tz.repo.TZDATA.init()
which also provides actual leap second support.
S - generic service typeserviceInterface - service interfaceimplementation - service providerIllegalStateException - if already registered or called on a non-standard resource loader like on AndroidCopyright © 2014–2021. All rights reserved.