public class MarshallerPool extends Object
Marshaller
or Unmarshaller
objects for use with SIS.
Users fetch (un)marshallers by calls to the acquireMarshaller()
or
acquireUnmarshaller()
methods, and can restitute the (un)marshaller to the pool
after usage like below:
Marshaller marshaller = pool.acquireMarshaller(); marshaller.marchall(...); pool.recycle(marshaller);
XML
class, in addition to JAXB standard properties.
MarshallerPool
instance can be safely used by many threads without synchronization
on the part of the caller. Subclasses should make sure that any overridden methods remain safe to call
from multiple threads.XML
,
JAXB Performance and thread-safetyDefined in the sis-utility
module
Modifier and Type | Field and Description |
---|---|
protected JAXBContext |
context
The JAXB context to use for creating marshaller and unmarshaller.
|
Constructor and Description |
---|
MarshallerPool(JAXBContext context,
Map<String,?> properties)
Creates a new factory using the given JAXB context.
|
MarshallerPool(Map<String,?> properties)
Creates a new factory using the SIS default
JAXBContext instance. |
Modifier and Type | Method and Description |
---|---|
Marshaller |
acquireMarshaller()
Returns a JAXB marshaller from the pool.
|
Unmarshaller |
acquireUnmarshaller()
Returns a JAXB unmarshaller from the pool.
|
protected Marshaller |
createMarshaller()
Creates an configures a new JAXB marshaller.
|
protected Unmarshaller |
createUnmarshaller()
Creates an configures a new JAXB unmarshaller.
|
void |
recycle(Marshaller marshaller)
Declares a marshaller as available for reuse.
|
void |
recycle(Unmarshaller unmarshaller)
Declares a unmarshaller as available for reuse.
|
protected final JAXBContext context
createMarshaller()
,
createUnmarshaller()
public MarshallerPool(Map<String,?> properties) throws JAXBException
JAXBContext
instance.
The properties
map is optional. If non-null, then the keys can be XML
constants or the
names of any other properties recognized by both Marshaller
and Unmarshaller
implementations.
Tip: if the properties for the Marshaller
differ from the properties
for the Unmarshaller
, then consider overriding the createMarshaller()
or createUnmarshaller()
methods instead.
properties
- the properties to be given to the (un)marshaller, or null
if none.JAXBException
- if the JAXB context can not be created.public MarshallerPool(JAXBContext context, Map<String,?> properties) throws JAXBException
properties
map is optional. If non-null, then the keys can be XML
constants or the
names of any other properties recognized by both Marshaller
and Unmarshaller
implementations.
Tip: if the properties for the Marshaller
differ from the properties
for the Unmarshaller
, then consider overriding the createMarshaller()
or createUnmarshaller()
methods instead.
context
- the JAXB context.properties
- the properties to be given to the (un)marshaller, or null
if none.JAXBException
- if the marshaller pool can not be created.public Marshaller acquireMarshaller() throws JAXBException
This method shall be used as below:
Marshaller marshaller = pool.acquireMarshaller(); marshaller.marchall(...); pool.recycle(marshaller);Note that
recycle(Marshaller)
shall not be invoked in case of exception,
since the marshaller may be in an invalid state.JAXBException
- if an error occurred while creating and configuring a marshaller.public Unmarshaller acquireUnmarshaller() throws JAXBException
This method shall be used as below:
Unmarshaller unmarshaller = pool.acquireUnmarshaller(); Unmarshaller.unmarchall(...); pool.recycle(unmarshaller);Note that
recycle(Unmarshaller)
shall not be invoked in case of exception,
since the unmarshaller may be in an invalid state.JAXBException
- if an error occurred while creating and configuring the unmarshaller.public void recycle(Marshaller marshaller)
finally
block.acquireMarshaller()
.
In case of doubt, it is better to not recycle the marshaller at all.marshaller
- the marshaller to return to the pool.public void recycle(Unmarshaller unmarshaller)
finally
block.acquireUnmarshaller()
.
In case of doubt, it is better to not recycle the unmarshaller at all.unmarshaller
- the unmarshaller to return to the pool.protected Marshaller createMarshaller() throws JAXBException
JAXBException
- if an error occurred while creating and configuring the marshaller.context
,
acquireMarshaller()
protected Unmarshaller createUnmarshaller() throws JAXBException
JAXBException
- if an error occurred while creating and configuring the unmarshaller.context
,
acquireUnmarshaller()
Copyright © 2010–2017 The Apache Software Foundation. All rights reserved.