public abstract class AbstractContext extends java.lang.Object implements Context
A skeletal implementation of the
Context interface to minimize
the effort required to implement this interface.
The full set of
Context interface, used by these methods, is loaded once
when they are needed for these methods for the first time.
Though a documented tool for loading service providers was added since Java 1.6,
this technique works in earlier Java versions also.
If some exception occurs while loading the set of service providers
(for example, if some of the service providers, listed in
have no public constructors without arguments), this fact is logged via
standard java.util.logging tools
with the SEVERE level.
The following logger is used for this purpose:
In this case, the execution of the called
is(Class) method is not interrupted,
but some (or all) service providers may be ignored in this and futher requests.
|Modifier and Type||Field and Description|
The value of the corresponding argument of the
|Modifier||Constructor and Description|
Creates a new instance of this class.
|Modifier and Type||Method and Description|
This implementation returns, when possible, the reference to this instance or to the service provider implementing the required class.
Returns true if this context class can be processed by
protected final boolean useServiceLoader
protected AbstractContext(boolean useServiceLoader)
public <T extends Context> T as(java.lang.Class<T> contextClass)
Contextinterface (not for the passed contextClass!), listed in META-INF/services/net.algart.contexts.Context file, which implements (extends) the required interface (class) contextClass, then an instance of this service provider is returned;
The 2nd check is performed only if the useServiceLoader argument, passed to the constructor, was true. If it was false, the service providers are not loaded and not checked.
contextClass- the class of returned object (or superclass, or implemented interface).
Contextinterface that implements (extends) required contextClass.
java.lang.NullPointerException- if contextClass is null.
java.lang.IllegalArgumentException- if contextClass does not extends or implements
UnsupportedContextException- if this context cannot serve the request.
public boolean is(java.lang.Class<? extends Context> contextClass)
as(Class)method. More precisely:
Contextinterface, this method returns false;
Contextinterface (not for the passed contextClass!), listed in META-INF/services/net.algart.contexts.Context file, which implements (extends) the required interface (class) contextClass, then this method returns true;
The 3rd check is performed only if the useServiceLoader argument, passed to the constructor, was true. If it was false, the service providers are not loaded and not checked.