Package org.simpleframework.xml.core
Class PrimitiveFactory
- java.lang.Object
-
- org.simpleframework.xml.core.Factory
-
- org.simpleframework.xml.core.PrimitiveFactory
-
- Direct Known Subclasses:
ObjectFactory
class PrimitiveFactory extends Factory
ThePrimitiveFactory
object is used to create objects that are primitive types. This creates primitives and enumerated types when given a string value. The string value is parsed using a matchedTransform
implementation. The transform is then used to convert the object instance to an from a suitable XML representation. Only enumerated types are not transformed using a transform, instead they useEnum.name
.- See Also:
Transformer
-
-
Constructor Summary
Constructors Constructor Description PrimitiveFactory(Context context, Type type)
Constructor for thePrimitiveFactory
object.PrimitiveFactory(Context context, Type type, java.lang.Class override)
Constructor for thePrimitiveFactory
object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
getInstance(java.lang.String text, java.lang.Class type)
This will instantiate an object of the field type using the provided string.Instance
getInstance(InputNode node)
This method will instantiate an object of the field type, or if theStrategy
object can resolve a class from the XML element then this is used instead.java.lang.String
getText(java.lang.Object source)
This is used to acquire a text value for the specified object.-
Methods inherited from class org.simpleframework.xml.core.Factory
getConversion, getInstance, getOverride, getType, isCompatible, isInstantiable, setOverride
-
-
-
-
Constructor Detail
-
PrimitiveFactory
public PrimitiveFactory(Context context, Type type)
Constructor for thePrimitiveFactory
object. This is provided the field type that is to be instantiated. This must be a type that contains aTransform
object, typically this is ajava.lang
primitive object or one of the primitive types such asint
. Also this can be given a class for an enumerated type.- Parameters:
context
- this is the context used by this factorytype
- this is the field type to be instantiated
-
PrimitiveFactory
public PrimitiveFactory(Context context, Type type, java.lang.Class override)
Constructor for thePrimitiveFactory
object. This is provided the field type that is to be instantiated. This must be a type that contains aTransform
object, typically this is ajava.lang
primitive object or one of the primitive types such asint
. Also this can be given a class for an enumerated type.- Parameters:
context
- this is the context used by this factorytype
- this is the field type to be instantiatedoverride
- this is the override used for this primitve
-
-
Method Detail
-
getInstance
public Instance getInstance(InputNode node) throws java.lang.Exception
This method will instantiate an object of the field type, or if theStrategy
object can resolve a class from the XML element then this is used instead. If the resulting type is abstract or an interface then this method throws an exception.- Parameters:
node
- this is the node to check for the override- Returns:
- this returns an instance of the resulting type
- Throws:
java.lang.Exception
-
getInstance
public java.lang.Object getInstance(java.lang.String text, java.lang.Class type) throws java.lang.Exception
This will instantiate an object of the field type using the provided string. Typically this string is transformed in to the type using aTransform
object. However, if the values is an enumeration then its value is created using theEnum.valueOf
method. Also string values typically do not require conversion of any form and are just returned.- Parameters:
text
- this is the value to be transformed to an objecttype
- this is the type of the primitive to instantiate- Returns:
- this returns an instance of the field type
- Throws:
java.lang.Exception
-
getText
public java.lang.String getText(java.lang.Object source) throws java.lang.Exception
This is used to acquire a text value for the specified object. This will convert the object to a string using the transformer so that it can be deserialized from the generate XML document. However if the type is anEnum
type then the text value is taken fromEnum.name
so it can later be deserialized easily using the enumeration class and name.- Parameters:
source
- this is the object instance to get the value of- Returns:
- this returns a string representation of the object
- Throws:
java.lang.Exception
- if the object could not be transformed
-
-