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.ObjectConverterfiles 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
ConverterRegistryclass 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 ConverterRegistryThe default system-wide instance. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateCreates 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 voidInvoked when thisConverterRegistryneeds to be initialized.private static booleanisSupportedNumber(Class<?> type) Returnstrueif the given type is one of the types supported byNumberConverter.private static booleantryInverse(Class<?> targetClass) Returnstrueif 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 betweenDateandLong. Those conversions are defined for the lifetime of the JVM.If a temporary set of converters is desired, a new instance of
ConverterRegistryshould 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 thisConverterRegistryneeds 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:
initializein classConverterRegistry
-
tryInverse
Returnstrueif we should look for the inverse converter of the given target class. For example if no converter is explicitly registered fromFloattoString, we can look for the converter fromStringtoFloat, 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 acceptingStringsources. - If the source and target types are numbers, generates a
NumberConverteron 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:
createConverterin classConverterRegistry- Type Parameters:
S- the source class.T- the target class.- Parameters:
sourceClass- the source class.targetClass- the target class, orObject.classfor any.- Returns:
- a newly generated converter from the specified source class to the target class,
or
nullif none.
- If the source class is
-
isSupportedNumber
Returnstrueif the given type is one of the types supported byNumberConverter.
-