|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
ObjectMarshallerPool
@ThreadSafe public class MarshallerPool
Creates and configures Marshaller or Unmarshaller objects for use with Geotk.
Users fetch (un)marshallers by calls to the acquireMarshaller() or
acquireUnmarshaller() methods.
Configuring marshallers
The (un)marshallers created by this class can optionally by configured with the Geotk-specific
properties defined in the XML class, in addition to JAXB standard properties.
XML
| utility/geotk-xml-base (download) | View source code for this class |
| Field Summary | |
|---|---|
static String |
ROOT_NAMESPACE_KEY
The key to be used in the map given to the constructors for specifying the root namespace. |
| Constructor Summary | |
|---|---|
MarshallerPool(Class<?>... classesToBeBound)
Creates a new factory for the given class to be bound, with a default empty namespace. |
|
MarshallerPool(Map<String,String> properties,
Class<?>... classesToBeBound)
Creates a new factory for the given class to be bound. |
|
MarshallerPool(Map<String,String> properties,
String packages)
Creates a new factory for the given packages. |
|
MarshallerPool(String packages)
Creates a new factory for the given packages, with a default empty namespace. |
|
| Method Summary | |
|---|---|
Marshaller |
acquireMarshaller()
Returns a JAXB marshaller from the pool. |
Unmarshaller |
acquireUnmarshaller()
Returns a JAXB unmarshaller from the pool. |
protected void |
addAnchor(String label,
URI linkage)
Adds a label associated to an URN. |
protected Marshaller |
createMarshaller()
Creates an configure a new JAXB marshaller. |
protected Unmarshaller |
createUnmarshaller()
Creates an configure a new JAXB unmarshaller. |
static Class<?>[] |
defaultClassesToBeBound()
Returns the root classes of Geotk objects to be marshalled by default. |
void |
release(Marshaller marshaller)
Declares a marshaller as available for reuse. |
void |
release(Unmarshaller unmarshaller)
Declares a unmarshaller as available for reuse. |
| Methods inherited from class Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String ROOT_NAMESPACE_KEY
"http://www.isotc211.org/2005/gmd".
| Constructor Detail |
|---|
public MarshallerPool(Class<?>... classesToBeBound)
throws JAXBException
classesToBeBound - The classes to be bound, for example DefaultMetadata.class.
JAXBException - If the JAXB context can not be created.
public MarshallerPool(Map<String,String> properties,
Class<?>... classesToBeBound)
throws JAXBException
properties map
shall be one or many of the constants defined in this class like ROOT_NAMESPACE_KEY.
properties - The set of properties to be given to the pool.classesToBeBound - The classes to be bound, for example DefaultMetadata.class.
JAXBException - If the JAXB context can not be created.
public MarshallerPool(String packages)
throws JAXBException
packages - The packages in which JAXB will search for annotated classes to be bound,
for example "org.geotoolkit.metadata.iso:org.geotoolkit.metadata.iso.citation".
JAXBException - If the JAXB context can not be created.
public MarshallerPool(Map<String,String> properties,
String packages)
throws JAXBException
properties map shall be one or many of the constants defined
in this class like ROOT_NAMESPACE_KEY.
properties - The set of properties to be given to the pool.packages - The packages in which JAXB will search for annotated classes to be bound,
for example "org.geotoolkit.metadata.iso:org.geotoolkit.metadata.iso.citation".
JAXBException - If the JAXB context can not be created.| Method Detail |
|---|
public static Class<?>[] defaultClassesToBeBound()
MarshallerPool
constructors, in order to bound a default set of classes with JAXBContext.
The list of classes is determined dynamically from the Geotk modules found on the classpath.
JAXBContext.
public Marshaller acquireMarshaller()
throws JAXBException
This method should be used as below:
Note that this is not strictly required to release the marshaller in aMarshaller marshaller = pool.acquireMarshaller(); marshaller.marchall(...); pool.release(marshaller);
finally
block. Actually it is safer to let the garbage collector disposes the marshaller if an
error occurred while marshalling the object.
JAXBException - If an error occurred while creating and configuring a marshaller.
public Unmarshaller acquireUnmarshaller()
throws JAXBException
This method should be used as below:
Note that this is not strictly required to release the unmarshaller in aUnmarshaller unmarshaller = pool.acquireUnmarshaller(); Unmarshaller.unmarchall(...); pool.release(unmarshaller);
finally
block. Actually it is safer to let the garbage collector disposes the unmarshaller if an
error occurred while unmarshalling the object.
JAXBException - If an error occurred while creating and configuring the unmarshaller.public void release(Marshaller marshaller)
marshaller - The marshaller to return to the pool.public void release(Unmarshaller unmarshaller)
unmarshaller - The unmarshaller to return to the pool.
protected Marshaller createMarshaller()
throws JAXBException
JAXBException - If an error occurred while creating and configuring the marshaller.
protected Unmarshaller createUnmarshaller()
throws JAXBException
JAXBException - If an error occurred while creating and configuring the unmarshaller.
protected void addAnchor(String label,
URI linkage)
throws IllegalStateException
String object, the code will be completed by the given URN in an AnchorType
element.
This method should be invoked from subclasses constructor only. Anchors can be added but can not be removed or modified.
label - The label associated to the URN.linkage - The URN.
IllegalStateException - If a URN is already associated to the given linkage.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||