Package org.simpleframework.xml.core
Class Signature
- java.lang.Object
-
- org.simpleframework.xml.core.Signature
-
- All Implemented Interfaces:
java.lang.Iterable<Parameter>
class Signature extends java.lang.Object implements java.lang.Iterable<Parameter>
TheSignature
object represents a constructor of parameters iterable in declaration order. This is used so that parameters can be acquired by name for validation. It is also used to create an array ofParameter
objects that can be used to acquire the correct deserialized values to use in order to instantiate the object.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.reflect.Constructor
factory
This is the type that the parameters are created for.private ParameterMap
parameters
This is the map of parameters that this signature uses.private java.lang.Class
type
This is the type that the signature was created for.
-
Constructor Summary
Constructors Constructor Description Signature(java.lang.reflect.Constructor factory)
Constructor for theSignature
object.Signature(java.lang.reflect.Constructor factory, java.lang.Class type)
Constructor for theSignature
object.Signature(Signature signature)
Constructor for theSignature
object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(Parameter parameter)
This will add the provided parameter to the signature.boolean
contains(java.lang.Object key)
This returns true if the signature contains a parameter that is mapped to the specified key.Signature
copy()
This is used to build aSignature
with the given context so that keys are styled.java.lang.Object
create()
This is used to instantiate the object using the default no argument constructor.java.lang.Object
create(java.lang.Object[] list)
This is used to instantiate the object using a constructor that takes deserialized objects as arguments.Parameter
get(int ordinal)
This is used to acquire aParameter
using the position of that parameter within the constructor.Parameter
get(java.lang.Object key)
This is used to acquire the parameter based on its name.java.util.List<Parameter>
getAll()
This is used to acquire an list ofParameter
objects in declaration order.java.lang.Class
getType()
This is the type associated with theSignature
.boolean
isEmpty()
This is used to determine if there are any parameters in the signature.java.util.Iterator<Parameter>
iterator()
This is used to iterate overParameter
objects.Parameter
remove(java.lang.Object key)
This is used to remove a parameter from the signature.void
set(java.lang.Object key, Parameter parameter)
This will add a new mapping to the signature based on the provided key.int
size()
This represents the number of parameters this signature has.java.lang.String
toString()
This is used to acquire a descriptive name for the instantiator.
-
-
-
Field Detail
-
parameters
private final ParameterMap parameters
This is the map of parameters that this signature uses.
-
factory
private final java.lang.reflect.Constructor factory
This is the type that the parameters are created for.
-
type
private final java.lang.Class type
This is the type that the signature was created for.
-
-
Constructor Detail
-
Signature
public Signature(Signature signature)
Constructor for theSignature
object. This is used to create a hash map that can be used to acquire parameters by name. It also provides the parameters in declaration order within a for each loop.- Parameters:
signature
- this is the signature to be copied
-
Signature
public Signature(java.lang.reflect.Constructor factory)
Constructor for theSignature
object. This is used to create a hash map that can be used to acquire parameters by name. It also provides the parameters in declaration order within a for each loop.- Parameters:
factory
- this is the constructor this represents
-
Signature
public Signature(java.lang.reflect.Constructor factory, java.lang.Class type)
Constructor for theSignature
object. This is used to create a hash map that can be used to acquire parameters by name. It also provides the parameters in declaration order within a for each loop.- Parameters:
factory
- this is the constructor this representstype
- this is the type the map is created for
-
-
Method Detail
-
size
public int size()
This represents the number of parameters this signature has. A signature with no parameters is the default no argument constructor, anything else is a candidate for injection.- Returns:
- this returns the number of annotated parameters
-
isEmpty
public boolean isEmpty()
This is used to determine if there are any parameters in the signature. If the signature contains no parameters then this will return true, if it does then this returns false.- Returns:
- this returns true of the signature has no parameters
-
contains
public boolean contains(java.lang.Object key)
This returns true if the signature contains a parameter that is mapped to the specified key. If no parameter exists with this key then this will return false.- Parameters:
key
- this is the key the parameter is mapped to- Returns:
- this returns true if there is a parameter mapping
-
iterator
public java.util.Iterator<Parameter> iterator()
This is used to iterate overParameter
objects. Parameters are iterated in the order that they are added to the map. This is primarily used for convenience iteration.- Specified by:
iterator
in interfacejava.lang.Iterable<Parameter>
- Returns:
- this returns an iterator for the parameters
-
remove
public Parameter remove(java.lang.Object key)
This is used to remove a parameter from the signature. This returns any parameter removed if it exists, if not then this returns null. This is used when performing matching.- Parameters:
key
- this is the key of the parameter to remove- Returns:
- this returns the parameter that was removed
-
get
public Parameter get(int ordinal)
This is used to acquire aParameter
using the position of that parameter within the constructor. This allows a builder to determine which parameters to use.- Parameters:
ordinal
- this is the position of the parameter- Returns:
- this returns the parameter for the position
-
get
public Parameter get(java.lang.Object key)
This is used to acquire the parameter based on its name. This is used for convenience when the parameter name needs to be matched up with an annotated field or method.- Parameters:
key
- this is the key of the parameter to acquire- Returns:
- this is the parameter mapped to the given name
-
getAll
public java.util.List<Parameter> getAll()
This is used to acquire an list ofParameter
objects in declaration order. This list will help with the resolution of the correct constructor for deserialization of the XML. It also provides a faster method of iteration.- Returns:
- this returns the parameters in declaration order
-
add
public void add(Parameter parameter)
This will add the provided parameter to the signature. The parameter is added to the signature mapped to the key of the parameter. If the key is null it is not added.- Parameters:
parameter
- this is the parameter to be added
-
set
public void set(java.lang.Object key, Parameter parameter)
This will add a new mapping to the signature based on the provided key. Adding a mapping to a parameter using something other than the key for the parameter allows for resolution of the parameter based on a path or a name if desired.- Parameters:
key
- this is the key to map the parameter toparameter
- this is the parameter to be mapped
-
create
public java.lang.Object create() throws java.lang.Exception
This is used to instantiate the object using the default no argument constructor. If for some reason the object can not be instantiated then this will throw an exception with the reason.- Returns:
- this returns the object that has been instantiated
- Throws:
java.lang.Exception
-
create
public java.lang.Object create(java.lang.Object[] list) throws java.lang.Exception
This is used to instantiate the object using a constructor that takes deserialized objects as arguments. The objects that have been deserialized are provided in declaration order so they can be passed to the constructor to instantiate the object.- Parameters:
list
- this is the list of objects used for instantiation- Returns:
- this returns the object that has been instantiated
- Throws:
java.lang.Exception
-
copy
public Signature copy() throws java.lang.Exception
This is used to build aSignature
with the given context so that keys are styled. This allows serialization to match styled element names or attributes to ensure that they can be used to acquire the parameters.- Returns:
- this returns a signature with styled keys
- Throws:
java.lang.Exception
-
getType
public java.lang.Class getType()
This is the type associated with theSignature
. All instances returned from this creator will be of this type.- Returns:
- this returns the type associated with the signature
-
toString
public java.lang.String toString()
This is used to acquire a descriptive name for the instantiator. Providing a name is useful in debugging and when exceptions are thrown as it describes the constructor the instantiator represents.- Overrides:
toString
in classjava.lang.Object
- Returns:
- this returns the name of the constructor to be used
-
-