Package org.simpleframework.xml.core
Class MethodPartFactory
java.lang.Object
org.simpleframework.xml.core.MethodPartFactory
The
MethodPartFactory
is used to create method parts
based on the method signature and the XML annotation. This is
effectively where a method is classified as either a getter or a
setter method within an object. In order to determine the type of
method the method name is checked to see if it is prefixed with
either the "get", "is", or "set" tokens.
Once the method is determined to be a Java Bean method according to conventions the method signature is validated. If the method signature does not follow a return type with no arguments for the get method, and a single argument for the set method then this will throw an exception.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AnnotationFactory
This is used to create the synthetic annotations for methods. -
Constructor Summary
ConstructorsConstructorDescriptionMethodPartFactory
(Detail detail, Support support) Constructor for theMethodPartFactory
object. -
Method Summary
Modifier and TypeMethodDescriptionprivate Annotation
getAnnotation
(Method method) This is used to synthesize an XML annotation given a method.private Class[]
getDependents
(Method method) This is used extract the dependents of the method.getInstance
(Method method, Annotation[] list) This is used to acquire aMethodPart
for the method provided.getInstance
(Method method, Annotation label, Annotation[] list) This is used to acquire aMethodPart
for the name and annotation of the provided method.private MethodType
getMethodType
(Method method) This is used to acquire aMethodType
for the name of the method provided.private MethodName
getName
(Method method, Annotation label) This is used to acquire aMethodName
for the name and annotation of the provided method.private Class
getParameterType
(Method method) This is the parameter type associated with the provided method.private MethodName
getRead
(Method method, MethodType type) This is used to acquire aMethodName
for the name and annotation of the provided method.private Class
getReturnType
(Method method) This is the return type associated with the provided method.This is used to extract the type from a method.private String
getTypeName
(String name, MethodType type) This is used to acquire the name of the method in a Java Bean property style.private MethodName
getWrite
(Method method, MethodType type) This is used to acquire aMethodName
for the name and annotation of the provided method.
-
Field Details
-
factory
This is used to create the synthetic annotations for methods.
-
-
Constructor Details
-
MethodPartFactory
Constructor for theMethodPartFactory
object. This is used to create method parts based on the method signature and the XML annotation is uses. The created part can be used to either set or get values depending on its type.- Parameters:
detail
- this contains details for the annotated classsupport
- this contains various support functions
-
-
Method Details
-
getInstance
This is used to acquire aMethodPart
for the method provided. This will synthesize an XML annotation to be used for the method. If the method provided is not a setter or a getter then this will return null, otherwise it will return a part with a synthetic XML annotation. In order to be considered a valid method the Java Bean conventions must be followed by the method.- Parameters:
method
- this is the method to acquire the part forlist
- this is the list of annotations on the method- Returns:
- this is the method part object for the method
- Throws:
Exception
-
getInstance
This is used to acquire aMethodPart
for the name and annotation of the provided method. This will determine the method type by examining its signature. If the method follows Java Bean conventions then either a setter method part or a getter method part is returned. If the method does not comply with the conventions an exception is thrown.- Parameters:
method
- this is the method to acquire the part forlabel
- this is the annotation associated with the methodlist
- this is the list of annotations on the method- Returns:
- this is the method part object for the method
- Throws:
Exception
-
getName
This is used to acquire aMethodName
for the name and annotation of the provided method. This will determine the method type by examining its signature. If the method follows Java Bean conventions then either a setter method name or a getter method name is returned. If the method does not comply with the conventions an exception is thrown.- Parameters:
method
- this is the method to acquire the name forlabel
- this is the annotation associated with the method- Returns:
- this is the method name object for the method
- Throws:
Exception
-
getMethodType
This is used to acquire aMethodType
for the name of the method provided. This will determine the method type by examining its prefix. If the name follows Java Bean conventions then either a setter method type is returned. If the name does not comply with the naming conventions then null is returned.- Parameters:
method
- this is the method to acquire the type for- Returns:
- this is the method name object for the method
-
getAnnotation
This is used to synthesize an XML annotation given a method. The provided method must follow the Java Bean conventions and either be a getter or a setter. If this criteria is satisfied then a suitable XML annotation is created to be used. Typically a match is performed on whether the method type is a Java collection or an array, if neither criteria are true a normal XML element is used. Synthesizing in this way ensures the best results.- Parameters:
method
- this is the method to extract the annotation for- Returns:
- an XML annotation or null if the method is not suitable
- Throws:
Exception
-
getDependents
This is used extract the dependents of the method. Extracting the dependents in this way ensures that they can be used when creating a default annotation. Any default annotation can then create the optimal attributes for the method it represents.- Parameters:
method
- this is the method to acquire the dependents for- Returns:
- this returns the dependents for the method
- Throws:
Exception
-
getType
This is used to extract the type from a method. Type type of a method is the return type for a getter and a parameter type for a setter. Such a parameter will only be returned if the method observes the Java Bean conventions for a property method.- Parameters:
method
- this is the method to acquire the type for- Returns:
- this returns the type associated with the method
- Throws:
Exception
-
getParameterType
This is the parameter type associated with the provided method. The first parameter is returned if the provided method is a setter. If the method takes more than one parameter or if it takes no parameters then null is returned from this.- Parameters:
method
- this is the method to get the parameter type for- Returns:
- this returns the parameter type associated with it
- Throws:
Exception
-
getReturnType
This is the return type associated with the provided method. The return type of the method is provided only if the method adheres to the Java Bean conventions regarding getter methods. If the method takes a parameter then this will return null.- Parameters:
method
- this is the method to get the return type for- Returns:
- this returns the return type associated with it
- Throws:
Exception
-
getRead
This is used to acquire aMethodName
for the name and annotation of the provided method. This must be a getter method, and so must have a return type that is not void and have not arguments. If the method has arguments an exception is thrown, if not the Java Bean method name is provided.- Parameters:
method
- this is the method to acquire the name fortype
- this is the method type to acquire the name for- Returns:
- this is the method name object for the method
- Throws:
Exception
-
getWrite
This is used to acquire aMethodName
for the name and annotation of the provided method. This must be a setter method, and so must accept a single argument, if it contains more or less than one argument an exception is thrown. return type that is not void and- Parameters:
method
- this is the method to acquire the name fortype
- this is the method type to acquire the name for- Returns:
- this is the method name object for the method
- Throws:
Exception
-
getTypeName
This is used to acquire the name of the method in a Java Bean property style. Thus any "get", "is", or "set" prefix is removed from the name and the following character is changed to lower case if it does not represent an acronym.- Parameters:
name
- this is the name of the method to be convertedtype
- this is the type of method the name represents- Returns:
- this returns the Java Bean name for the method
-