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
See Also:
  • 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.
    • services

      private static ServiceLoader<TypeRegistration> services()
      Returns the TypeRegistration instances. Must be invoked in a synchronized block.
    • load

      private static Class<?>[] load(boolean getTypes)
      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 the getTypes argument.

      Parameters:
      getTypes - whether to get the root classes to put in JAXB context (may cause class loading).
      Returns:
      if getTypes was true, the root classes to be bound in JAXBContext.
    • 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