Package org.simpleframework.xml.core
Class MapFactory
- java.lang.Object
-
- org.simpleframework.xml.core.Factory
-
- org.simpleframework.xml.core.MapFactory
-
class MapFactory extends Factory
TheMapFactoryis used to create map instances that are compatible with the field type. This performs resolution of the map class by consulting the specifiedStrategyimplementation. If the strategy cannot resolve the map class then this will select a type from the Java Collections framework, if a compatible one exists.
-
-
Constructor Summary
Constructors Constructor Description MapFactory(Context context, Type type)Constructor for theMapFactoryobject.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.ClassgetConversion(java.lang.Class require)This is used to convert the provided type to a map object type from the Java Collections framework.java.lang.ObjectgetInstance()Creates a map object that is determined from the field type.InstancegetInstance(Value value)This creates aMapobject instance from the type provided.InstancegetInstance(InputNode node)Creates the map object to use.private booleanisMap(java.lang.Class type)This determines whether the type provided is a object map type.-
Methods inherited from class org.simpleframework.xml.core.Factory
getConversion, getOverride, getType, isCompatible, isInstantiable, setOverride
-
-
-
-
Constructor Detail
-
MapFactory
public MapFactory(Context context, Type type)
Constructor for theMapFactoryobject. This is given the field type as taken from the owning object. The given type is used to determine the map instance created.- Parameters:
context- this is the context object for this factorytype- this is the class for the owning object
-
-
Method Detail
-
getInstance
public java.lang.Object getInstance() throws java.lang.ExceptionCreates a map object that is determined from the field type. This is used for theElementMapto get a map that does not have any overrides. This must be done as the inline list does not contain an outer element.- Overrides:
getInstancein classFactory- Returns:
- a type which is used to instantiate the map
- Throws:
java.lang.Exception
-
getInstance
public Instance getInstance(InputNode node) throws java.lang.Exception
Creates the map object to use. TheStrategyobject is consulted for the map object class, if one is not resolved by the strategy implementation or if the collection resolved is abstract then the Java Collections framework is consulted.- Parameters:
node- this is the input node representing the list- Returns:
- this is the map object instantiated for the field
- Throws:
java.lang.Exception
-
getInstance
public Instance getInstance(Value value) throws java.lang.Exception
This creates aMapobject instance from the type provided. If the type provided is abstract or an interface then this can promote the type to a map object type that can be instantiated. This is done by asking the type to convert itself.- Parameters:
value- the type used to instantiate the map object- Returns:
- this returns a compatible map object instance
- Throws:
java.lang.Exception
-
getConversion
public java.lang.Class getConversion(java.lang.Class require) throws java.lang.ExceptionThis is used to convert the provided type to a map object type from the Java Collections framework. This will check to see if the type is aMaporSortedMapand return aHashMaporTreeSettype. If no suitable match can be found this throws an exception.- Parameters:
require- this is the type that is to be converted- Returns:
- a collection that is assignable to the provided type
- Throws:
java.lang.Exception
-
isMap
private boolean isMap(java.lang.Class type)
This determines whether the type provided is a object map type. If the type is assignable to aMapobject then this returns true, otherwise this returns false.- Parameters:
type- given to determine whether it is a map type- Returns:
- true if the provided type is a map object type
-
-