Class StaticNameCoder

java.lang.Object
com.thoughtworks.xstream.io.naming.StaticNameCoder
All Implemented Interfaces:
NameCoder

public class StaticNameCoder extends Object implements NameCoder
A NameCoder that encodes and decodes names based on a map.

The provided map should contain a mapping between the name of the Java type or field to the proper element in the target format. If a name cannot be found in the map, it is assumed not to be mapped at all. Note that the values of the map should be unique also, otherwise the decoding will produce wrong results.

Since:
1.4
  • Field Details

    • java2Node

      private final Map java2Node
    • java2Attribute

      private final Map java2Attribute
    • node2Java

      private transient Map node2Java
    • attribute2Java

      private transient Map attribute2Java
  • Constructor Details

    • StaticNameCoder

      public StaticNameCoder(Map java2Node, Map java2Attribute)
      Construct a StaticNameCoder.
      Parameters:
      java2Node - mapping of Java names to nodes
      java2Attribute - mapping of Java names to attributes
      Since:
      1.4
  • Method Details

    • decodeAttribute

      public String decodeAttribute(String attributeName)
      Decode an attribute name to an object name.
      Specified by:
      decodeAttribute in interface NameCoder
      Parameters:
      attributeName - the name of the attribute
      Returns:
      the name of the meta-data
    • decodeNode

      public String decodeNode(String nodeName)
      Decode a node name to an object name.
      Specified by:
      decodeNode in interface NameCoder
      Parameters:
      nodeName - the name of the node
      Returns:
      the name of the object
    • encodeAttribute

      public String encodeAttribute(String name)
      Encode a meta-data name for an attribute in the target format.
      Specified by:
      encodeAttribute in interface NameCoder
      Parameters:
      name - the name of the meta-data
      Returns:
      the attribute name in the target format
    • encodeNode

      public String encodeNode(String name)
      Encode an object name for a node in the target format.
      Specified by:
      encodeNode in interface NameCoder
      Parameters:
      name - the name of the object data
      Returns:
      the node name in the target format
    • readResolve

      private Object readResolve()
    • invertMap

      private Map invertMap(Map map)