Class ReflectionTypeDescriptorConverter

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

    public class ReflectionTypeDescriptorConverter
    extends java.lang.Object
    implements com.thoughtworks.xstream.converters.Converter
    Converter for the ReflectionTypeDescriptor.
    Author:
    Sass
    • 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 TypeDescriptor<?>[] getAllAttributes​(com.thoughtworks.xstream.io.HierarchicalStreamReader reader, int numberOfAttributes)
      Gets All attributes for maps, sets and collections.
      private TypeDescriptor<?> getMapType​(java.lang.String name, java.lang.String regex)
      Get the map type from the typeRegistry.
      private TypeDescriptor<?> getSequenceType​(java.lang.String name, java.lang.String regex)
      Get the sequence type from the typeRegistry.
      private TypeDescriptor<?> getSetType​(java.lang.String name, java.lang.String regex)
      Get the set type from the typeRegistry.
      private TypeDescriptor<?>[] getType​(java.lang.String name, java.lang.String regex)
      Get type from the typeRegistry.
      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 marshaling context.
      static void setTypeRegistry​(TypeRegistry registry)
      Setter for the type registry.
      private java.lang.String[] splitString​(java.lang.String name, java.lang.String regex)
      Splits a string with a given regex.
      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 unmarshaling context.
      • Methods inherited from class java.lang.Object

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

      • ReflectionTypeDescriptorConverter

        public ReflectionTypeDescriptorConverter()
        Creates a singleton type converter.
    • Method Detail

      • 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 a ReflectionTypeDescriptor class), 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 marshaling context. This method translates a ReflectionTypeDescriptor type singleton to a name.
        Specified by:
        marshal in interface com.thoughtworks.xstream.converters.Converter
        Parameters:
        object - the object to be marshaled
        writer - the output stream writer
        context - the marshaling 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 unmarshaling 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 marshaling context
        Returns:
        the unmarshaled object
      • getAllAttributes

        private TypeDescriptor<?>[] getAllAttributes​(com.thoughtworks.xstream.io.HierarchicalStreamReader reader,
                                                     int numberOfAttributes)
        Gets All attributes for maps, sets and collections.
        Parameters:
        reader - HierarchicalStreamReader
        numberOfAttributes - the number of attributes
        Returns:
        Array of all attribute types
      • getSequenceType

        private TypeDescriptor<?> getSequenceType​(java.lang.String name,
                                                  java.lang.String regex)
                                           throws VilException
        Get the sequence type from the typeRegistry.
        Parameters:
        name - type name
        regex - regex
        Returns:
        SequenceType
        Throws:
        VilException - exception
      • getMapType

        private TypeDescriptor<?> getMapType​(java.lang.String name,
                                             java.lang.String regex)
                                      throws VilException
        Get the map type from the typeRegistry.
        Parameters:
        name - type name
        regex - regex
        Returns:
        MapType
        Throws:
        VilException - exception
      • getSetType

        private TypeDescriptor<?> getSetType​(java.lang.String name,
                                             java.lang.String regex)
                                      throws VilException
        Get the set type from the typeRegistry.
        Parameters:
        name - type name
        regex - regex
        Returns:
        set type
        Throws:
        VilException - exception
      • getType

        private TypeDescriptor<?>[] getType​(java.lang.String name,
                                            java.lang.String regex)
        Get type from the typeRegistry.
        Parameters:
        name - type name
        regex - regex
        Returns:
        TypeDescriptor
      • splitString

        private java.lang.String[] splitString​(java.lang.String name,
                                               java.lang.String regex)
        Splits a string with a given regex.
        Parameters:
        name - the string to be splitted
        regex - the regex used for splitting
        Returns:
        result
      • setTypeRegistry

        public static void setTypeRegistry​(TypeRegistry registry)
        Setter for the type registry.
        Parameters:
        registry - The type registry to be set