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 intBit masks for various boolean attributes.private ValueConverterThe object converters to use during (un)marshalling.The initial state of the (un)marshaller.private final booleantrueif the JAXB implementation is the one bundled in JDK 6, orfalseif this is the external implementation provided as a JAR file in the endorsed directory.private LocaleAn optional locale forInternationalStringandCodeList.private FilterThe object to inform about warnings, ornullif none.(package private) longTheSystem.nanoTime()value of the last call toreset(Pooled).private ReferenceResolverThe 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 theschemasmap.The base URL of ISO 19115-3 (or other standards) schemas.private TimeZoneThe timezone, ornullif unspecified.private VersionThe GML version to be marshalled or unmarshalled, ornullif unspecified.private VersionThe metadata version to be marshalled or unmarshalled, ornullif unspecified. -
Constructor Summary
ConstructorsConstructorDescriptionPooled(boolean internal) Creates aPooledTemplate.Creates aPooledMarshallerorPooledUnmarshaller. -
Method Summary
Modifier and TypeMethodDescription(package private) final Contextbegin()Must be invoked by subclasses before atryblock performing a (un)marshalling operation.abstract <A extends XmlAdapter>
AgetAdapter(Class<A> type) A method which is common to bothMarshallerandUnmarshaller.abstract ValidationEventHandlerA method which is common to bothMarshallerandUnmarshaller.final ObjectgetProperty(String name) A method which is common to bothMarshallerandUnmarshaller.(package private) final UnaryOperator<Object>[]Returns the adapters to apply on the root object to marshal, ornullor an empty array if none.abstract SchemaA method which is common to bothMarshallerandUnmarshaller.(package private) abstract ObjectgetStandardProperty(String name) Gets the given property from the wrapped (un)marshaller.(package private) final TransformVersionReturns theTransformVersionenumeration value to use for the current GML or metadata version, ornullif the SIS native versions are suitable.(package private) final voidinitialize(Pooled template) Completes the creation of aPooledMarshallerorPooledUnmarshaller.(package private) final booleanisPropertySaved(Class<?> key) Returnstrueif the initial property is already saved for the given key.protected abstract voidResets the given marshaller property to its initial state.final voidReleases resources and resets the (un)marshaller to its initial state.(package private) final <E> voidsaveProperty(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 bothMarshallerandUnmarshaller.final voidsetAdapter(XmlAdapter adapter) Delegates tosetAdapter(adapter.getClass(), adapter)as specified in[Un]Marshallerjavadoc.voidsetEventHandler(ValidationEventHandler handler) A method which is common to bothMarshallerandUnmarshaller.final voidsetProperty(String name, Object value) A method which is common to bothMarshallerandUnmarshaller.voidA method which is common to bothMarshallerandUnmarshaller.(package private) abstract voidsetStandardProperty(String name, Object value) Sets the given property to the wrapped (un)marshaller.(package private) intReturns bit masks specific to the object being marshalled.
-
Field Details
-
SCHEMA_KEYS
The keys of entries that can be stored in theschemasmap. Those keys are documented inXML.SCHEMAS. -
internal
private final boolean internaltrueif the JAXB implementation is the one bundled in JDK 6, orfalseif 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_SUBSTITUTESproperty. -
locale
-
timezone
The timezone, ornullif unspecified. Can be set by theXML.TIMEZONEproperty. -
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.SCHEMASproperty. -
versionGML
The GML version to be marshalled or unmarshalled, ornullif unspecified. If null, then the latest version is assumed.- See Also:
-
versionMetadata
The metadata version to be marshalled or unmarshalled, ornullif unspecified. If null, then the latest version is assumed.- See Also:
-
resolver
The reference resolver to use during unmarshalling. Can be set by theXML.RESOLVERproperty. -
converter
The object converters to use during (un)marshalling. Can be set by theXML.CONVERTERproperty. -
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, ornullif 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-trueif the JAXB implementation is the one bundled in JDK 6, orfalseif this is the external implementation provided as a JAR file in the endorsed directory.
-
Pooled
Pooled(Pooled template) Creates aPooledMarshallerorPooledUnmarshaller. Theinitialize(Pooled)method must be invoked after this constructor for completing the initialization.- Parameters:
template- thePooledTemplatefrom which to get the initial values.
-
-
Method Details
-
initialize
Completes the creation of aPooledMarshallerorPooledUnmarshaller. This method is not invoked in thePooled(Pooled)constructor in order to give to subclasses a chance to complete their construction first.- Parameters:
template- thePooledTemplatefrom 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 byMarshallerPooljust before to push a (un)marshaller in the pool after its usage.- Parameters:
template- thePooledTemplatefrom 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 aStringor 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 theTransformVersionenumeration value to use for the current GML or metadata version, ornullif 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 aTransformingWriterin order to replace the namespace of versions implemented by SIS by the namespace of versions requested by the user.- See Also:
-
isPropertySaved
Returnstrueif the initial property is already saved for the given key. Note that a property set tonullis 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 bothMarshallerandUnmarshaller. 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 bothMarshallerandUnmarshaller.- 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 theXMLconstants.- 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 theXMLconstants.- Throws:
PropertyException
-
setAdapter
Delegates tosetAdapter(adapter.getClass(), adapter)as specified in[Un]Marshallerjavadoc. -
setAdapter
A method which is common to bothMarshallerandUnmarshaller. 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 bothMarshallerandUnmarshaller. -
getRootAdapters
Returns the adapters to apply on the root object to marshal, ornullor 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 bothMarshallerandUnmarshaller. 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 bothMarshallerandUnmarshaller. -
setEventHandler
A method which is common to bothMarshallerandUnmarshaller. 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 bothMarshallerandUnmarshaller.- 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 thePooledbase 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 atryblock performing a (un)marshalling operation. Must be followed by a call tofinish()in afinallyblock.- See Also:
-