Package org.apache.sis.internal.jaxb
Class TypeRegistration
java.lang.Object
org.apache.sis.internal.jaxb.TypeRegistration
- Direct Known Subclasses:
MetadataTypes
,ProfileTypes
,ReferencingTypes
Declares the classes of objects to be marshalled using a default
MarshallerPool
.
This class is not strictly necessary for marshalling a SIS object using JAXB, but makes
the job easier by allowing MarshallerPool
to configure the JAXB context automatically.
To allow such automatic configuration, modules must declare instances of this interface in the
following file:
- Since:
- 0.3
- Version:
- 1.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static Reference<JAXBContext>
The JAXB context, ornull
if not yet created or if the classpath changed.private static UnaryOperator<Object>[]
Converters to apply before to marshal an object, or an empty array if none.static final String
Undocumented (for now) marshaller property for specifying conversions to apply on root objects before marshalling.private static ServiceLoader<TypeRegistration>
The registrations, cached only a few seconds. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected UnaryOperator<Object>
If some objects need to be converted before marshalling, the converter for performing those conversions.getPrivateInfo
(Map<String, ?> properties) Completes the given properties with an entry forROOT_ADAPTERS
if not already present.static void
getRenameFileLoader
(boolean export, Set<Class<?>> addTo) Adds in the given set the classes to use for loading"RenameOnImport.lst"
and/or"RenameOnExport.lst"
files.static JAXBContext
Returns the sharedJAXBContext
for the set of classes returned byload(boolean)
.protected abstract void
getTypes
(Collection<Class<?>> addTo) Adds to the given collection every types that should be given to the initial JAXB context.protected boolean
hasRenameFile
(boolean export) Returnstrue
if"RenameOnImport.lst"
and/or"RenameOnExport.lst"
files are provided.private static Class<?>[]
load
(boolean getTypes) Scans the classpath for root classes to put in JAXB context and for converters to those classes.private static ServiceLoader<TypeRegistration>
services()
Returns theTypeRegistration
instances.
-
Field Details
-
ROOT_ADAPTERS
Undocumented (for now) marshaller property for specifying conversions to apply on root objects before marshalling. Conversions are applied byUnaryOperator
instances.- See Also:
-
context
The JAXB context, ornull
if not yet created or if the classpath changed.- See Also:
-
converters
Converters to apply before to marshal an object, or an empty array if none. This isnull
if not yet initialized or if classpath changed.- See Also:
-
services
The registrations, cached only a few seconds. We do not need to keep them a long time becauseTypeRegistration
is used only for initializing some classes or fields.- See Also:
-
-
Constructor Details
-
TypeRegistration
protected TypeRegistration()For subclasses constructors.
-
-
Method Details
-
getTypes
Adds to the given collection every types that should be given to the initial JAXB context. The types added by this method include only implementation classes having JAXB annotations. If the module can also marshal arbitrary implementations of some interfaces (e.g. GeoAPI), then thebeforeMarshal()
method should be overridden.- Parameters:
addTo
- the collection in which to add new types.
-
beforeMarshal
If some objects need to be converted before marshalling, the converter for performing those conversions. The converterapply(Object)
method may returnnull
if the value class is not recognized, orvalue
if the class is recognized but the value does not need to be changed. Implementations will typically perform aninstanceof
check, then invoke one of thecastOrCopy(…)
static methods defined in various Apache SIS classes.- Returns:
- converter for the value to marshal, or
null
if there are no values to convert. - Since:
- 0.8
-
hasRenameFile
protected boolean hasRenameFile(boolean export) Returnstrue
if"RenameOnImport.lst"
and/or"RenameOnExport.lst"
files are provided. Iftrue
, then those files shall be located in the same directory than thisTypeRegistration
subclass.- Parameters:
export
-true
for"RenameOnImport.lst"
,false
for"RenameOnImport.lst"
.- Returns:
- whether
"RenameOnImport.lst"
and/or"RenameOnExport.lst"
files are provided.
-
getRenameFileLoader
Adds in the given set the classes to use for loading"RenameOnImport.lst"
and/or"RenameOnExport.lst"
files. The given set should preserve insertion order, since the order in which files are loaded may matter.- Parameters:
export
-true
for"RenameOnImport.lst"
,false
for"RenameOnImport.lst"
.addTo
- where to add the classes to use for loading the resource files.
-
services
Returns theTypeRegistration
instances. Must be invoked in a synchronized block. -
load
Scans the classpath for root classes to put in JAXB context and for converters to those classes. Those lists are determined dynamically from the SIS modules found on the classpath. This method does nothing if this class already has all required information.The list of converters is cached (that result is stored in
converters
) while the list of root classes in JAXB context is not cached. So the information about whether this method needs to fetch the list of root classes or not must be specified by thegetTypes
argument.- Parameters:
getTypes
- whether to get the root classes to put in JAXB context (may cause class loading).- Returns:
- if
getTypes
wastrue
, the root classes to be bound inJAXBContext
.
-
getPrivateInfo
Completes the given properties with an entry forROOT_ADAPTERS
if not already present. If aROOT_ADAPTERS
entry is already present, then the map is returned unchanged.This method stores a reference to the internal
TypeRegistration[]
array in a copy of the given map. That array shall not be modified. This method is currently for Apache SIS internal usage only, because theTypeRegistration
class is not part of public API. However if we add this functionality in a future SIS release (probably as an interface rather than exposingTypeRegistration
itself), then we may consider removing this method.- Parameters:
properties
- the properties to complete.- Returns:
- the given properties with the
ROOT_ADAPTERS
entry added. - Since:
- 0.8
-