Class Pooled

java.lang.Object
org.apache.sis.xml.Pooled
Direct Known Subclasses:
PooledMarshaller, PooledTemplate, PooledUnmarshaller

abstract class Pooled extends Object
Base class of PooledMarshaller and PooledUnmarshaller. This class provides basic service for saving the initial values of (un)marshaller properties, in order to reset them to their initial values after usage. This is required in order to allow (un)marshaller reuse. In addition this base class translates properties key from JDK 6 names to "endorsed JAR" names if needed.
Since:
0.3
Version:
1.1
  • Field Details

    • SCHEMA_KEYS

      private static final String[] SCHEMA_KEYS
      The keys of entries that can be stored in the schemas map. Those keys are documented in XML.SCHEMAS.
    • internal

      private final boolean internal
      true if the JAXB implementation is the one bundled in JDK 6, or false if this is the external implementation provided as a JAR file in the endorsed directory. If true, then an additional "internal" package name needs to be inserted in the property keys.
      See Also:
    • initialProperties

      final Map<Object,Object> initialProperties
      The initial state of the (un)marshaller. Will be filled only as needed, often with null values (which must be supported by the map implementation).
      • For each entry having a key of type Class, the value is the argument to be given to a marshaller.setFoo(value) method.
      • For each entry having a key of type String, the value is the argument to be given to the marshaller.setProperty(key, value) method.
      This map is never null.
    • bitMasks

      private int bitMasks
      Bit masks for various boolean attributes. This include whatever the language codes or the country codes should be substituted by a simpler character string elements. Those bits are determined by the XML.STRING_SUBSTITUTES property.
    • locale

      private Locale locale
      An optional locale for InternationalString and CodeList. Can be set by the XML.LOCALE property.
    • timezone

      private TimeZone timezone
      The timezone, or null if unspecified. Can be set by the XML.TIMEZONE property.
    • schemas

      private Map<String,String> schemas
      The base URL of ISO 19115-3 (or other standards) schemas. It shall be an unmodifiable instance because getProperty(String) returns a direct reference to the user. The valid values are documented in the XML.SCHEMAS property.
    • versionGML

      private Version versionGML
      The GML version to be marshalled or unmarshalled, or null if unspecified. If null, then the latest version is assumed.
      See Also:
    • versionMetadata

      private Version versionMetadata
      The metadata version to be marshalled or unmarshalled, or null if unspecified. If null, then the latest version is assumed.
      See Also:
    • resolver

      private ReferenceResolver resolver
      The reference resolver to use during unmarshalling. Can be set by the XML.RESOLVER property.
    • converter

      private ValueConverter converter
      The object converters to use during (un)marshalling. Can be set by the XML.CONVERTER property.
    • rootAdapters

      private UnaryOperator<Object>[] rootAdapters
      Converters from arbitrary classes implementing GeoAPI interfaces to Apache SIS implementations providing JAXB annotations, or null or an empty array if none. This is used at marshalling time.
      See Also:
    • logFilter

      private Filter logFilter
      The object to inform about warnings, or null if none.
    • resetTime

      volatile long resetTime
      The System.nanoTime() value of the last call to reset(Pooled). This is used for disposing (un)marshallers that have not been used for a while, since reset() is invoked just before to push a (un)marshaller in the pool.
  • Constructor Details

    • Pooled

      Pooled(boolean internal)
      Creates a PooledTemplate.
      Parameters:
      internal - true if the JAXB implementation is the one bundled in JDK 6, or false if this is the external implementation provided as a JAR file in the endorsed directory.
    • Pooled

      Pooled(Pooled template)
      Creates a PooledMarshaller or PooledUnmarshaller. The initialize(Pooled) method must be invoked after this constructor for completing the initialization.
      Parameters:
      template - the PooledTemplate from which to get the initial values.
  • Method Details

    • initialize

      final void initialize(Pooled template) throws JAXBException
      Completes the creation of a PooledMarshaller or PooledUnmarshaller. This method is not invoked in the Pooled(Pooled) constructor in order to give to subclasses a chance to complete their construction first.
      Parameters:
      template - the PooledTemplate from which to get the initial values.
      Throws:
      JAXBException - if an error occurred while setting a property.
    • reset

      public final void reset(Pooled template) throws JAXBException
      Releases resources and resets the (un)marshaller to its initial state. This method is invoked by MarshallerPool just before to push a (un)marshaller in the pool after its usage.
      Parameters:
      template - the PooledTemplate from which to get the initial values.
      Throws:
      JAXBException - if an error occurred while restoring a property.
    • reset

      protected abstract void reset(Object key, Object value) throws JAXBException
      Resets the given marshaller property to its initial state. This method is invoked automatically by the reset(Pooled) method. The key is either a String or a Class. If this is a string, then the value shall be given to the setProperty(key, value) method. Otherwise the value shall be given to setFoo(value) method where "Foo" is determined from the key.
      Parameters:
      key - the property to reset.
      value - the initial value to give to the property.
      Throws:
      JAXBException - if an error occurred while restoring a property.
    • getTransformVersion

      final TransformVersion getTransformVersion()
      Returns the TransformVersion enumeration value to use for the current GML or metadata version, or null if the SIS native versions are suitable. If this method returns a non-null value, then the output generated by JAXB will need to go through a TransformingWriter in order to replace the namespace of versions implemented by SIS by the namespace of versions requested by the user.
      See Also:
    • isPropertySaved

      final boolean isPropertySaved(Class<?> key)
      Returns true if the initial property is already saved for the given key. Note that a property set to null is still considered as defined.
    • saveProperty

      final <E> void saveProperty(Class<E> type, E value)
      Saves the current value of a property. This method is invoked before a value is modified for the first time, in order to allow reset(Pooled) to restore the (un)marshaller to its initial state.
      Parameters:
      type - the property to save.
      value - the current value of the property.
    • setProperty

      public final void setProperty(String name, Object value) throws PropertyException
      A method which is common to both Marshaller and Unmarshaller. It saves the initial state if it was not already done, but subclasses will need to complete the work.
      Throws:
      PropertyException
    • getProperty

      public final Object getProperty(String name) throws PropertyException
      A method which is common to both Marshaller and Unmarshaller.
      Throws:
      PropertyException
    • setStandardProperty

      abstract void setStandardProperty(String name, Object value) throws PropertyException
      Sets the given property to the wrapped (un)marshaller. This method is invoked automatically when the property given to the setProperty(String, Object) method was not one of the XML constants.
      Throws:
      PropertyException
    • getStandardProperty

      abstract Object getStandardProperty(String name) throws PropertyException
      Gets the given property from the wrapped (un)marshaller. This method is invoked automatically when the property key given to the getProperty(String) method was not one of the XML constants.
      Throws:
      PropertyException
    • setAdapter

      public final void setAdapter(XmlAdapter adapter)
      Delegates to setAdapter(adapter.getClass(), adapter) as specified in [Un]Marshaller javadoc.
    • setAdapter

      public <A extends XmlAdapter> void setAdapter(Class<A> type, A adapter)
      A method which is common to both Marshaller and Unmarshaller. It saves the initial state if it was not already done, but subclasses will need to complete the work.
    • getAdapter

      public abstract <A extends XmlAdapter> A getAdapter(Class<A> type)
      A method which is common to both Marshaller and Unmarshaller.
    • getRootAdapters

      final UnaryOperator<Object>[] getRootAdapters()
      Returns the adapters to apply on the root object to marshal, or null or an empty array if none. This is used for converting from arbitrary implementations of GeoAPI interfaces to Apache SIS implementations providing JAXB annotations.
      Returns:
      a direct reference to the internal array of converters - do not modify.
    • setSchema

      public void setSchema(Schema schema)
      A method which is common to both Marshaller and Unmarshaller. It saves the initial state if it was not already done, but subclasses will need to complete the work.
    • getSchema

      public abstract Schema getSchema()
      A method which is common to both Marshaller and Unmarshaller.
    • setEventHandler

      public void setEventHandler(ValidationEventHandler handler) throws JAXBException
      A method which is common to both Marshaller and Unmarshaller. It saves the initial state if it was not already done, but subclasses will need to complete the work.
      Throws:
      JAXBException
    • getEventHandler

      public abstract ValidationEventHandler getEventHandler() throws JAXBException
      A method which is common to both Marshaller and Unmarshaller.
      Throws:
      JAXBException
    • specificBitMasks

      int specificBitMasks()
      Returns bit masks specific to the object being marshalled. This mask will be combined with the bit masks managed by the Pooled base class. This is used mostly for mandating legacy metadata format (ISO 19139:2007) for some object to marshal.

      This is a hopefully temporary hack for marshalling metadata in GML. May be deleted if we implement SIS-401.

      See Also:
    • begin

      final Context begin()
      Must be invoked by subclasses before a try block performing a (un)marshalling operation. Must be followed by a call to finish() in a finally block.
      See Also: