org.apache.shindig.protocol.conversion.xstream
Class InterfaceClassMapper

java.lang.Object
  extended by com.thoughtworks.xstream.mapper.MapperWrapper
      extended by org.apache.shindig.protocol.conversion.xstream.InterfaceClassMapper
All Implemented Interfaces:
com.thoughtworks.xstream.mapper.Mapper

public class InterfaceClassMapper
extends com.thoughtworks.xstream.mapper.MapperWrapper

The InterfaceClassMapper provides the central mapping of the XStream bean converter. It is used by XStream to determine the element names and classes being mapped. This is driven by a number of read only data structures that are injected on creation. The resolution of classes follow the inheritance model. To map all collections to an element we would use the Collection.class as the reference class and then ArrayList and Set would both be mapped to the same element.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.thoughtworks.xstream.mapper.Mapper
com.thoughtworks.xstream.mapper.Mapper.ImplicitCollectionMapping, com.thoughtworks.xstream.mapper.Mapper.Null
 
Constructor Summary
InterfaceClassMapper(WriterStack writerStack, com.thoughtworks.xstream.mapper.Mapper wrapped, List<ClassFieldMapping> elementMappingList, List<ClassFieldMapping> listElementMappingList, List<ImplicitCollectionFieldMapping> itemFieldMappings, com.google.common.collect.Multimap<String,Class<?>> omitMMap, Map<String,Class<?>> elementClassMap)
          Create an Interface Class Mapper with a configuration.
 
Method Summary
 com.thoughtworks.xstream.mapper.Mapper.ImplicitCollectionMapping getImplicitCollectionDefForFieldName(Class itemType, String fieldName)
          
 Class realClass(String elementName)
          Get the real class associated with an element name from the elementMappingList.
 String serializedClass(Class type)
           Get the serialized element name for a specific class.
 void setBaseObject(Object base)
          Set the base object at the start of a serialization, this ensures that the base element type is appropriate for the elements that are contained within the object.
 boolean shouldSerializeMember(Class definedIn, String fieldName)
          Checks to see if the field in a class should be serialized.
 
Methods inherited from class com.thoughtworks.xstream.mapper.MapperWrapper
aliasForAttribute, aliasForAttribute, aliasForSystemAttribute, attributeForAlias, attributeForAlias, attributeForClassDefiningField, attributeForEnumType, attributeForImplementationClass, attributeForReadResolveField, defaultImplementationOf, getConverterFromAttribute, getConverterFromAttribute, getConverterFromAttribute, getConverterFromItemType, getConverterFromItemType, getConverterFromItemType, getFieldNameForItemTypeAndName, getItemTypeForItemFieldName, getLocalConverter, isImmutableValueType, lookupMapperOfType, realMember, serializedMember
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InterfaceClassMapper

public InterfaceClassMapper(WriterStack writerStack,
                            com.thoughtworks.xstream.mapper.Mapper wrapped,
                            List<ClassFieldMapping> elementMappingList,
                            List<ClassFieldMapping> listElementMappingList,
                            List<ImplicitCollectionFieldMapping> itemFieldMappings,
                            com.google.common.collect.Multimap<String,Class<?>> omitMMap,
                            Map<String,Class<?>> elementClassMap)
Create an Interface Class Mapper with a configuration.

Parameters:
writerStack - A thread safe WriterStack implementation connected to the XStream driver and hence all the writers.
wrapped - the base mapper to be wrapped by this wrapper. All mappers must wrap the default mapper.
elementMappingList - A list of element to class mappings specified by ClassFieldMapping Object. This list is priority ordered with the highest priority mappings coming first.
listElementMappingList - A list of element names to use as the base element where there is a collection of the same type objects being serialized.
omitMMap - A Multimap of fields in classes to omit from serialization.
elementClassMap - a map of element names to class types.
Method Detail

setBaseObject

public void setBaseObject(Object base)
Set the base object at the start of a serialization, this ensures that the base element type is appropriate for the elements that are contained within the object. This method only has any effect if the base object is a Collection of some form. other wise this method has no effect on the state. The method is thread safe attaching state to the thread for later retrieval.

Parameters:
base - the base object being serialized.

serializedClass

public String serializedClass(Class type)

Get the serialized element name for a specific class. If this is the first object to be serialized, and it is a collection, then the elements of the collection will have been inspected to determine if the container should have a special name. These names are specified in the listElementMappingList which is specified on construction. If the first element is not found a standard list.container element name is used to contain all the others, this list type is only ever used in the unit tests.

For subsequent elements, the class is mapped directly to a element name at the same level, specified via the elementMappingList which is injected in the constructor. This mapping looks to see if the class in question inherits of extends the classes in the list and uses the element name associated wit the first match.

Specified by:
serializedClass in interface com.thoughtworks.xstream.mapper.Mapper
Overrides:
serializedClass in class com.thoughtworks.xstream.mapper.MapperWrapper
Parameters:
type - the type of the class to the serialized
Returns:
the name of the element that that should be used to contain the class when serialized.
See Also:
MapperWrapper.serializedClass(java.lang.Class)

shouldSerializeMember

public boolean shouldSerializeMember(Class definedIn,
                                     String fieldName)
Checks to see if the field in a class should be serialized. This is controlled buy the omitMMap Multimap which is keyed by the field name. Each entry in the map contains a list of classes where the field name should be excluded from the output.

Specified by:
shouldSerializeMember in interface com.thoughtworks.xstream.mapper.Mapper
Overrides:
shouldSerializeMember in class com.thoughtworks.xstream.mapper.MapperWrapper
Parameters:
definedIn - the class the field is defined in
fieldName - the field being considered
Returns:
true of the field should be serialized false if it should be ignored.
See Also:
MapperWrapper.shouldSerializeMember(java.lang.Class, java.lang.String)

realClass

public Class realClass(String elementName)
Get the real class associated with an element name from the elementMappingList.

Specified by:
realClass in interface com.thoughtworks.xstream.mapper.Mapper
Overrides:
realClass in class com.thoughtworks.xstream.mapper.MapperWrapper
Parameters:
elementName - the name of the element being read.
See Also:
MapperWrapper.realClass(java.lang.String)

getImplicitCollectionDefForFieldName

public com.thoughtworks.xstream.mapper.Mapper.ImplicitCollectionMapping getImplicitCollectionDefForFieldName(Class itemType,
                                                                                                             String fieldName)

Specified by:
getImplicitCollectionDefForFieldName in interface com.thoughtworks.xstream.mapper.Mapper
Overrides:
getImplicitCollectionDefForFieldName in class com.thoughtworks.xstream.mapper.MapperWrapper
See Also:
MapperWrapper.getImplicitCollectionDefForFieldName(java.lang.Class, java.lang.String)


Copyright © 2007-2012. All Rights Reserved.