Class OperationConverter

  • All Implemented Interfaces:
    com.thoughtworks.xstream.converters.Converter, com.thoughtworks.xstream.converters.ConverterMatcher

    public class OperationConverter
    extends java.lang.Object
    implements com.thoughtworks.xstream.converters.Converter
    A type converter for built-in operations. Background: Similar to delegating singletons also operations must be mapped. Therefore, this class writes the signature to the stream and maps back from the signature.
    Author:
    Holger Eichelberger
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.util.Map<java.lang.String,​Operation> OPERATIONS
      Stores the signature-operation-mappings.
    • Constructor Summary

      Constructors 
      Constructor Description
      OperationConverter()
      Creates an operation converter.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean canConvert​(java.lang.Class cls)
      Determines whether this converter instance handles the given class.
      private static java.lang.String getSignature​(Operation operation)
      Returns the signature of an operation.
      void marshal​(java.lang.Object object, com.thoughtworks.xstream.io.HierarchicalStreamWriter writer, com.thoughtworks.xstream.converters.MarshallingContext context)
      Marshals a given object to the given writer in the specified marshalling context.
      java.lang.Object unmarshal​(com.thoughtworks.xstream.io.HierarchicalStreamReader reader, com.thoughtworks.xstream.converters.UnmarshallingContext context)
      Unmarshals the current object to be read from the given reader in the specified unmarshalling context.
      • Methods inherited from class java.lang.Object

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

      • OPERATIONS

        private static final java.util.Map<java.lang.String,​Operation> OPERATIONS
        Stores the signature-operation-mappings. So far we do not allow operations to be modified dynamically.
    • Constructor Detail

      • OperationConverter

        public OperationConverter()
        Creates an operation converter.
    • Method Detail

      • getSignature

        private static final java.lang.String getSignature​(Operation operation)
        Returns the signature of an operation.
        Parameters:
        operation - the operation to return the signature for
        Returns:
        the signature of operation
      • canConvert

        public boolean canConvert​(java.lang.Class cls)
        Determines whether this converter instance handles the given class.
        Specified by:
        canConvert in interface com.thoughtworks.xstream.converters.ConverterMatcher
        Parameters:
        cls - the class to be tested
        Returns:
        true if this instance handles class (this is only the case if it is an Operation), false else
      • marshal

        public void marshal​(java.lang.Object object,
                            com.thoughtworks.xstream.io.HierarchicalStreamWriter writer,
                            com.thoughtworks.xstream.converters.MarshallingContext context)
        Marshals a given object to the given writer in the specified marshalling context. This method translates a delegating type singleton to a name.
        Specified by:
        marshal in interface com.thoughtworks.xstream.converters.Converter
        Parameters:
        object - the object to be marshalled
        writer - the output stream writer
        context - the marshalling context
      • unmarshal

        public java.lang.Object unmarshal​(com.thoughtworks.xstream.io.HierarchicalStreamReader reader,
                                          com.thoughtworks.xstream.converters.UnmarshallingContext context)
        Unmarshals the current object to be read from the given reader in the specified unmarshalling context. This method translates the name back to the singleton instance.
        Specified by:
        unmarshal in interface com.thoughtworks.xstream.converters.Converter
        Parameters:
        reader - the input stream writer
        context - the marshalling context
        Returns:
        the unmarshalled object