Package org.apache.sis.xml
Class PooledMarshaller
java.lang.Object
org.apache.sis.xml.Pooled
org.apache.sis.xml.PooledMarshaller
- All Implemented Interfaces:
Marshaller
Wraps a
Marshaller
in order to have some control on the modifications applied on it.
This wrapper serves three purposes:
- Save properties before modification, in order to restore them to their original values when the marshaller is recycled.
- Constructs a SIS
Context
object on marshalling, in order to give additional information to the SIS object being marshalled. - Wraps the output stream in a
TransformingWriter
if the desired GML version in not the SIS native GML version.
- Since:
- 0.3
- Version:
- 1.0
-
Nested Class Summary
Nested classes/interfaces inherited from interface javax.xml.bind.Marshaller
Marshaller.Listener
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Marshaller
The wrapper marshaller which does the real work.private int
Bit masks specific to the object being marshalled.Fields inherited from class org.apache.sis.xml.Pooled
initialProperties, resetTime
Fields inherited from interface javax.xml.bind.Marshaller
JAXB_ENCODING, JAXB_FORMATTED_OUTPUT, JAXB_FRAGMENT, JAXB_NO_NAMESPACE_SCHEMA_LOCATION, JAXB_SCHEMA_LOCATION
-
Constructor Summary
ConstructorsConstructorDescriptionPooledMarshaller
(Marshaller marshaller, Pooled template) Creates a pooled marshaller wrapping the given one. -
Method Summary
Modifier and TypeMethodDescription<A extends XmlAdapter>
AgetAdapter
(Class<A> type) Delegates to the wrapped marshaller.Delegates to the wrapped marshaller.private String
Returns the encoding of the XML document to write.Delegates to the wrapped marshaller.Delegates to the wrapped marshaller.Delegates the marshalling to the wrapped marshaller.Delegates to the wrapped marshaller.(package private) Object
getStandardProperty
(String name) Delegates to the wrapped marshaller.void
Delegates the marshalling to the wrapped marshaller.void
marshal
(Object object, OutputStream output) Delegates the marshalling to the wrapped marshaller.void
Delegates the marshalling to the wrapped marshaller.void
marshal
(Object object, XMLEventWriter output) Delegates the marshalling to the wrapped marshaller.private void
marshal
(Object object, XMLEventWriter output, TransformVersion version) Marshals to the given output with on-the-fly substitution of namespaces.void
marshal
(Object object, XMLStreamWriter output) Delegates the marshalling to the wrapped marshaller.void
Delegates the marshalling to the wrapped marshaller.void
Delegates the marshalling to the wrapped marshaller.void
marshal
(Object object, ContentHandler output) Delegates the marshalling to the wrapped marshaller.protected void
Resets the given marshaller property to its initial state.<A extends XmlAdapter>
voidsetAdapter
(Class<A> type, A adapter) Delegates to the wrapped marshaller.void
Delegates to the wrapped marshaller.void
setEventHandler
(ValidationEventHandler handler) Delegates to the wrapped marshaller.void
setListener
(Marshaller.Listener listener) Delegates to the wrapped marshaller.void
Delegates to the wrapped marshaller.(package private) void
setStandardProperty
(String name, Object value) Delegates to the wrapped marshaller.(package private) final int
Returns a non-zero bitmask if the object given in last call totoImplementation(Object)
should use legacy metadata.private Object
toImplementation
(Object value) Converts the given arbitrary object to an implementation having JAXB annotations.Methods inherited from class org.apache.sis.xml.Pooled
begin, getProperty, getRootAdapters, getTransformVersion, initialize, isPropertySaved, reset, saveProperty, setAdapter, setProperty
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface javax.xml.bind.Marshaller
getProperty, setAdapter, setProperty
-
Field Details
-
marshaller
The wrapper marshaller which does the real work. -
specificBitMasks
private int specificBitMasksBit 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.
-
-
Constructor Details
-
PooledMarshaller
PooledMarshaller(Marshaller marshaller, Pooled template) throws JAXBException Creates a pooled marshaller wrapping the given one. Callers shall invokePooled.reset(Pooled)
after construction for completing the initialization.- Parameters:
marshaller
- the marshaller to use for the actual work.template
- thePooledTemplate
from which to get the initial values.- Throws:
JAXBException
- if an error occurred while setting a property.
-
-
Method Details
-
reset
Resets the given marshaller property to its initial state. This method is invoked automatically byPooled.reset(Pooled)
.- Specified by:
reset
in classPooled
- Parameters:
key
- the property to reset.value
- the saved initial value to give to the property.- Throws:
JAXBException
- if an error occurred while restoring a property.
-
getEncoding
Returns the encoding of the XML document to write.- Throws:
PropertyException
-
specificBitMasks
final int specificBitMasks()Returns a non-zero bitmask if the object given in last call totoImplementation(Object)
should use legacy metadata. This is a hack for marshalling metadata in GML. May be deleted if we implement SIS-401.- Overrides:
specificBitMasks
in classPooled
- See Also:
-
toImplementation
Converts the given arbitrary object to an implementation having JAXB annotations. If the given object is not recognized or is already an instance of the expected class, then it is returned unchanged. -
marshal
private void marshal(Object object, XMLEventWriter output, TransformVersion version) throws XMLStreamException, JAXBException Marshals to the given output with on-the-fly substitution of namespaces. This method is invoked when the user asked to marshal to a different GML or metadata version than the one supported natively by SIS, i.e. whenPooled.getTransformVersion()
returns a non-null value.- Parameters:
object
- the object to marshal.output
- the writer created by SIS (not the writer given by the user).version
- identifies the namespace substitutions to perform.- Throws:
XMLStreamException
JAXBException
-
marshal
Delegates the marshalling to the wrapped marshaller.- Specified by:
marshal
in interfaceMarshaller
- Throws:
JAXBException
-
marshal
Delegates the marshalling to the wrapped marshaller.- Specified by:
marshal
in interfaceMarshaller
- Throws:
JAXBException
-
marshal
Delegates the marshalling to the wrapped marshaller.- Specified by:
marshal
in interfaceMarshaller
- Throws:
JAXBException
-
marshal
Delegates the marshalling to the wrapped marshaller.- Specified by:
marshal
in interfaceMarshaller
- Throws:
JAXBException
-
marshal
Delegates the marshalling to the wrapped marshaller.- Specified by:
marshal
in interfaceMarshaller
- Throws:
JAXBException
-
marshal
Delegates the marshalling to the wrapped marshaller.- Specified by:
marshal
in interfaceMarshaller
- Throws:
JAXBException
-
marshal
Delegates the marshalling to the wrapped marshaller.- Specified by:
marshal
in interfaceMarshaller
- Throws:
JAXBException
-
marshal
Delegates the marshalling to the wrapped marshaller.- Specified by:
marshal
in interfaceMarshaller
- Throws:
JAXBException
-
getNode
Delegates the marshalling to the wrapped marshaller.- Specified by:
getNode
in interfaceMarshaller
- Throws:
JAXBException
-
setStandardProperty
Delegates to the wrapped marshaller. This method is invoked by the parent class if the given name was not one of theXML
constants.- Specified by:
setStandardProperty
in classPooled
- Throws:
PropertyException
-
getStandardProperty
Delegates to the wrapped marshaller. This method is invoked by the parent class if the given name was not one of theXML
constants.- Specified by:
getStandardProperty
in classPooled
- Throws:
PropertyException
-
setAdapter
Delegates to the wrapped marshaller. The initial state will be saved if it was not already done, for future restoration byPooled.reset(Pooled)
.- Specified by:
setAdapter
in interfaceMarshaller
- Overrides:
setAdapter
in classPooled
-
getAdapter
Delegates to the wrapped marshaller.- Specified by:
getAdapter
in interfaceMarshaller
- Specified by:
getAdapter
in classPooled
-
setSchema
Delegates to the wrapped marshaller. The initial state will be saved if it was not already done, for future restoration byPooled.reset(Pooled)
.- Specified by:
setSchema
in interfaceMarshaller
- Overrides:
setSchema
in classPooled
-
getSchema
Delegates to the wrapped marshaller.- Specified by:
getSchema
in interfaceMarshaller
- Specified by:
getSchema
in classPooled
-
setEventHandler
Delegates to the wrapped marshaller. The initial state will be saved if it was not already done, for future restoration byPooled.reset(Pooled)
.- Specified by:
setEventHandler
in interfaceMarshaller
- Overrides:
setEventHandler
in classPooled
- Throws:
JAXBException
-
getEventHandler
Delegates to the wrapped marshaller.- Specified by:
getEventHandler
in interfaceMarshaller
- Specified by:
getEventHandler
in classPooled
- Throws:
JAXBException
-
setAttachmentMarshaller
Delegates to the wrapped marshaller. The initial state will be saved if it was not already done, for future restoration byPooled.reset(Pooled)
.- Specified by:
setAttachmentMarshaller
in interfaceMarshaller
-
getAttachmentMarshaller
Delegates to the wrapped marshaller.- Specified by:
getAttachmentMarshaller
in interfaceMarshaller
-
setListener
Delegates to the wrapped marshaller. The initial state will be saved if it was not already done, for future restoration byPooled.reset(Pooled)
.- Specified by:
setListener
in interfaceMarshaller
-
getListener
Delegates to the wrapped marshaller.- Specified by:
getListener
in interfaceMarshaller
-