Package org.simpleframework.xml.core
Class CollectionFactory
- java.lang.Object
-
- org.simpleframework.xml.core.Factory
-
- org.simpleframework.xml.core.CollectionFactory
-
class CollectionFactory extends Factory
TheCollectionFactory
is used to create collection instances that are compatible with the field type. This performs resolution of the collection class by firstly consulting the specifiedStrategy
implementation. If the strategy cannot resolve the collection class then this will select a type from the Java Collections framework, if a compatible one exists.
-
-
Constructor Summary
Constructors Constructor Description CollectionFactory(Context context, Type type)
Constructor for theCollectionFactory
object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Class
getConversion(java.lang.Class require)
This is used to convert the provided type to a collection type from the Java Collections framework.java.lang.Object
getInstance()
Creates a collection that is determined from the field type.Instance
getInstance(Value value)
This creates aCollection
instance from the type provided.Instance
getInstance(InputNode node)
Creates the collection to use.private boolean
isCollection(java.lang.Class type)
This determines whether the type provided is a collection type.-
Methods inherited from class org.simpleframework.xml.core.Factory
getConversion, getOverride, getType, isCompatible, isInstantiable, setOverride
-
-
-
-
Constructor Detail
-
CollectionFactory
public CollectionFactory(Context context, Type type)
Constructor for theCollectionFactory
object. This is given the field type as taken from the owning object. The given type is used to determine the collection instance created.- Parameters:
context
- this is the context associated with this factorytype
- this is the class for the owning object
-
-
Method Detail
-
getInstance
public java.lang.Object getInstance() throws java.lang.Exception
Creates a collection that is determined from the field type. This is used for theElementList
to get a collection that does not have any overrides. This must be done as the inline list does not contain an outer element.- Overrides:
getInstance
in classFactory
- Returns:
- a type which is used to instantiate the collection
- Throws:
java.lang.Exception
-
getInstance
public Instance getInstance(InputNode node) throws java.lang.Exception
Creates the collection to use. TheStrategy
object is consulted for the collection 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 collection instantiated for the field
- Throws:
java.lang.Exception
-
getInstance
public Instance getInstance(Value value) throws java.lang.Exception
This creates aCollection
instance from the type provided. If the type provided is abstract or an interface then this can promote the type to a collection type that can be instantiated. This is done by asking the type to convert itself.- Parameters:
value
- the type used to instantiate the collection- Returns:
- this returns a compatible collection instance
- Throws:
java.lang.Exception
-
getConversion
public java.lang.Class getConversion(java.lang.Class require) throws java.lang.Exception
This is used to convert the provided type to a collection type from the Java Collections framework. This will check to see if the type is aList
orSet
and return anArrayList
orHashSet
type. 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
-
isCollection
private boolean isCollection(java.lang.Class type)
This determines whether the type provided is a collection type. If the type is assignable to aCollection
then this returns true, otherwise this returns false.- Parameters:
type
- given to determine whether it is a collection- Returns:
- true if the provided type is a collection type
-
-