Class ReflectionTypeDescriptorConverter
- java.lang.Object
-
- net.ssehub.easy.instantiation.serializer.xml.converter.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.ConverterConverter for theReflectionTypeDescriptor.- Author:
- Sass
-
-
Field Summary
Fields Modifier and Type Field Description private static EASyLoggerFactory.EASyLoggerloggerprivate static java.util.Map<java.lang.String,TypeDescriptor<?>>pseudoTypesprivate static TypeRegistrytypeRegistry
-
Constructor Summary
Constructors Constructor Description ReflectionTypeDescriptorConverter()Creates a singleton type converter.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanConvert(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.voidmarshal(java.lang.Object object, com.thoughtworks.xstream.io.HierarchicalStreamWriter writer, com.thoughtworks.xstream.converters.MarshallingContext context)Marshals a givenobjectto the givenwriterin the specified marshalingcontext.static voidsetTypeRegistry(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.Objectunmarshal(com.thoughtworks.xstream.io.HierarchicalStreamReader reader, com.thoughtworks.xstream.converters.UnmarshallingContext context)Unmarshals the current object to be read from the givenreaderin the specified unmarshalingcontext.
-
-
-
Field Detail
-
logger
private static EASyLoggerFactory.EASyLogger logger
-
typeRegistry
private static TypeRegistry typeRegistry
-
pseudoTypes
private static java.util.Map<java.lang.String,TypeDescriptor<?>> pseudoTypes
-
-
Method Detail
-
canConvert
public boolean canConvert(java.lang.Class cls)
Determines whether this converter instance handles the given class.- Specified by:
canConvertin interfacecom.thoughtworks.xstream.converters.ConverterMatcher- Parameters:
cls- the class to be tested- Returns:
trueif this instance handlesclass(this is only the case if it is a ReflectionTypeDescriptor class),falseelse
-
marshal
public void marshal(java.lang.Object object, com.thoughtworks.xstream.io.HierarchicalStreamWriter writer, com.thoughtworks.xstream.converters.MarshallingContext context)Marshals a givenobjectto the givenwriterin the specified marshalingcontext. This method translates a ReflectionTypeDescriptor type singleton to a name.- Specified by:
marshalin interfacecom.thoughtworks.xstream.converters.Converter- Parameters:
object- the object to be marshaledwriter- the output stream writercontext- 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 givenreaderin the specified unmarshalingcontext. This method translates the name back to the singleton instance.- Specified by:
unmarshalin interfacecom.thoughtworks.xstream.converters.Converter- Parameters:
reader- the input stream writercontext- 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- HierarchicalStreamReadernumberOfAttributes- 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 nameregex- 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 nameregex- 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 nameregex- 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 nameregex- 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 splittedregex- 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
-
-