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.Nodefor viewing aMap.Entry<Locale,Charset>as aLocalenode with aCharsetchild. This is used for providing textual representation of metadata.
- Since:
- 1.0
- Version:
- 1.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final classThe only child of the node containing aLocalevalue. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final TreeTable.NodeThe node containing aMap.Entry<Locale,Charset>value. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new node for the given entry. -
Method Summary
Modifier and TypeMethodDescriptionbooleanTests 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 thisLocaleAndCharsetis a substitute for that node.Returns the user object associated to this node.<V> VgetValue(TableColumn<V> column) Returns the value associated to the given column of this node.inthashCode()Returns a hash code value for this node.booleanisEditable(TableColumn<?> column) Considers this node as non-editable since it represents the key in a map, and keys cannot be modified through theMap.Entryinterface.booleanisLeaf()Returnsfalsesince this node can have a children, which is theLocaleAndCharset.Child.private static ObjectkeyOrValue(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> VseparateValue(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> voidsetValue(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 thisLocaleAndCharsetview.
-
-
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 thisLocaleAndCharsetis a substitute for that node.- Specified by:
getParentin interfaceTreeTable.Node- Returns:
- the parent, or
nullif none.
-
isEditable
Considers this node as non-editable since it represents the key in a map, and keys cannot be modified through theMap.Entryinterface. However,LocaleAndCharset.Childwill be editable for the value column.- Specified by:
isEditablein interfaceTreeTable.Node- Parameters:
column- the column to query.- Returns:
trueif the given column is a legal column for thisNodeimplementation and the corresponding value is editable, orfalseotherwise.
-
isLeaf
public boolean isLeaf()Returnsfalsesince this node can have a children, which is theLocaleAndCharset.Child.- Specified by:
isLeafin interfaceTreeTable.Node- Returns:
trueif 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-truefor fetching the key, orfalsefor 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:
getUserObjectin interfaceTreeTable.Node- Returns:
- any object stored at this node by the user, or
nullif 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:
getValuein 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
nullif 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:
setValuein 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 areCharsetvalues associated to theLocale. The list contains O or 1 element.- Specified by:
getChildrenin interfaceTreeTable.Node- Returns:
- the children, or an empty collection if none.
-
newChild
Creates a new child only if none exists.- Specified by:
newChildin interfaceTreeTable.Node- Returns:
- the new child.
-
hashCode
public int hashCode()Returns a hash code value for this node.- Specified by:
hashCodein interfaceTreeTable.Node- Overrides:
hashCodein 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. TwoLocaleAndCharsetinstances are considered equal if they wrap the same node.- Specified by:
equalsin interfaceTreeTable.Node- Overrides:
equalsin 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 firstCharsetand 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.
-