Package org.apache.sis.internal.jaxb.lan
Class LocaleAndCharset
java.lang.Object
org.apache.sis.internal.jaxb.lan.LocaleAndCharset
- All Implemented Interfaces:
TreeTable.Node
Utility methods for handling
Map<Locale,Charset>
as separated collections.
Locale and character set were separated properties in legacy ISO 19115:2003 but become combined
under a single PT_Locale
entity in ISO 19115:2014. This change is not really convenient
in Java since the standard Locale
and Charset
objects are separated entities.
This class provides two services for managing that:
- Static methods, used mostly for JAXB marshalling and unmarshalling.
- Implementation of
TreeTable.Node
for viewing aMap.Entry<Locale,Charset>
as aLocale
node with aCharset
child. This is used for providing textual representation of metadata.
- Since:
- 1.0
- Version:
- 1.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final class
The only child of the node containing aLocale
value. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final TreeTable.Node
The node containing aMap.Entry<Locale,Charset>
value. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new node for the given entry. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Tests this node with the given object for equality.static Collection
<Charset> getCharacterSets
(Map<Locale, Charset> locales) Returns the character coding standard used for the resource.Returns the list of children, which is implemented by this class itself.static Collection
<Locale> getLanguages
(Map<Locale, Charset> locales) Returns the language(s) used within the resource.Delegates to wrapped node since thisLocaleAndCharset
is a substitute for that node.Returns the user object associated to this node.<V> V
getValue
(TableColumn<V> column) Returns the value associated to the given column of this node.int
hashCode()
Returns a hash code value for this node.boolean
isEditable
(TableColumn<?> column) Considers this node as non-editable since it represents the key in a map, and keys cannot be modified through theMap.Entry
interface.boolean
isLeaf()
Returnsfalse
since this node can have a children, which is theLocaleAndCharset.Child
.private static Object
keyOrValue
(Object object, boolean key) Returns the key or the value of the givenMap.Entry
.newChild()
Creates a new child only if none exists.private <V> V
separateValue
(TableColumn<V> column, boolean key) Implementation ofgetValue(TableColumn)
also used by theLocaleAndCharset.Child
.setCharacterSets
(Map<Locale, Charset> locales, Collection<? extends Charset> newValues) Sets the character coding standard(s) used within the resource.setLanguages
(Map<Locale, Charset> locales, Collection<? extends Locale> newValues) Sets the language(s) used within the resource.<V> void
setValue
(TableColumn<V> column, V value) Always throws an exception since we cannot edit the key of a map entry.
-
Field Details
-
node
The node containing aMap.Entry<Locale,Charset>
value. This is the node to replace by thisLocaleAndCharset
view.
-
-
Constructor Details
-
LocaleAndCharset
Creates a new node for the given entry. The user object associated to the given node must be an instance ofMap.Entry<Locale,Charset>
.- Parameters:
node
- the node to wrap.
-
-
Method Details
-
getParent
Delegates to wrapped node since thisLocaleAndCharset
is a substitute for that node.- Specified by:
getParent
in interfaceTreeTable.Node
- Returns:
- the parent, or
null
if none.
-
isEditable
Considers this node as non-editable since it represents the key in a map, and keys cannot be modified through theMap.Entry
interface. However,LocaleAndCharset.Child
will be editable for the value column.- Specified by:
isEditable
in interfaceTreeTable.Node
- Parameters:
column
- the column to query.- Returns:
true
if the given column is a legal column for thisNode
implementation and the corresponding value is editable, orfalse
otherwise.
-
isLeaf
public boolean isLeaf()Returnsfalse
since this node can have a children, which is theLocaleAndCharset.Child
.- Specified by:
isLeaf
in interfaceTreeTable.Node
- Returns:
true
if this node cannot have any children.
-
keyOrValue
Returns the key or the value of the givenMap.Entry
. If the given object is not a map entry or is null, then it is returned as-is. This latter case should never happen (the object shall always be a non-null map entry), but we nevertheless check for making the code more robust to ill-formed metadata. We apply this tolerance because this method is used (indirectly) fortoString()
implementations, and failure in those methods make debugging more difficult (string representations are often requested when the developer knows that there is a problem to investigate).- Parameters:
object
- the map entry for which to get the key or the value.key
-true
for fetching the key, orfalse
for fetching the value.- Returns:
- the requested key or value, or the given object itself if it is not a map entry.
-
getUserObject
Returns the user object associated to this node. For this node, that object is the key (aLocale
) of the map entry. For theLocaleAndCharset.Child
, the user object will be the value (aCharset
) of the same map entry.- Specified by:
getUserObject
in interfaceTreeTable.Node
- Returns:
- any object stored at this node by the user, or
null
if none.
-
getValue
Returns the value associated to the given column of this node. This method delegates to the wrapped node, then extract the key component of the map entry if the requested column is the value.- Specified by:
getValue
in interfaceTreeTable.Node
- Type Parameters:
V
- the base type of values in the given column.- Parameters:
column
- identifier of the column from which to get the value.- Returns:
- the value in the given column, or
null
if none. - See Also:
-
separateValue
Implementation ofgetValue(TableColumn)
also used by theLocaleAndCharset.Child
. -
setValue
Always throws an exception since we cannot edit the key of a map entry. Attempts to edit other columns than the value column will also cause an exception to be thrown, but the error message provided by the wrapped node is more detailed.- Specified by:
setValue
in interfaceTreeTable.Node
- Type Parameters:
V
- the base type of values in the given column.- Parameters:
column
- identifier of the column into which to set the value.value
- the value to set.- See Also:
-
getChildren
Returns the list of children, which is implemented by this class itself. The children areCharset
values associated to theLocale
. The list contains O or 1 element.- Specified by:
getChildren
in interfaceTreeTable.Node
- Returns:
- the children, or an empty collection if none.
-
newChild
Creates a new child only if none exists.- Specified by:
newChild
in interfaceTreeTable.Node
- Returns:
- the new child.
-
hashCode
public int hashCode()Returns a hash code value for this node.- Specified by:
hashCode
in interfaceTreeTable.Node
- Overrides:
hashCode
in classObject
- Returns:
- a hash code for this node, potentially based on values and children but ignoring parent.
-
equals
Tests this node with the given object for equality. TwoLocaleAndCharset
instances are considered equal if they wrap the same node.- Specified by:
equals
in interfaceTreeTable.Node
- Overrides:
equals
in classObject
- Parameters:
other
- the other object to compare with this node.- Returns:
- whether the two objects are nodes with equal values and equal children, ignoring parents.
-
getLanguages
Returns the language(s) used within the resource. The returned collection supports theadd(Locale)
method in order to enable XML unmarshalling of legacy ISO 19157 metadata documents. That hack is not needed for newer XML documents (ISO 19115-3:2016).- Parameters:
locales
- the map of locales and character sets, ornull
.- Returns:
- language(s) used within the resource, or
null
.
-
getCharacterSets
Returns the character coding standard used for the resource. The returned collection supportsadd(Charset)
method in order to enable XML unmarshalling of legacy ISO 19157 metadata documents. That hack is not be needed for newer (ISO 19115-3:2016) XML documents.- Parameters:
locales
- the map of locales and character sets, ornull
.- Returns:
- character coding standard(s) used, or
null
.
-
setLanguages
public static Map<Locale,Charset> setLanguages(Map<Locale, Charset> locales, Collection<? extends Locale> newValues) Sets the language(s) used within the resource. This method preserves the character sets if possible.- Parameters:
locales
- the map of locales and character sets, ornull
.newValues
- the new languages.- Returns:
- the given map, or a new map if necessary and the given map was null.
-
setCharacterSets
public static Map<Locale,Charset> setCharacterSets(Map<Locale, Charset> locales, Collection<? extends Charset> newValues) Sets the character coding standard(s) used within the resource. Current implementation takes only the firstCharset
and set the encoding of all locales to that character set. This is suboptimal, but this approach is used only for implementation of deprecated methods.- Parameters:
locales
- the map of locales and character sets, ornull
.newValues
- the new character coding standard(s).- Returns:
- the given map, or a new map if necessary and the given map was null.
-