Class ResourceLoader
Defines a general access point of loading any text resources and services.
Specification: All external subclasses must have a public no-arg constructor.
- Since:
- 3.5/4.3
- Author:
- Meno Hochschild
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic ResourceLoader
Applications should never use the constructor but this static method to achieve a general instance.Loads a resource as input stream based on the classloader of given module reference.abstract InputStream
Loads given URI-resource as input stream.abstract URI
Constructs an URI for given module resource.<S> void
registerService(Class<S> serviceInterface, S implementation)
Registers an external service provider.abstract <S> Iterable<S>
Finds a collection of service providers available for given service provider interface.
-
Field Details
-
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.- See Also:
- Constant Field Values
-
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
.- Since:
- 3.16/4.13
- See Also:
- Constant Field Values
-
-
Method Details
-
getInstance
Applications should never use the constructor but this static method to achieve a general instance.
- Returns:
ResourceLoader
- Since:
- 3.5/4.3
-
locate
Constructs an URI for given module resource.
Attention: Some implementations might yield an uri without verifying if the uri resource really exists.
- Parameters:
moduleName
- name of related time4j-modulemoduleRef
- module-specific class referencepath
- path to text resource- Returns:
- uri of resource or
null
if unable to locate the resource - Since:
- 3.5/4.3
-
load
Loads given URI-resource as input stream.
Callers are responsible for closing the result stream.
- Parameters:
uri
- uniform resource identifier as result of locate-method (optional)noCache
- avoid caching?- Returns:
- input stream or
null
if the resource could not be opened - Since:
- 3.5/4.3
- See Also:
locate(String, Class, String)
-
load
Loads a resource as input stream based on the classloader of given module reference.
Callers are responsible for closing the result stream.
- Parameters:
moduleRef
- module-specific class referencepath
- path to text resource (must be understandable by class loaders)noCache
- avoid caching?- Returns:
- input stream
- Throws:
IOException
- if the stream cannot be opened or if this method is called on Android platforms- Since:
- 3.16/4.13
-
services
Finds a collection of service providers available for given service provider interface.
- Type Parameters:
S
- generic service type- Parameters:
serviceInterface
- service provider interface- Returns:
- iterable collection of service providers
- Since:
- 3.5/4.3
-
registerService
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.- Type Parameters:
S
- generic service type- Parameters:
serviceInterface
- service interfaceimplementation
- service provider- Throws:
IllegalStateException
- if already registered or called on a non-standard resource loader like on Android- Since:
- 5.0
-