Class XML
MarshallerPool).
Unmarshalling detects the version automatically.
| Topic | SIS 0.3 to 0.8 | SIS 1.0 | Remarks |
|---|---|---|---|
| Metadata | ISO 19139:2007 | ISO 19115-3:2016 | |
| Referencing | ISO 19136:2007 | ISO 19136:2007 | Same as GML 3.2 |
Marshaller
and Unmarshaller instances created by MarshallerPool:
| Key | Value type | Purpose |
|---|---|---|
LOCALE | Locale | for specifying the locale to use for international strings and code lists. |
TIMEZONE | TimeZone | for specifying the timezone to use for dates and times. |
SCHEMAS | Map | for specifying the root URL of metadata schemas to use. |
GML_VERSION | Version | for specifying the GML version of the document to be (un)marshalled. |
METADATA_VERSION | Version | for specifying the metadata version of the document to be (un)marshalled. |
RESOLVER | ReferenceResolver | for replacing xlink or uuidref attributes by the actual object to use. |
CONVERTER | ValueConverter | for controlling the conversion of URL, UUID, Units or similar objects. |
STRING_SUBSTITUTES | String[] | for specifying which code lists to replace by simpler <gco:CharacterString> elements. |
WARNING_FILTER | Filter | for being notified about non-fatal warnings. |
- Since:
- 0.3
Defined in the sis-metadata module
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringControls the behaviors of the (un)marshalling process when an element cannot be processed, or alter the element values.static final StringSpecifies the GML version of the document to be marshalled or unmarshalled.static final StringSpecifies whether the unmarshalling process should accept any metadata or GML supported version if the user did not specified an explicit version.static final StringSpecifies the locale to use for marshallingInternationalStringandCodeListinstances.static final StringSpecifies the metadata version of the document to be marshalled or unmarshalled.static final StringAllows client code to replacexlinkoruuidrefattributes by the actual objects to use.static final StringSpecifies the root URLs of some schemas.static final StringAllows marshallers to substitute some code lists by the simpler<gco:CharacterString>element.static final StringSpecifies the timezone to use for marshalling dates and times.static final StringSpecifies a listener to be notified when a non-fatal error occurred during the (un)marshalling. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringMarshal the given object into a string.static voidMarshal the given object into a file.static voidmarshal(Object object, OutputStream output) Marshal the given object into a stream.static voidMarshal the given object into a path.static voidMarshal the given object to a stream, DOM or other destinations.static ObjectUnmarshal an object from the given file.static Objectunmarshal(InputStream input) Unmarshal an object from the given stream.static ObjectUnmarshal an object from the given string.static ObjectUnmarshal an object from the given URL.static ObjectUnmarshal an object from the given path.static <T> JAXBElement<T>Unmarshal an object from the given stream, DOM or other sources.static ObjectUnmarshal an object from the given stream, DOM or other sources.
-
Field Details
-
LOCALE
Specifies the locale to use for marshallingInternationalStringandCodeListinstances. The value for this property shall be an instance ofLocaleor aCharSequencerecognized byLocales.parse(String).This property is mostly for marshallers. However, this property can also be used at unmarshalling time, for example if a
<lan:PT_FreeText>element containing many localized strings need to be represented in a JavaStringobject. In such case, the unmarshaller will try to pickup a string in the language specified by this property.Default behavior
If this property is never set, then (un)marshalling will try to use "unlocalized" strings - typically some programmatic strings like UML identifiers. While such identifiers often look like English words, they are not considered as the English localization. The algorithm attempting to find a "unlocalized" string is defined in theDefaultInternationalString.toString(Locale)javadoc.Special case
If the object to be marshalled is an instance ofDefaultMetadata, then the value given to itssetLanguage(Locale)method will have precedence over this property. This behavior is compliant with INSPIRE rules.- See Also:
-
OptionKey.LOCALEMarshaller.setProperty(String, Object)DefaultMetadata.setLanguage(Locale)- Constant Field Values
-
TIMEZONE
Specifies the timezone to use for marshalling dates and times. The value for this property shall be an instance ofTimeZoneor aCharSequencerecognized byTimeZone.getTimeZone(String).Default behavior
If this property is never set, then (un)marshalling will use the default timezone.- See Also:
-
SCHEMAS
Specifies the root URLs of some schemas. This property modifies only the URL strings; it does not change the structure of marshalled XML documents (for content structure, seeMETADATA_VERSION). The value for this property shall be an instance ofMap<String,String>. This property controls the URLs to be used when marshalling the following elements:- The value of the
codeListattribute when marshalling subclasses ofCodeList. - The value of the
uomattribute when marshalling measures (for example<gco:Distance>).
Examples: URLs in code lists and is units of measurement may appear as below. The underlined fragment is the part that can be replaced byThe currently recognized keys are listed below. The entries to be used depend on the metadata version to be marshalled. For example, theSCHEMASvalues:http://standards.iso.org/iso/19115/resources/Codelist/cat/codelists.xml#LanguageCodehttp://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#LanguageCodehttp://www.isotc211.org/2005/resources/uom/gmxUom.xml#xpointer(//*[@gml:id='m'])
"cat"entry is used when marshalling ISO 19115-3:2016 document, while the"gmd"and"gmi"entries are used when marshalling ISO 19139:2007 documents. The following table gives some typical URLs, with the default URL in bold characters:
Additional keys, if any, are ignored. Future SIS versions may recognize more keys.Supported root URLs Map key Typical values (choose only one) cat http://standards.iso.org/iso/19115/ gmd http://www.isotc211.org/2005/
http://schemas.opengis.net/iso/19139/20070417/
http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/- See Also:
- The value of the
-
GML_VERSION
Specifies the GML version of the document to be marshalled or unmarshalled. The GML version may affect the set of XML elements to be marshalled and their namespaces. Note that GML 3.2 is identical to ISO 19136:2007.Compatibility note: Newer versions typically have more elements, but not always. For example, inThe value can be<gml:VerticalDatum>, the<gml:verticalDatumType>property presents in GML 3.0 and 3.1 has been removed in GML 3.2.StringorVersionobject. If no version is specified, then the most recent supported GML version is assumed.Supported GML versions
Apache SIS currently supports GML 3.2.1 by default. SIS can read and write GML 3.2 if this property is set to "3.2". It is also possible to set this property to "3.1", but the marshalled XML is not GML 3.1.1 conformant because of the differences between the two schemas. See SIS-160: Need XSLT between GML 3.1 and 3.2 for information about the status of GML 3.1.1 support.- See Also:
-
METADATA_VERSION
Specifies the metadata version of the document to be marshalled or unmarshalled. The metadata version may affect the set of XML elements to be marshalled and their namespaces. The value can beStringorVersionobject. If no version is specified, then the most recent supported metadata version is assumed.The metadata version may be ignored when the metadata to marshal is inside a GML element. For example, the
<gml:domainOfValidity>element inside a coordinate reference system is always marshalled using ISO 19139:2007 if the enclosing element uses GML 3.2 schema.Supported metadata versions
Apache SIS currently supports ISO 19115-3:2016 by default. This version can be explicitly set with value "2014" or above (because the abstract model was defined in ISO 19115-1:2014). SIS can write legacy ISO 19139:2007 documents if this property is set to a value less than "2014". Both versions can be read without the need to specify this property.- Since:
- 1.0
- See Also:
-
LENIENT_UNMARSHAL
Specifies whether the unmarshalling process should accept any metadata or GML supported version if the user did not specified an explicit version. The value can be aBooleaninstance, or"true"or"false"as aString. If this value is not specified, then the default istruefor allXML.unmarshalmethods andfalseotherwise.Metadata and Geographic Markup Language have slightly different XML encoding depending on the OGC/ISO version in use. Often the namespaces are different, but not only. Internally, Apache SIS supports only the schema versions documented in this class javadoc, for example the ISO 19115-3:2016 version of metadata schema. For unmarshalling a document encoded according an older metadata schema (e.g. ISO 19139:2007), a transformation is applied on-the-fly. However this transformation may sometimes produce undesirable results or make debugging more difficult. For this reason
MarshallerPoolapplies the transformation only if explicitly requested, either by setting aMETADATA_VERSIONorGML_VERSIONexplicitly, or by setting thisLENIENT_UNMARSHALproperty totrueif the version to unmarshal is not known in advance.- Since:
- 1.0
- See Also:
-
RESOLVER
Allows client code to replacexlinkoruuidrefattributes by the actual objects to use. The value for this property shall be an instance ofReferenceResolver.If a property in a XML document is defined only by
xlinkoruuidrefattributes, without any concrete definition, then the default behavior is as below:- If the reference is of the form
xlink:href="#foo"and an object with thegml:id="foo"attribute was previously found in the same XML document, then that object will be used. - Otherwise an empty element containing only the values of the above-cited attributes is created.
ReferenceResolverand configuring a unmarshaller as below:ReferenceResolver myResolver = ...; Map<String,Object> properties = new HashMap<>(); properties.put(XML.RESOLVER, myResolver); Object obj = XML.unmarshal(source, properties);
- See Also:
-
Unmarshaller.setProperty(String, Object)ReferenceResolver- Constant Field Values
- If the reference is of the form
-
CONVERTER
Controls the behaviors of the (un)marshalling process when an element cannot be processed, or alter the element values. The value for this property shall be an instance ofValueConverter.If an element in a XML document cannot be parsed (for example if a URL string is not valid), the default behavior is to throw an exception which cause the (un)marshalling of the entire document to fail. This default behavior can be customized by invoking
Marshaller.setProperty(String, Object)with thisCONVERTERproperty key and a customValueConverterinstance.ValueConvertercan also be used for replacing an erroneous URL by a fixed URL. See theValueConverterjavadoc for more details.Example: the following example collects the failures in a list without stopping the (un)marshalling process.class WarningCollector extends ValueConverter { // The warnings collected during (un)marshalling. List<String> messages = new ArrayList<String>(); // Override the default implementation in order to // collect the warnings and allow the process to continue. @Override protected <T> boolean exceptionOccured(MarshalContext context, T value, Class<T> sourceType, Class<T> targetType, Exception e) { mesages.add(e.getLocalizedMessage()); return true; } } // Unmarshal a XML string, trapping some kind of errors. // Not all errors are trapped - see the ValueConverter // javadoc for more details. WarningCollector myWarningList = new WarningCollector(); Map<String,Object> properties = new HashMap<>(); properties.put(XML.CONVERTER, myWarningList); Object obj = XML.unmarshal(source, properties); if (!myWarningList.isEmpty()) { // Report here the warnings to the user. }- See Also:
-
Unmarshaller.setProperty(String, Object)ValueConverter- Constant Field Values
-
STRING_SUBSTITUTES
Allows marshallers to substitute some code lists by the simpler<gco:CharacterString>element. The value for this property shall be aString[]array of any of the following values:- "
language" for substituting<lan:LanguageCode>elements - "
country" for substituting<lan:Country>elements - "
filename" for substituting<gcx:FileName>elements - "
mimetype" for substituting<gcx:MimeFileType>elements
Example: INSPIRE compliant language code shall be formatted like below (details may vary):
However if this property contains the "<gmd:language> <gmd:LanguageCode codeList="http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#LanguageCode" codeListValue="fra">French</gmd:LanguageCode> </gmd:language>language" value, then the marshaller will format the language code like below (which is legal according OGC schemas, but is not INSPIRE compliant):<lan:language> <gco:CharacterString>fra</gco:CharacterString> </lan:language>
- See Also:
- "
-
WARNING_FILTER
Specifies a listener to be notified when a non-fatal error occurred during the (un)marshalling. The value for this property shall be an instance ofFilter.By default, warnings that occur during the (un)marshalling process are logged. However if a property is set for this key, then the
Filter.isLoggable(LogRecord)method will be invoked. If that method returnsfalse, then the warning will not be logged by the (un)marshaller.- Since:
- 1.0
- See Also:
-
-
Method Details
-
marshal
Marshal the given object into a string.- Parameters:
object- the root of content tree to be marshalled.- Returns:
- the XML representation of the given object.
- Throws:
JAXBException- if an error occurred during the marshalling.
-
marshal
Marshal the given object into a stream.- Parameters:
object- the root of content tree to be marshalled.output- the stream where to write.- Throws:
JAXBException- if an error occurred during the marshalling.
-
marshal
Marshal the given object into a file.- Parameters:
object- the root of content tree to be marshalled.output- the file to be written.- Throws:
JAXBException- if an error occurred during the marshalling.
-
marshal
Marshal the given object into a path.- Parameters:
object- the root of content tree to be marshalled.output- the file to be written.- Throws:
JAXBException- if an error occurred during the marshalling.
-
marshal
public static void marshal(Object object, Result output, Map<String, ?> properties) throws JAXBExceptionMarshal the given object to a stream, DOM or other destinations. This is the most flexible marshalling method provided in thisXMLclass. The destination is specified by theoutputargument implementation, for exampleStreamResultfor writing to a file or output stream. The optionalpropertiesmap can contain any key documented in thisXMLclass, together with the keys documented in the supported properties section of the theMarshallerclass.- Parameters:
object- the root of content tree to be marshalled.output- the file to be written.properties- an optional map of properties to give to the marshaller, ornullif none.- Throws:
JAXBException- if a property has an illegal value, or if an error occurred during the marshalling.- Since:
- 0.4
-
unmarshal
Unmarshal an object from the given string. Note that the given argument is the XML document itself, not a URL to a XML document.- Parameters:
xml- the XML representation of an object.- Returns:
- the object unmarshalled from the given input.
- Throws:
JAXBException- if an error occurred during the unmarshalling.
-
unmarshal
Unmarshal an object from the given stream.- Parameters:
input- the stream from which to read a XML representation.- Returns:
- the object unmarshalled from the given input.
- Throws:
JAXBException- if an error occurred during the unmarshalling.
-
unmarshal
Unmarshal an object from the given URL.- Parameters:
input- the URL from which to read a XML representation.- Returns:
- the object unmarshalled from the given input.
- Throws:
JAXBException- if an error occurred during the unmarshalling.
-
unmarshal
Unmarshal an object from the given file.- Parameters:
input- the file from which to read a XML representation.- Returns:
- the object unmarshalled from the given input.
- Throws:
JAXBException- if an error occurred during the unmarshalling.
-
unmarshal
Unmarshal an object from the given path.- Parameters:
input- the path from which to read a XML representation.- Returns:
- the object unmarshalled from the given input.
- Throws:
JAXBException- if an error occurred during the unmarshalling.
-
unmarshal
Unmarshal an object from the given stream, DOM or other sources. Together with the Unmarshal by Declared Type variant, this is the most flexible unmarshalling method provided in thisXMLclass. The source is specified by theinputargument implementation, for exampleStreamSourcefor reading from a file or input stream. The optionalpropertiesmap can contain any key documented in thisXMLclass, together with the keys documented in the supported properties section of the theUnmarshallerclass.- Parameters:
input- the file from which to read a XML representation.properties- an optional map of properties to give to the unmarshaller, ornullif none.- Returns:
- the object unmarshalled from the given input.
- Throws:
JAXBException- if a property has an illegal value, or if an error occurred during the unmarshalling.- Since:
- 0.4
-
unmarshal
public static <T> JAXBElement<T> unmarshal(Source input, Class<T> declaredType, Map<String, ?> properties) throws JAXBExceptionUnmarshal an object from the given stream, DOM or other sources. Together with the Unmarshal Global Root Element variant, this is the most flexible unmarshalling method provided in thisXMLclass. The source is specified by theinputargument implementation, for exampleStreamSourcefor reading from a file or input stream. The optionalpropertiesmap can contain any key documented in thisXMLclass, together with the keys documented in the supported properties section of the theUnmarshallerclass.- Type Parameters:
T- compile-time value of thedeclaredTypeargument.- Parameters:
input- the file from which to read a XML representation.declaredType- the JAXB mapped class of the object to unmarshal.properties- an optional map of properties to give to the unmarshaller, ornullif none.- Returns:
- the object unmarshalled from the given input, wrapped in a JAXB element.
- Throws:
JAXBException- if a property has an illegal value, or if an error occurred during the unmarshalling.- Since:
- 0.8
-