Package org.apache.sis.xml
Class ReferenceResolver
Object
ReferenceResolver
Controls the (un)marshaller behavior regarding the 
xlink or uuidref attributes.
 At marshalling time, this class controls whether the marshaller is allowed to write a reference
 to an existing instance instead of writing the full object definition.
 At unmarshalling time, this class replaces (if possible) a reference by the full object definition.
 Subclasses can override the methods defined in this class in order to search in their own catalog.
 See the XML.RESOLVER javadoc for an example of registering a custom ReferenceResolver
 to a unmarshaller.
- Since:
- 0.3
Defined in the sis-metadata module
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final ReferenceResolverThe default and thread-safe instance.
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedCreates a defaultReferenceResolver.
- 
Method SummaryModifier and TypeMethodDescriptionanchor(MarshalContext context, Object value, CharSequence text) Returns the<gcx:Anchor>to use for the given text, ornullif none.<T> booleancanSubstituteByReference(MarshalContext context, Class<T> type, T object, String id) Returnstrueif the marshaller can use axlink:href="#id"reference to the given object instead of writing the full XML element.<T> booleancanSubstituteByReference(MarshalContext context, Class<T> type, T object, UUID uuid) Returnstrueif the marshaller can use a reference to the given object instead of writing the full XML element.<T> booleancanSubstituteByReference(MarshalContext context, Class<T> type, T object, XLink link) Returnstrueif the marshaller can use axlink:hrefreference to the given object instead of writing the full XML element.<T> TnewIdentifiedObject(MarshalContext context, Class<T> type, Identifier... identifiers) Returns an empty object of the given type having the given identifiers.<T> Tresolve(MarshalContext context, Class<T> type, UUID uuid) Returns an object of the given type for the givenuuidattribute, ornullif none.<T> Tresolve(MarshalContext context, Class<T> type, XLink link) Returns an object of the given type for the givenxlinkattribute, ornullif none.
- 
Field Details- 
DEFAULTThe default and thread-safe instance. This instance is used at unmarshalling time when noReferenceResolverwas explicitly set by theXML.RESOLVERproperty.
 
- 
- 
Constructor Details- 
ReferenceResolverprotected ReferenceResolver()Creates a defaultReferenceResolver. This constructor is for subclasses only.
 
- 
- 
Method Details- 
newIdentifiedObjectReturns an empty object of the given type having the given identifiers. The object returned by the default implementation has the following properties:- Implements the given typeinterface.
- Implements the NilObjectandIdentifiedObjectinterfaces from this package.
- IdentifiedObject.getIdentifiers()will return the given identifiers.
- IdentifiedObject.getIdentifierMap()will return a- Mapview over the given identifiers.
- All other methods except the ones inherited from the Objectclass will return an empty collection, an empty array,null,Double.NaN, 0 orfalse, depending on the method return type.
 - Type Parameters:
- T- the compile-time type of the- typeargument.
- Parameters:
- context- context (GML version, locale, etc.) of the (un)marshalling process.
- type- the type of object to be unmarshalled, often as a GeoAPI interface.
- identifiers- an arbitrary number 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 nullif none.
 
- Implements the given 
- 
resolveReturns an object of the given type for the givenuuidattribute, ornullif none. The default implementation returnsnullin all cases.- Type Parameters:
- T- the compile-time type of the- typeargument.
- Parameters:
- context- context (GML version, locale, etc.) of the (un)marshalling process.
- type- the type of object to be unmarshalled, often as a GeoAPI interface.
- uuid- the- uuidattributes.
- Returns:
- an object of the given type for the given uuidattribute, ornullif none.
 
- 
resolveReturns an object of the given type for the givenxlinkattribute, ornullif none. The default implementation performs the following lookups:- If the xlink:hrefattribute is a URI fragment of the form"#foo"and if an object of classtypewith thegml:id="foo"attribute has previously been seen in the same XML document, then that object is returned.
- Otherwise returns null.
 - Type Parameters:
- T- the compile-time type of the- typeargument.
- Parameters:
- context- context (GML version, locale, etc.) of the (un)marshalling process.
- type- the type of object to be unmarshalled, often as a GeoAPI interface.
- link- the- xlinkattributes.
- Returns:
- an object of the given type for the given xlinkattribute, ornullif none.
 
- If the 
- 
canSubstituteByReferencepublic <T> boolean canSubstituteByReference(MarshalContext context, Class<T> type, T object, String id) Returnstrueif the marshaller can use axlink:href="#id"reference to the given object instead of writing the full XML element. This method is invoked by the marshaller when:- The given object has already been marshalled in the same XML document.
- The marshalled object had a gml:idattribute- either specified explicitly by
         IdentifierMap.put(IdentifierSpace.ID, id)
- or inferred automatically by the marshalled object
         (e.g. AbstractIdentifiedObject).
 
- either specified explicitly by
         
 true, then the use ofxlink:href="#id"will have precedence over UUID and XLink alternatives.The default implementation unconditionally returns true. Subclasses can override this method if they want to filter which objects to declare by reference.- Type Parameters:
- T- the compile-time type of the- typeargument.
- Parameters:
- context- context (GML version, locale, etc.) of the (un)marshalling process.
- type- the type of object to be unmarshalled, often as a GeoAPI interface.
- object- the object to be marshalled.
- id- the- gml:idvalue of the object to be marshalled.
- Returns:
- trueif the marshaller can use the- xlink:href="#id"attribute instead of marshalling the given object.
- Since:
- 0.7
 
- 
canSubstituteByReferencepublic <T> boolean canSubstituteByReference(MarshalContext context, Class<T> type, T object, UUID uuid) Returnstrueif the marshaller can use a reference to the given object instead of writing the full XML element. This method is invoked when an object to be marshalled has a UUID identifier. Because those object may be defined externally, SIS cannot know if the object shall be fully marshalled or not. Such information needs to be provided by the application.The default implementation returns truein the following cases:- If objectimplementsNilObject.
- If objectimplementsEmptiableand itsisEmpty()method returnstrue.
 - Type Parameters:
- T- the compile-time type of the- typeargument.
- Parameters:
- context- context (GML version, locale, etc.) of the (un)marshalling process.
- type- the type of object to be unmarshalled, often as a GeoAPI interface.
- object- the object to be marshalled.
- uuid- the unique identifier of the object to be marshalled.
- Returns:
- trueif the marshaller can use the- uuidrefattribute instead of marshalling the given object.
 
- If 
- 
canSubstituteByReferencepublic <T> boolean canSubstituteByReference(MarshalContext context, Class<T> type, T object, XLink link) Returnstrueif the marshaller can use axlink:hrefreference to the given object instead of writing the full XML element. This method is invoked when an object to be marshalled has aXLinkidentifier. Because those object may be defined externally, SIS cannot know if the object shall be fully marshalled or not. Such information needs to be provided by the application.The default implementation returns truein the following cases:- If objectimplementsNilObject.
- If objectimplementsEmptiableand itsisEmpty()method returnstrue.
 - Type Parameters:
- T- the compile-time type of the- typeargument.
- Parameters:
- context- context (GML version, locale, etc.) of the (un)marshalling process.
- type- the type of object to be unmarshalled, often as a GeoAPI interface.
- object- the object to be marshalled.
- link- the reference of the object to be marshalled.
- Returns:
- trueif the marshaller can use the- xlink:hrefattribute instead of marshalling the given object.
 
- If 
- 
anchorReturns the<gcx:Anchor>to use for the given text, ornullif none. Anchors can appear in ISO 19115-3 documents where we would normally expect a character sequence. For example:
 Subclasses can override this method if they can provide a mapping from some text values to anchors.XML representations of string As <gco:CharacterString>As <gcx:Anchor><cit:country> <gco:CharacterString>France</gco:CharacterString> </cit:country><cit:country> <gcx:Anchor xlink:href="SDN:C320:2:FR">France</gcx:Anchor> </cit:country>- Parameters:
- context- context (GML version, locale, etc.) of the (un)marshalling process.
- value- the value for which an anchor is requested. Often the same instance than- text, but can also be the- URIor- Localeinstance for which- textis a string representation.
- text- the textual representation of the value for which to get the anchor.
- Returns:
- the anchor for the given text, or nullif none.
 
 
-