Package org.apache.sis.internal.jaxb
Class Context
java.lang.Object
org.apache.sis.xml.MarshalContext
org.apache.sis.internal.jaxb.Context
Thread-local status of a marshalling or unmarshalling processes.
All non-static methods in this class except
finish() are implementation of public API.
All static methods are internal API. Those methods expect a Context instance as their first argument.
They can be though as if they were normal member methods, except that they accept null instance
if no (un)marshalling is in progress.- Since:
- 0.3
- Version:
- 1.0
- Author:
- Martin Desruisseaux (Geomatys), Cullen Rombach (Image Matters)
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intWhether we are (un)marshalling legacy metadata as defined in 2003 model (ISO 19139:2007).static final intWhether the unmarshalling process should accept any metadata or GML version if the user did not specified an explicit version.static final LoggerThe logger to use for warnings that are specific to XML.static final intThe bit flag telling if a marshalling process is under progress.static final intThe bit flag for enabling substitution of country codes by character strings.static final intThe bit flag for enabling substitution of filenames by character strings.static final intThe bit flag for enabling substitution of language codes by character strings.static final intThe bit flag for enabling substitution of mime types by character strings. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ValueConverterReturns the value converter in use for the current marshalling or unmarshalling process.static Contextcurrent()Returns the context of the XML (un)marshalling currently progressing in the current thread, ornullif none.final voidfinish()Invoked in afinallyblock when a unmarshalling process is finished.final LocaleReturns the locale to use for marshalling, ornullif no locale were explicitly specified.static ObjectgetObjectForID(Context context, String id) Returns the object for the givengml:id, ornullif none.static StringgetObjectID(Context context, Object object) If agml:idvalue has already been used for the given object in the current XML document, returns that identifier.final TimeZoneReturns the timezone to use for marshalling, ornullif none were explicitly specified.final VersiongetVersion(String prefix) Returns the schema version of the XML document being (un)marshalled.static PropertyType<?, ?> getWrapper(Context context) Returns the<gml:*PropertyType>which is wrapping the<gml:*Type>object to (un)marshal, ornullif this information is not provided.static booleanReturnstrueif the given flag is set.static booleanisGMLVersion(Context context, Version version) Returnstrueif the GML version is equal or newer than the specified version.static voidpull()Restores the locale which was used prior the call topush(Locale).static voidSets the locale to the given value.static ReferenceResolverReturns the reference resolver in use for the current marshalling or unmarshalling process.static StringBuilderReturns the base URL of ISO 19115-3 (or other standards) schemas.static booleansetObjectForID(Context context, Object object, String id) Returnstrueif the given identifier is available, orfalseif it is used by another object.static voidsetWrapper(Context context, PropertyType<?, ?> wrapper) Invoked byPropertyTypeimplementations for declaring the<gml:*PropertyType>instance which is wrapping the<gml:*Type>object to (un)marshal.static voidwarningOccured(Context context, Class<?> classe, String method, Class<? extends IndexedResourceBundle> resources, short key, Object... arguments) static voidwarningOccured(Context context, Class<?> classe, String method, Exception cause, boolean isWarning) Convenience method for sending a warning for the given exception.static voidwarningOccured(Context context, Level level, Class<?> classe, String method, Throwable exception, Class<? extends IndexedResourceBundle> resources, short key, Object... arguments) Sends a warning to the warning listener if there is one, or logs the warning otherwise.
-
Field Details
-
MARSHALLING
public static final int MARSHALLINGThe bit flag telling if a marshalling process is under progress. This flag is unset for unmarshalling processes.- See Also:
-
SUBSTITUTE_LANGUAGE
public static final int SUBSTITUTE_LANGUAGEThe bit flag for enabling substitution of language codes by character strings.- See Also:
-
SUBSTITUTE_COUNTRY
public static final int SUBSTITUTE_COUNTRYThe bit flag for enabling substitution of country codes by character strings.- See Also:
-
SUBSTITUTE_FILENAME
public static final int SUBSTITUTE_FILENAMEThe bit flag for enabling substitution of filenames by character strings.- See Also:
-
SUBSTITUTE_MIMETYPE
public static final int SUBSTITUTE_MIMETYPEThe bit flag for enabling substitution of mime types by character strings.- See Also:
-
LEGACY_METADATA
public static final int LEGACY_METADATAWhether we are (un)marshalling legacy metadata as defined in 2003 model (ISO 19139:2007). If this flag is not set, then we assume latest metadata as defined in 2014 model (ISO 19115-3).- See Also:
-
LENIENT_UNMARSHAL
public static final int LENIENT_UNMARSHALWhether the unmarshalling process should accept any metadata or GML version if the user did not specified an explicit version. Accepting any version may have surprising results since namespace substitutions may be performed on the fly.- See Also:
-
LOGGER
The logger to use for warnings that are specific to XML.
-
-
Constructor Details
-
Context
public Context(int bitMasks, Locale locale, TimeZone timezone, Map<String, String> schemas, Version versionGML, Version versionMetadata, ReferenceResolver resolver, ValueConverter converter, Filter logFilter) Invoked when a marshalling or unmarshalling process is about to begin. Must be followed by a call tofinish()in afinallyblock.- Parameters:
bitMasks- a combination ofMARSHALLING,SUBSTITUTE_*or other bit masks.locale- the locale, ornullif unspecified.timezone- the timezone, ornullif unspecified.schemas- the schemas root URL, ornullif none.versionGML- the GML version, ornull.versionMetadata- the metadata version, ornull.resolver- the resolver in use.converter- the converter in use.logFilter- the object to inform about warnings.
-
-
Method Details
-
getLocale
Returns the locale to use for marshalling, ornullif no locale were explicitly specified.- Specified by:
getLocalein classMarshalContext- Returns:
- the locale in the context of current (un)marshalling process.
- See Also:
-
getTimeZone
Returns the timezone to use for marshalling, ornullif none were explicitly specified.- Specified by:
getTimeZonein classMarshalContext- Returns:
- the timezone in the context of current (un)marshalling process.
-
getVersion
Returns the schema version of the XML document being (un)marshalled. See the super-class javadoc for the list of prefix that we shall support.- Specified by:
getVersionin classMarshalContext- Parameters:
prefix- one of the above-cited prefix.- Returns:
- the version in the context of current (un)marshalling process.
-
current
Returns the context of the XML (un)marshalling currently progressing in the current thread, ornullif none.- Returns:
- the current (un)marshalling context, or
nullif none.
-
push
Sets the locale to the given value. The old locales are remembered and will be restored by the next call topull(). This method can be invoked when marshalling object that need to marshal their children in a different locale, like below:- Parameters:
locale- the locale to set, ornull.
-
pull
public static void pull()Restores the locale which was used prior the call topush(Locale). It is not necessary to invoke this method in afinallyblock. -
isFlagSet
Returnstrueif the given flag is set.- Parameters:
context- the current context, ornullif none.flag- one ofMARSHALLING,SUBSTITUTE_LANGUAGE,SUBSTITUTE_COUNTRYor other bit masks.- Returns:
trueif the given flag is set.
-
isGMLVersion
Returnstrueif the GML version is equal or newer than the specified version. If no GML version was specified, then this method returnstrue, i.e. newest version is assumed.API note: This method is static for the convenience of performing the check for null context.- Parameters:
context- the current context, ornullif none.version- the version to compare to.- Returns:
trueif the GML version is equal or newer than the specified version.- See Also:
-
schema
Returns the base URL of ISO 19115-3 (or other standards) schemas. The valid values are documented in theXML.SCHEMASproperty. If the returned value is not empty, then this method guarantees it ends with'/'.API note: This method is static for the convenience of performing the check for null context.- Parameters:
context- the current context, ornullif none.key- one of the value documented in the "Map key" column ofXML.SCHEMAS.defaultSchema- the value to return if no schema is found for the given key.- Returns:
- the base URL of the schema, or an empty buffer if none were specified.
-
getWrapper
Returns the<gml:*PropertyType>which is wrapping the<gml:*Type>object to (un)marshal, ornullif this information is not provided. The<gml:*PropertyType>element can contains information not found in<gml:*Type>objects like XLink or UUID.Example: before unmarshalling theFor performance reasons, this<gml:OperationParameter>(upper caseO) element below,wrapperwill be set to the temporary object representing<gml:operationParameter>. That adapter provides important information for the SIS<gml:OperationParameter>constructor.wrapperinformation is not provided by default. SeesetWrapper(Context, PropertyType)for more information.- Parameters:
context- the current context, ornullif none.- Returns:
- the
<gml:*PropertyType>which is wrapping the<gml:*Type>object to (un)marshal, ornullif unknown.
-
setWrapper
Invoked byPropertyTypeimplementations for declaring the<gml:*PropertyType>instance which is wrapping the<gml:*Type>object to (un)marshal.For performance reasons, this
wrapperinformation is not provided by default. To get this information, thePropertyTypeimplementation needs to define thebeforeUnmarshal(…)method. For an implementation example, seeCC_OperationParameter.- Parameters:
context- the current context, ornullif none.wrapper- the<gml:*PropertyType>which is wrapping the<gml:*Type>object to (un)marshal, ornullif unknown.
-
getObjectID
If agml:idvalue has already been used for the given object in the current XML document, returns that identifier. Otherwise returnsnull.- Parameters:
context- the current context, ornullif none.object- the object for which to get thegml:id.- Returns:
- the identifier used in the current XML document for the given object, or
nullif none. - Since:
- 0.7
-
getObjectForID
Returns the object for the givengml:id, ornullif none. This association is valid only for the current XML document.- Parameters:
context- the current context, ornullif none.id- the identifier for which to get the object.- Returns:
- the object associated to the given identifier, or
nullif none. - Since:
- 0.7
-
setObjectForID
Returnstrueif the given identifier is available, orfalseif it is used by another object. If this method returnstrue, then the given identifier is associated to the given object for future invocation ofContextmethods. If this method returnsfalse, then the caller is responsible for computing another identifier candidate.- Parameters:
context- the current context, ornullif none.object- the object for which to assign thegml:id.id- the identifier to assign to the given object.- Returns:
trueif the given identifier can be used.- Since:
- 0.7
-
resolver
Returns the reference resolver in use for the current marshalling or unmarshalling process. If no resolver were explicitly set, then this method returnsReferenceResolver.DEFAULT.API note: This method is static for the convenience of performing the check for null context.- Parameters:
context- the current context, ornullif none.- Returns:
- the current reference resolver (never null).
-
converter
Returns the value converter in use for the current marshalling or unmarshalling process. If no converter were explicitly set, then this method returnsValueConverter.DEFAULT.API note: This method is static for the convenience of performing the check for null context.- Parameters:
context- the current context, ornullif none.- Returns:
- the current value converter (never null).
-
warningOccured
public static void warningOccured(Context context, Level level, Class<?> classe, String method, Throwable exception, Class<? extends IndexedResourceBundle> resources, short key, Object... arguments) Sends a warning to the warning listener if there is one, or logs the warning otherwise. In the latter case, this method logs to the given logger.If the given
resourcesisnull, then this method will build the log message from theexception.- Parameters:
context- the current context, ornullif none.level- the logging level.classe- the class to declare as the warning source.method- the name of the method to declare as the warning source.exception- the exception thrown, ornullif none.resources- eitherErrors.class,Messages.classornullfor the exception message.key- the resource keys as one of the constants defined in theKeysinner class.arguments- the arguments to be given toMessageFormatfor formatting the log message.- Since:
- 0.5
-
warningOccured
public static void warningOccured(Context context, Class<?> classe, String method, Class<? extends IndexedResourceBundle> resources, short key, Object... arguments) Convenience method for sending a warning for the given message from theErrorsorMessagesresources. The message will be logged atLevel.WARNING.- Parameters:
context- the current context, ornullif none.classe- the class to declare as the warning source.method- the name of the method to declare as the warning source.resources- eitherErrors.classorMessages.class.key- the resource keys as one of the constants defined in theKeysinner class.arguments- the arguments to be given toMessageFormatfor formatting the log message.- Since:
- 0.5
-
warningOccured
public static void warningOccured(Context context, Class<?> classe, String method, Exception cause, boolean isWarning) Convenience method for sending a warning for the given exception. The logger will be"org.apache.sis.xml".- Parameters:
context- the current context, ornullif none.classe- the class to declare as the warning source.method- the name of the method to declare as the warning source.cause- the exception which occurred.isWarning-trueforLevel.WARNING, orfalseforLevel.FINE.
-
finish
public final void finish()Invoked in afinallyblock when a unmarshalling process is finished.
-