Class MethodPartFactory

java.lang.Object
org.simpleframework.xml.core.MethodPartFactory

class MethodPartFactory extends Object
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 Details

    • factory

      private final AnnotationFactory factory
      This is used to create the synthetic annotations for methods.
  • Constructor Details

    • MethodPartFactory

      public MethodPartFactory(Detail detail, Support support)
      Constructor for the MethodPartFactory 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 class
      support - this contains various support functions
  • Method Details

    • getInstance

      public MethodPart getInstance(Method method, Annotation[] list) throws Exception
      This is used to acquire a MethodPart 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 for
      list - this is the list of annotations on the method
      Returns:
      this is the method part object for the method
      Throws:
      Exception
    • getInstance

      public MethodPart getInstance(Method method, Annotation label, Annotation[] list) throws Exception
      This is used to acquire a MethodPart 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 for
      label - this is the annotation associated with the method
      list - this is the list of annotations on the method
      Returns:
      this is the method part object for the method
      Throws:
      Exception
    • getName

      private MethodName getName(Method method, Annotation label) throws Exception
      This is used to acquire a MethodName 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 for
      label - this is the annotation associated with the method
      Returns:
      this is the method name object for the method
      Throws:
      Exception
    • getMethodType

      private MethodType getMethodType(Method method)
      This is used to acquire a MethodType 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 Annotation getAnnotation(Method method) throws 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:
      Exception
    • getDependents

      private Class[] getDependents(Method method) throws 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:
      Exception
    • getType

      public Class getType(Method method) throws 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:
      Exception
    • getParameterType

      private Class getParameterType(Method method) throws 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:
      Exception
    • getReturnType

      private Class getReturnType(Method method) throws 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:
      Exception
    • getRead

      private MethodName getRead(Method method, MethodType type) throws Exception
      This is used to acquire a MethodName 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 for
      type - this is the method type to acquire the name for
      Returns:
      this is the method name object for the method
      Throws:
      Exception
    • getWrite

      private MethodName getWrite(Method method, MethodType type) throws Exception
      This is used to acquire a MethodName 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 for
      type - this is the method type to acquire the name for
      Returns:
      this is the method name object for the method
      Throws:
      Exception
    • getTypeName

      private String getTypeName(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 converted
      type - this is the type of method the name represents
      Returns:
      this returns the Java Bean name for the method