Package org.apache.sis.xml
Class Pooled
java.lang.Object
org.apache.sis.xml.Pooled
- Direct Known Subclasses:
PooledMarshaller
,PooledTemplate
,PooledUnmarshaller
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 Summary
FieldsModifier and TypeFieldDescriptionprivate int
Bit masks for various boolean attributes.private ValueConverter
The object converters to use during (un)marshalling.The initial state of the (un)marshaller.private final boolean
true
if the JAXB implementation is the one bundled in JDK 6, orfalse
if this is the external implementation provided as a JAR file in the endorsed directory.private Locale
An optional locale forInternationalString
andCodeList
.private Filter
The object to inform about warnings, ornull
if none.(package private) long
TheSystem.nanoTime()
value of the last call toreset(Pooled)
.private ReferenceResolver
The reference resolver to use during unmarshalling.private UnaryOperator<Object>[]
Converters from arbitrary classes implementing GeoAPI interfaces to Apache SIS implementations providing JAXB annotations, or null or an empty array if none.private static final String[]
The keys of entries that can be stored in theschemas
map.The base URL of ISO 19115-3 (or other standards) schemas.private TimeZone
The timezone, ornull
if unspecified.private Version
The GML version to be marshalled or unmarshalled, ornull
if unspecified.private Version
The metadata version to be marshalled or unmarshalled, ornull
if unspecified. -
Constructor Summary
ConstructorsConstructorDescriptionPooled
(boolean internal) Creates aPooledTemplate
.Creates aPooledMarshaller
orPooledUnmarshaller
. -
Method Summary
Modifier and TypeMethodDescription(package private) final Context
begin()
Must be invoked by subclasses before atry
block performing a (un)marshalling operation.abstract <A extends XmlAdapter>
AgetAdapter
(Class<A> type) A method which is common to bothMarshaller
andUnmarshaller
.abstract ValidationEventHandler
A method which is common to bothMarshaller
andUnmarshaller
.final Object
getProperty
(String name) A method which is common to bothMarshaller
andUnmarshaller
.(package private) final UnaryOperator<Object>[]
Returns the adapters to apply on the root object to marshal, ornull
or an empty array if none.abstract Schema
A method which is common to bothMarshaller
andUnmarshaller
.(package private) abstract Object
getStandardProperty
(String name) Gets the given property from the wrapped (un)marshaller.(package private) final TransformVersion
Returns theTransformVersion
enumeration value to use for the current GML or metadata version, ornull
if the SIS native versions are suitable.(package private) final void
initialize
(Pooled template) Completes the creation of aPooledMarshaller
orPooledUnmarshaller
.(package private) final boolean
isPropertySaved
(Class<?> key) Returnstrue
if the initial property is already saved for the given key.protected abstract void
Resets the given marshaller property to its initial state.final void
Releases resources and resets the (un)marshaller to its initial state.(package private) final <E> void
saveProperty
(Class<E> type, E value) Saves the current value of a property.<A extends XmlAdapter>
voidsetAdapter
(Class<A> type, A adapter) A method which is common to bothMarshaller
andUnmarshaller
.final void
setAdapter
(XmlAdapter adapter) Delegates tosetAdapter(adapter.getClass(), adapter)
as specified in[Un]Marshaller
javadoc.void
setEventHandler
(ValidationEventHandler handler) A method which is common to bothMarshaller
andUnmarshaller
.final void
setProperty
(String name, Object value) A method which is common to bothMarshaller
andUnmarshaller
.void
A method which is common to bothMarshaller
andUnmarshaller
.(package private) abstract void
setStandardProperty
(String name, Object value) Sets the given property to the wrapped (un)marshaller.(package private) int
Returns bit masks specific to the object being marshalled.
-
Field Details
-
SCHEMA_KEYS
The keys of entries that can be stored in theschemas
map. Those keys are documented inXML.SCHEMAS
. -
internal
private final boolean internaltrue
if the JAXB implementation is the one bundled in JDK 6, orfalse
if this is the external implementation provided as a JAR file in the endorsed directory. Iftrue
, then an additional"internal"
package name needs to be inserted in the property keys.- See Also:
-
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 amarshaller.setFoo(value)
method. - For each entry having a key of type
String
, the value is the argument to be given to themarshaller.setProperty(key, value)
method.
null
. - For each entry having a key of type
-
bitMasks
private int bitMasksBit 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 theXML.STRING_SUBSTITUTES
property. -
locale
-
timezone
The timezone, ornull
if unspecified. Can be set by theXML.TIMEZONE
property. -
schemas
The base URL of ISO 19115-3 (or other standards) schemas. It shall be an unmodifiable instance becausegetProperty(String)
returns a direct reference to the user. The valid values are documented in theXML.SCHEMAS
property. -
versionGML
The GML version to be marshalled or unmarshalled, ornull
if unspecified. If null, then the latest version is assumed.- See Also:
-
versionMetadata
The metadata version to be marshalled or unmarshalled, ornull
if unspecified. If null, then the latest version is assumed.- See Also:
-
resolver
The reference resolver to use during unmarshalling. Can be set by theXML.RESOLVER
property. -
converter
The object converters to use during (un)marshalling. Can be set by theXML.CONVERTER
property. -
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
The object to inform about warnings, ornull
if none. -
resetTime
volatile long resetTimeTheSystem.nanoTime()
value of the last call toreset(Pooled)
. This is used for disposing (un)marshallers that have not been used for a while, sincereset()
is invoked just before to push a (un)marshaller in the pool.
-
-
Constructor Details
-
Pooled
Pooled(boolean internal) Creates aPooledTemplate
.- Parameters:
internal
-true
if the JAXB implementation is the one bundled in JDK 6, orfalse
if this is the external implementation provided as a JAR file in the endorsed directory.
-
Pooled
Pooled(Pooled template) Creates aPooledMarshaller
orPooledUnmarshaller
. Theinitialize(Pooled)
method must be invoked after this constructor for completing the initialization.- Parameters:
template
- thePooledTemplate
from which to get the initial values.
-
-
Method Details
-
initialize
Completes the creation of aPooledMarshaller
orPooledUnmarshaller
. This method is not invoked in thePooled(Pooled)
constructor in order to give to subclasses a chance to complete their construction first.- Parameters:
template
- thePooledTemplate
from which to get the initial values.- Throws:
JAXBException
- if an error occurred while setting a property.
-
reset
Releases resources and resets the (un)marshaller to its initial state. This method is invoked byMarshallerPool
just before to push a (un)marshaller in the pool after its usage.- Parameters:
template
- thePooledTemplate
from which to get the initial values.- Throws:
JAXBException
- if an error occurred while restoring a property.
-
reset
Resets the given marshaller property to its initial state. This method is invoked automatically by thereset(Pooled)
method. The key is either aString
or aClass
. If this is a string, then the value shall be given to thesetProperty(key, value)
method. Otherwise the value shall be given tosetFoo(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
Returns theTransformVersion
enumeration value to use for the current GML or metadata version, ornull
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 aTransformingWriter
in order to replace the namespace of versions implemented by SIS by the namespace of versions requested by the user.- See Also:
-
isPropertySaved
Returnstrue
if the initial property is already saved for the given key. Note that a property set tonull
is still considered as defined. -
saveProperty
Saves the current value of a property. This method is invoked before a value is modified for the first time, in order to allowreset(Pooled)
to restore the (un)marshaller to its initial state.- Parameters:
type
- the property to save.value
- the current value of the property.
-
setProperty
A method which is common to bothMarshaller
andUnmarshaller
. It saves the initial state if it was not already done, but subclasses will need to complete the work.- Throws:
PropertyException
-
getProperty
A method which is common to bothMarshaller
andUnmarshaller
.- Throws:
PropertyException
-
setStandardProperty
Sets the given property to the wrapped (un)marshaller. This method is invoked automatically when the property given to thesetProperty(String, Object)
method was not one of theXML
constants.- Throws:
PropertyException
-
getStandardProperty
Gets the given property from the wrapped (un)marshaller. This method is invoked automatically when the property key given to thegetProperty(String)
method was not one of theXML
constants.- Throws:
PropertyException
-
setAdapter
Delegates tosetAdapter(adapter.getClass(), adapter)
as specified in[Un]Marshaller
javadoc. -
setAdapter
A method which is common to bothMarshaller
andUnmarshaller
. It saves the initial state if it was not already done, but subclasses will need to complete the work. -
getAdapter
A method which is common to bothMarshaller
andUnmarshaller
. -
getRootAdapters
Returns the adapters to apply on the root object to marshal, ornull
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
A method which is common to bothMarshaller
andUnmarshaller
. It saves the initial state if it was not already done, but subclasses will need to complete the work. -
getSchema
A method which is common to bothMarshaller
andUnmarshaller
. -
setEventHandler
A method which is common to bothMarshaller
andUnmarshaller
. It saves the initial state if it was not already done, but subclasses will need to complete the work.- Throws:
JAXBException
-
getEventHandler
A method which is common to bothMarshaller
andUnmarshaller
.- 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 thePooled
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
Must be invoked by subclasses before atry
block performing a (un)marshalling operation. Must be followed by a call tofinish()
in afinally
block.- See Also:
-