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, ornullif 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 StringUndocumented (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_ADAPTERSif not already present.static voidgetRenameFileLoader(boolean export, Set<Class<?>> addTo) Adds in the given set the classes to use for loading"RenameOnImport.lst"and/or"RenameOnExport.lst"files.static JAXBContextReturns the sharedJAXBContextfor the set of classes returned byload(boolean).protected abstract voidgetTypes(Collection<Class<?>> addTo) Adds to the given collection every types that should be given to the initial JAXB context.protected booleanhasRenameFile(boolean export) Returnstrueif"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 theTypeRegistrationinstances.
-
Field Details
-
ROOT_ADAPTERS
Undocumented (for now) marshaller property for specifying conversions to apply on root objects before marshalling. Conversions are applied byUnaryOperatorinstances.- See Also:
-
context
The JAXB context, ornullif 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 isnullif 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 becauseTypeRegistrationis 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 returnnullif the value class is not recognized, orvalueif the class is recognized but the value does not need to be changed. Implementations will typically perform aninstanceofcheck, then invoke one of thecastOrCopy(…)static methods defined in various Apache SIS classes.- Returns:
- converter for the value to marshal, or
nullif there are no values to convert. - Since:
- 0.8
-
hasRenameFile
protected boolean hasRenameFile(boolean export) Returnstrueif"RenameOnImport.lst"and/or"RenameOnExport.lst"files are provided. Iftrue, then those files shall be located in the same directory than thisTypeRegistrationsubclass.- Parameters:
export-truefor"RenameOnImport.lst",falsefor"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-truefor"RenameOnImport.lst",falsefor"RenameOnImport.lst".addTo- where to add the classes to use for loading the resource files.
-
services
Returns theTypeRegistrationinstances. 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 thegetTypesargument.- Parameters:
getTypes- whether to get the root classes to put in JAXB context (may cause class loading).- Returns:
- if
getTypeswastrue, the root classes to be bound inJAXBContext.
-
getPrivateInfo
Completes the given properties with an entry forROOT_ADAPTERSif not already present. If aROOT_ADAPTERSentry 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 theTypeRegistrationclass is not part of public API. However if we add this functionality in a future SIS release (probably as an interface rather than exposingTypeRegistrationitself), then we may consider removing this method.- Parameters:
properties- the properties to complete.- Returns:
- the given properties with the
ROOT_ADAPTERSentry added. - Since:
- 0.8
-