Package org.simpleframework.xml.core
Class MethodPartFactory
- java.lang.Object
-
- org.simpleframework.xml.core.MethodPartFactory
-
class MethodPartFactory extends java.lang.Object
TheMethodPartFactory
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:
MethodScanner
-
-
Field Summary
Fields Modifier and Type Field Description private AnnotationFactory
factory
This is used to create the synthetic annotations for methods.
-
Constructor Summary
Constructors Constructor Description MethodPartFactory(Detail detail, Support support)
Constructor for theMethodPartFactory
object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.lang.annotation.Annotation
getAnnotation(java.lang.reflect.Method method)
This is used to synthesize an XML annotation given a method.private java.lang.Class[]
getDependents(java.lang.reflect.Method method)
This is used extract the dependents of the method.MethodPart
getInstance(java.lang.reflect.Method method, java.lang.annotation.Annotation[] list)
This is used to acquire aMethodPart
for the method provided.MethodPart
getInstance(java.lang.reflect.Method method, java.lang.annotation.Annotation label, java.lang.annotation.Annotation[] list)
This is used to acquire aMethodPart
for the name and annotation of the provided method.private MethodType
getMethodType(java.lang.reflect.Method method)
This is used to acquire aMethodType
for the name of the method provided.private MethodName
getName(java.lang.reflect.Method method, java.lang.annotation.Annotation label)
This is used to acquire aMethodName
for the name and annotation of the provided method.private java.lang.Class
getParameterType(java.lang.reflect.Method method)
This is the parameter type associated with the provided method.private MethodName
getRead(java.lang.reflect.Method method, MethodType type)
This is used to acquire aMethodName
for the name and annotation of the provided method.private java.lang.Class
getReturnType(java.lang.reflect.Method method)
This is the return type associated with the provided method.java.lang.Class
getType(java.lang.reflect.Method method)
This is used to extract the type from a method.private java.lang.String
getTypeName(java.lang.String name, MethodType type)
This is used to acquire the name of the method in a Java Bean property style.private MethodName
getWrite(java.lang.reflect.Method method, MethodType type)
This is used to acquire aMethodName
for the name and annotation of the provided method.
-
-
-
Field Detail
-
factory
private final AnnotationFactory factory
This is used to create the synthetic annotations for methods.
-
-
Constructor Detail
-
MethodPartFactory
public MethodPartFactory(Detail detail, Support support)
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 Detail
-
getInstance
public MethodPart getInstance(java.lang.reflect.Method method, java.lang.annotation.Annotation[] list) throws java.lang.Exception
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:
java.lang.Exception
-
getInstance
public MethodPart getInstance(java.lang.reflect.Method method, java.lang.annotation.Annotation label, java.lang.annotation.Annotation[] list) throws java.lang.Exception
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:
java.lang.Exception
-
getName
private MethodName getName(java.lang.reflect.Method method, java.lang.annotation.Annotation label) throws java.lang.Exception
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:
java.lang.Exception
-
getMethodType
private MethodType getMethodType(java.lang.reflect.Method method)
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
private java.lang.annotation.Annotation getAnnotation(java.lang.reflect.Method method) throws java.lang.Exception
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:
java.lang.Exception
-
getDependents
private java.lang.Class[] getDependents(java.lang.reflect.Method method) throws java.lang.Exception
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:
java.lang.Exception
-
getType
public java.lang.Class getType(java.lang.reflect.Method method) throws java.lang.Exception
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:
java.lang.Exception
-
getParameterType
private java.lang.Class getParameterType(java.lang.reflect.Method method) throws java.lang.Exception
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:
java.lang.Exception
-
getReturnType
private java.lang.Class getReturnType(java.lang.reflect.Method method) throws java.lang.Exception
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:
java.lang.Exception
-
getRead
private MethodName getRead(java.lang.reflect.Method method, MethodType type) throws java.lang.Exception
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:
java.lang.Exception
-
getWrite
private MethodName getWrite(java.lang.reflect.Method method, MethodType type) throws java.lang.Exception
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:
java.lang.Exception
-
getTypeName
private java.lang.String getTypeName(java.lang.String name, MethodType type)
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
-
-