Class SystemRegistry
java.lang.Object
org.apache.sis.internal.converter.ConverterRegistry
org.apache.sis.internal.converter.SystemRegistry
The Apache SIS system-wide
ConverterRegistry
.
This class serves two purposes:
- Fetch the list of converters from the content of all
META-INF/services/org.apache.sis.util.ObjectConverter
files found on the classpath. The intent is to allow other modules to register their own converters. - Apply heuristic rules in addition to the explicitly registered converters.
Those heuristic rules are provided in a separated class in order to keep the
ConverterRegistry
class a little bit more "pure", and concentrate most arbitrary decisions in this single class.
SystemRegistry
, new converters may "automagically" appear as a consequence
of the above-cited heuristic rules. This differs from the ConverterRegistry
behavior,
where only registered converters are used.
Thread safety
The sameINSTANCE
can be safely used by many threads without synchronization on the part of the caller.- Since:
- 0.3
- Version:
- 0.8
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ConverterRegistry
The default system-wide instance. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Creates an initially empty set of object converters. -
Method Summary
Modifier and TypeMethodDescriptionprotected <S,
T> ObjectConverter<S, T> createConverter
(Class<S> sourceClass, Class<T> targetClass) Creates dynamically the converters for a few special cases.protected void
Invoked when thisConverterRegistry
needs to be initialized.private static boolean
isSupportedNumber
(Class<?> type) Returnstrue
if the given type is one of the types supported byNumberConverter
.private static boolean
tryInverse
(Class<?> targetClass) Returnstrue
if we should look for the inverse converter of the given target class.Methods inherited from class org.apache.sis.internal.converter.ConverterRegistry
clear, find, findEquals, findExact, register, toString
-
Field Details
-
INSTANCE
The default system-wide instance. This register is initialized with conversions between some basic Java and SIS objects, like conversions betweenDate
andLong
. Those conversions are defined for the lifetime of the JVM.If a temporary set of converters is desired, a new instance of
ConverterRegistry
should be created explicitly instead.See the package javadoc for information about how applications can add custom system-wide converters.
-
-
Constructor Details
-
SystemRegistry
private SystemRegistry()Creates an initially empty set of object converters. The heuristic rules apply right away, even if no converter have been registered yet.
-
-
Method Details
-
initialize
protected void initialize()Invoked when thisConverterRegistry
needs to be initialized. This method is automatically invoked the first time thatConverterRegistry.register(ObjectConverter)
orConverterRegistry.find(Class, Class)
is invoked.The default implementation is equivalent to the following code (see the package javadoc for more information):
- Overrides:
initialize
in classConverterRegistry
-
tryInverse
Returnstrue
if we should look for the inverse converter of the given target class. For example if no converter is explicitly registered fromFloat
toString
, we can look for the converter fromString
toFloat
, then fetch its inverse.We allow this operation only for a few types which are needed for the way SIS converters are defined in this internal package.
-
createConverter
Creates dynamically the converters for a few special cases. This method is invoked only the first time that a new pair of source and target classes is requested. Then, the value returned by this method will be cached for future invocations.Some (not all) special cases are:
- If the source class is
CharSequence
, tries to delegate to another converter acceptingString
sources. - If the source and target types are numbers, generates a
NumberConverter
on the fly. - If the target type is a code list, generate the converter on-the-fly. We do not register every code lists in advance because there is too many of them, and a generic code is available for all of them.
- Overrides:
createConverter
in classConverterRegistry
- Type Parameters:
S
- the source class.T
- the target class.- Parameters:
sourceClass
- the source class.targetClass
- the target class, orObject.class
for any.- Returns:
- a newly generated converter from the specified source class to the target class,
or
null
if none.
- If the source class is
-
isSupportedNumber
Returnstrue
if the given type is one of the types supported byNumberConverter
.
-