Class TypeHandler

java.lang.Object
org.apache.commons.cli.TypeHandler

public class TypeHandler extends Object
This is a temporary implementation. TypeHandler will handle the pluggableness of OptionTypes and it will direct all of these types of conversion functionalities to ConvertUtils component in Commons already. BeanUtils I think.
  • Constructor Details

  • Method Details

    • createClass

      public static Class<?> createClass(String className) throws ParseException
      Returns the class whose name is className.
      Parameters:
      className - the class name
      Returns:
      The class if it is found
      Throws:
      ParseException - if the class could not be found
    • createDate

      public static Date createDate(String str)
      Returns the date represented by str.

      This method is not yet implemented and always throws an UnsupportedOperationException.

      Parameters:
      str - the date string
      Returns:
      The date if str is a valid date string, otherwise return null.
      Throws:
      UnsupportedOperationException - always
    • createFile

      public static File createFile(String str)
      Returns the File represented by str.
      Parameters:
      str - the File location
      Returns:
      The file represented by str.
    • createFiles

      public static File[] createFiles(String str)
      Returns the File[] represented by str.

      This method is not yet implemented and always throws an UnsupportedOperationException.

      Parameters:
      str - the paths to the files
      Returns:
      The File[] represented by str.
      Throws:
      UnsupportedOperationException - always
    • createNumber

      public static Number createNumber(String str) throws ParseException
      Create a number from a String. If a '.' is present, it creates a Double, otherwise a Long.
      Parameters:
      str - the value
      Returns:
      the number represented by str
      Throws:
      ParseException - if str is not a number
    • createObject

      public static Object createObject(String className) throws ParseException
      Create an Object from the class name and empty constructor.
      Parameters:
      className - the argument value
      Returns:
      the initialized object
      Throws:
      ParseException - if the class could not be found or the object could not be created
    • createURL

      public static URL createURL(String str) throws ParseException
      Returns the URL represented by str.
      Parameters:
      str - the URL string
      Returns:
      The URL in str is well-formed
      Throws:
      ParseException - if the URL in str is not well-formed
    • createValue

      public static <T> T createValue(String str, Class<T> clazz) throws ParseException
      Returns the Object of type clazz with the value of str.
      Type Parameters:
      T - type of argument
      Parameters:
      str - the command line value
      clazz - the class representing the type of argument
      Returns:
      The instance of clazz initialized with the value of str.
      Throws:
      ParseException - if the value creation for the given class failed
    • createValue

      public static Object createValue(String str, Object obj) throws ParseException
      Returns the Object of type obj with the value of str.
      Parameters:
      str - the command line value
      obj - the type of argument
      Returns:
      The instance of obj initialized with the value of str.
      Throws:
      ParseException - if the value creation for the given object type failed
    • openFile

      public static FileInputStream openFile(String str) throws ParseException
      Returns the opened FileInputStream represented by str.
      Parameters:
      str - the file location
      Returns:
      The file input stream represented by str.
      Throws:
      ParseException - if the file is not exist or not readable