Class TypeRegistration

java.lang.Object
org.apache.sis.internal.jaxb.TypeRegistration
Direct Known Subclasses:
MetadataTypes, ProfileTypes, ReferencingTypes

public abstract class TypeRegistration extends Object
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
Author:
Martin Desruisseaux (Geomatys)
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Undocumented (for now) marshaller property for specifying conversions to apply on root objects before marshalling.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    For subclasses constructors.
  • Method Summary

    Modifier and Type
    Method
    Description
    If some objects need to be converted before marshalling, the converter for performing those conversions.
    static Map<String,?>
    getPrivateInfo(Map<String,?> properties)
    Completes the given properties with an entry for ROOT_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.
    Returns the shared JAXBContext for the set of classes returned by load(boolean).
    protected abstract void
    Adds to the given collection every types that should be given to the initial JAXB context.
    protected boolean
    hasRenameFile(boolean export)
    Returns true if "RenameOnImport.lst" and/or "RenameOnExport.lst" files are provided.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • TypeRegistration

      protected TypeRegistration()
      For subclasses constructors.
  • Method Details

    • getTypes

      protected abstract void getTypes(Collection<Class<?>> addTo)
      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 the beforeMarshal() method should be overridden.
      Parameters:
      addTo - the collection in which to add new types.
    • beforeMarshal

      protected UnaryOperator<Object> beforeMarshal()
      If some objects need to be converted before marshalling, the converter for performing those conversions. The converter apply(Object) method may return null if the value class is not recognized, or value if the class is recognized but the value does not need to be changed. Implementations will typically perform an instanceof check, then invoke one of the castOrCopy(…) 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)
      Returns true if "RenameOnImport.lst" and/or "RenameOnExport.lst" files are provided. If true, then those files shall be located in the same directory than this TypeRegistration subclass.
      Parameters:
      export -  true for "RenameOnImport.lst", false for "RenameOnImport.lst".
      Returns:
      whether "RenameOnImport.lst" and/or "RenameOnExport.lst" files are provided.
    • getRenameFileLoader

      public 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. 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.
    • getSharedContext

      public static JAXBContext getSharedContext() throws JAXBException
      Returns the shared JAXBContext for the set of classes returned by load(boolean). Note that the JAXBContext class is thread safe, but the Marshaller, Unmarshaller, and Validator classes are not thread safe.
      Returns:
      the shared JAXB context.
      Throws:
      JAXBException - if an error occurred while creating the JAXB context.
    • getPrivateInfo

      public static Map<String,?> getPrivateInfo(Map<String,?> properties)
      Completes the given properties with an entry for ROOT_ADAPTERS if not already present. If a ROOT_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 the TypeRegistration class is not part of public API. However if we add this functionality in a future SIS release (probably as an interface rather than exposing TypeRegistration 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