org.geotoolkit.xml
Class ObjectLinker

Object
  extended by ObjectLinker

public class ObjectLinker
extends Object

Invoked by the unmarshaller when xlink or uuidref attributes are found instead of object definition. This class provides methods for assigning a UUID to an arbitrary object, or fetching an existing object from a UUID.

Subclasses can override the methods defined in this class in order to search in their own catalog. See the XML.LINKER javadoc for an example of registering a custom ObjectLinker to a unmarshaller.

Since:
3.18
Version:
3.19
Author:
Martin Desruisseaux (Geomatys)
Module:
utility/geotk-xml-base (download)    View source code for this class

Field Summary
static ObjectLinker DEFAULT
          The default and thread-safe instance.
 
Constructor Summary
protected ObjectLinker()
          Creates a default ObjectLinker.
 
Method Summary
<T> boolean
canUseReference(Class<T> type, T object, UUID uuid)
          Returns true if the marshaller can use a reference to the given metadata instead than writing the full element.
<T> T
newIdentifiedObject(Class<T> type, Identifier... identifiers)
          Returns an empty object of the given type having the given identifiers.
<T> T
resolve(Class<T> type, NilReason nilReason)
          Returns an object of the given type for the given nilReason attributes.
<T> T
resolve(Class<T> type, UUID uuid)
          Returns an object of the given type for the given uuid attribute, or null if none.
<T> T
resolve(Class<T> type, XLink link)
          Returns an object of the given type for the given xlink attribute, or null if none.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT

public static final ObjectLinker DEFAULT
The default and thread-safe instance. This instance is used at unmarshalling time when no ObjectLinker was explicitly set by the XML.LINKER property.

Constructor Detail

ObjectLinker

protected ObjectLinker()
Creates a default ObjectLinker. This constructor is for subclasses only.

Method Detail

newIdentifiedObject

public <T> T newIdentifiedObject(Class<T> type,
                                 Identifier... identifiers)
Returns an empty object of the given type having the given identifiers. The object returned by the default implementation has the following properties:

Type Parameters:
T - The compile-time type of the type argument.
Parameters:
type - The type of object to be unmarshalled as an interface. This is usually a GeoAPI interface.
identifiers - An arbitrary amount of identifiers. For each identifier, the authority is typically (but not necessarily) one of the constants defined in IdentifierSpace.
Returns:
An object of the given type for the given identifiers, or null if none.
Since:
3.19

resolve

public <T> T resolve(Class<T> type,
                     UUID uuid)
Returns an object of the given type for the given uuid attribute, or null if none. The default implementation first looks in an internal map for previously unmarshalled object having the given UUID.

Type Parameters:
T - The compile-time type of the type argument.
Parameters:
type - The type of object to be unmarshalled as an interface. This is usually a GeoAPI interface.
uuid - The uuid attributes.
Returns:
An object of the given type for the given uuid attribute, or null if none.
Since:
3.19

resolve

public <T> T resolve(Class<T> type,
                     XLink link)
Returns an object of the given type for the given xlink attribute, or null if none. The default implementation returns null in all cases.

Type Parameters:
T - The compile-time type of the type argument.
Parameters:
type - The type of object to be unmarshalled as an interface. This is usually a GeoAPI interface.
link - The xlink attributes.
Returns:
An object of the given type for the given xlink attribute, or null if none.

resolve

public <T> T resolve(Class<T> type,
                     NilReason nilReason)
Returns an object of the given type for the given nilReason attributes. The default implementation returns an immutable object which implement the NilObject interface and the given type. The NilObject.getNilReason() method will return the given reason, and all other methods (except the ones inherited from the Object class) will return null or an empty collection as appropriate.

Type Parameters:
T - The compile-time type of the type argument.
Parameters:
type - The type of object to be unmarshalled as an interface. This is usually a GeoAPI interface.
nilReason - The nilReason attribute.
Returns:
An object of the given type for the given nilReason attribute, or null if none.

canUseReference

public <T> boolean canUseReference(Class<T> type,
                                   T object,
                                   UUID uuid)
Returns true if the marshaller can use a reference to the given metadata instead than writing the full element. This method is invoked when a metadata to be marshalled has a UUID identifier. Because those metadata may be defined externally, Geotk can not know if the metadata shall be fully marshalled or not. This information must be provided by the application.

The default implementation conservatively returns false in every cases.

Type Parameters:
T - The compile-time type of the type argument.
Parameters:
type - The type of object to be marshalled as an interface. This is usually a GeoAPI interface.
object - The object to be marshalled.
uuid - The unique identifier of the object to be marshalled.
Returns:
true if the marshaller can use the uuidref attribute instead than marshalling the given metadata.
Since:
3.19


Copyright © 2009-2011 Geotoolkit.org. All Rights Reserved.