Class XGlobalAttributeNameMap

  • All Implemented Interfaces:
    XAttributeNameMap

    public class XGlobalAttributeNameMap
    extends java.lang.Object
    implements XAttributeNameMap
    This singleton class implements a global attribute name mapping facility and can manage a number of attribute name mappings. Further, this class also acts as a proxy to the standard mapping, i.e. it can be used directly as a attribute name mapping instance.
    Author:
    Christian W. Guenther (christian@deckfour.org)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String MAPPING_DUTCH
      The attribute name mapping to the Dutch language.
      static java.lang.String MAPPING_ENGLISH
      The attribute name mapping to the English language.
      static java.lang.String MAPPING_FRENCH
      The attribute name mapping to the French language.
      static java.lang.String MAPPING_GERMAN
      The attribute name mapping to the German language.
      static java.lang.String MAPPING_ITALIAN
      The attribute name mapping to the Italian language.
      static java.lang.String MAPPING_PORTUGUESE
      The attribute name mapping to the Portuguese language.
      static java.lang.String MAPPING_SPANISH
      The attribute name mapping to the Spanish language.
      static java.lang.String MAPPING_STANDARD
      The standard attribute name mapping, to the English language (EN).
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Collection<java.lang.String> getAvailableMappingNames()
      Returns the names of all available mappings.
      java.util.Collection<XAttributeNameMap> getAvailableMappings()
      Returns all available mappings.
      XAttributeNameMap getMapping​(java.lang.String name)
      Provides access to a specific attribute name mapping by its name.
      java.lang.String getMappingName()
      Returns the name of this mapping.
      XAttributeNameMap getStandardMapping()
      Retrieves the standard attribute name mapping, i.e.
      static XGlobalAttributeNameMap instance()
      Accesses the singleton instance.
      java.lang.String map​(java.lang.String attributeKey)
      Returns the name mapped onto the provided attribute key by this mapping.
      java.lang.String map​(XAttribute attribute)
      Returns the name mapped onto the provided attribute by this mapping.
      java.lang.String mapSafely​(java.lang.String attributeKey, java.lang.String mappingName)
      Maps an attribute safely, using the given attribute mapping.
      java.lang.String mapSafely​(java.lang.String attributeKey, XAttributeNameMap mapping)
      Maps an attribute safely, using the given attribute mapping.
      java.lang.String mapSafely​(XAttribute attribute, java.lang.String mappingName)
      Maps an attribute safely, using the given attribute mapping.
      java.lang.String mapSafely​(XAttribute attribute, XAttributeNameMap mapping)
      Maps an attribute safely, using the given attribute mapping.
      void registerMapping​(java.lang.String mappingName, java.lang.String attributeKey, java.lang.String alias)
      Registers a known attribute for mapping in a given attribute name map.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • MAPPING_STANDARD

        public static final java.lang.String MAPPING_STANDARD
        The standard attribute name mapping, to the English language (EN).
        See Also:
        Constant Field Values
      • MAPPING_ENGLISH

        public static final java.lang.String MAPPING_ENGLISH
        The attribute name mapping to the English language.
        See Also:
        Constant Field Values
      • MAPPING_GERMAN

        public static final java.lang.String MAPPING_GERMAN
        The attribute name mapping to the German language.
        See Also:
        Constant Field Values
      • MAPPING_DUTCH

        public static final java.lang.String MAPPING_DUTCH
        The attribute name mapping to the Dutch language.
        See Also:
        Constant Field Values
      • MAPPING_FRENCH

        public static final java.lang.String MAPPING_FRENCH
        The attribute name mapping to the French language.
        See Also:
        Constant Field Values
      • MAPPING_ITALIAN

        public static final java.lang.String MAPPING_ITALIAN
        The attribute name mapping to the Italian language.
        See Also:
        Constant Field Values
      • MAPPING_SPANISH

        public static final java.lang.String MAPPING_SPANISH
        The attribute name mapping to the Spanish language.
        See Also:
        Constant Field Values
      • MAPPING_PORTUGUESE

        public static final java.lang.String MAPPING_PORTUGUESE
        The attribute name mapping to the Portuguese language.
        See Also:
        Constant Field Values
    • Method Detail

      • instance

        public static XGlobalAttributeNameMap instance()
        Accesses the singleton instance.
        Returns:
        The global attribute name mapping instance.
      • getAvailableMappingNames

        public java.util.Collection<java.lang.String> getAvailableMappingNames()
        Returns the names of all available mappings. Note that referenced mappings may be empty.
        Returns:
        A collection of names of all available mappings.
      • getAvailableMappings

        public java.util.Collection<XAttributeNameMap> getAvailableMappings()
        Returns all available mappings. Note that returned mappings may be empty.
        Returns:
        A collection of all available mappings.
      • getMapping

        public XAttributeNameMap getMapping​(java.lang.String name)
        Provides access to a specific attribute name mapping by its name. If the requested mapping does not exist yet, a new mapping will be created, added to the set of managed mappings, and returned. This means, this method will always return a mapping, but this could be empty.
        Parameters:
        name - Name of the requested mapping.
        Returns:
        The requested mapping, as stored in this facility (or newly created).
      • getStandardMapping

        public XAttributeNameMap getStandardMapping()
        Retrieves the standard attribute name mapping, i.e. the EN english language mapping.
        Returns:
        The standard mapping.
      • mapSafely

        public java.lang.String mapSafely​(XAttribute attribute,
                                          XAttributeNameMap mapping)
        Maps an attribute safely, using the given attribute mapping. Safe mapping attempts to map the attribute using the given mapping first. If this does not succeed, the standard mapping (EN) will be used for mapping. If no mapping is available in the standard mapping, the original attribute key is returned unchanged. This way, it is always ensured that this method returns a valid string for naming attributes.
        Parameters:
        attribute - Attribute to map.
        mapping - Mapping to be used preferably.
        Returns:
        The safe mapping for the given attribute.
      • mapSafely

        public java.lang.String mapSafely​(java.lang.String attributeKey,
                                          XAttributeNameMap mapping)
        Maps an attribute safely, using the given attribute mapping. Safe mapping attempts to map the attribute using the given mapping first. If this does not succeed, the standard mapping (EN) will be used for mapping. If no mapping is available in the standard mapping, the original attribute key is returned unchanged. This way, it is always ensured that this method returns a valid string for naming attributes.
        Parameters:
        attributeKey - Key of the attribute to map.
        mapping - Mapping to be used preferably.
        Returns:
        The safe mapping for the given attribute key.
      • mapSafely

        public java.lang.String mapSafely​(XAttribute attribute,
                                          java.lang.String mappingName)
        Maps an attribute safely, using the given attribute mapping. Safe mapping attempts to map the attribute using the given mapping first. If this does not succeed, the standard mapping (EN) will be used for mapping. If no mapping is available in the standard mapping, the original attribute key is returned unchanged. This way, it is always ensured that this method returns a valid string for naming attributes.
        Parameters:
        attribute - Attribute to map.
        mappingName - Name of the mapping to be used preferably.
        Returns:
        The safe mapping for the given attribute.
      • mapSafely

        public java.lang.String mapSafely​(java.lang.String attributeKey,
                                          java.lang.String mappingName)
        Maps an attribute safely, using the given attribute mapping. Safe mapping attempts to map the attribute using the given mapping first. If this does not succeed, the standard mapping (EN) will be used for mapping. If no mapping is available in the standard mapping, the original attribute key is returned unchanged. This way, it is always ensured that this method returns a valid string for naming attributes.
        Parameters:
        attributeKey - Key of the attribute to map.
        mappingName - Name of the mapping to be used preferably.
        Returns:
        The safe mapping for the given attribute.
      • registerMapping

        public void registerMapping​(java.lang.String mappingName,
                                    java.lang.String attributeKey,
                                    java.lang.String alias)
        Registers a known attribute for mapping in a given attribute name map. IMPORTANT: This method should only be called when one intends to create, or add to, the global attribute name mapping.
        Parameters:
        mappingName - Name of the mapping to register with.
        attributeKey - Attribute key to be mapped.
        alias - Alias to map the given attribute to.
      • getMappingName

        public java.lang.String getMappingName()
        Description copied from interface: XAttributeNameMap
        Returns the name of this mapping.
        Specified by:
        getMappingName in interface XAttributeNameMap
        Returns:
        The name of this mapping.
      • map

        public java.lang.String map​(XAttribute attribute)
        Description copied from interface: XAttributeNameMap
        Returns the name mapped onto the provided attribute by this mapping. If no mapping for the given attribute is provided by this map, null is returned.
        Specified by:
        map in interface XAttributeNameMap
        Parameters:
        attribute - Attribute to retrieve mapping for.
        Returns:
        The mapping for the given attribute, or null, if no such mapping exists.
      • map

        public java.lang.String map​(java.lang.String attributeKey)
        Description copied from interface: XAttributeNameMap
        Returns the name mapped onto the provided attribute key by this mapping. If no mapping for the given attribute key is provided by this map, null is returned.
        Specified by:
        map in interface XAttributeNameMap
        Parameters:
        attributeKey - Attribute key to retrieve mapping for.
        Returns:
        The mapping for the given attribute key, or null, if no such mapping exists.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object