Package org.apache.commons.cli
Class TypeHandler
java.lang.Object
org.apache.commons.cli.TypeHandler
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Class<?> createClass(String className) Returns the class whose name isclassName.static DatecreateDate(String str) Returns the date represented bystr.static FilecreateFile(String str) Returns the File represented bystr.static File[]createFiles(String str) Returns the File[] represented bystr.static NumbercreateNumber(String str) Create a number from a String.static ObjectcreateObject(String className) Create an Object from the class name and empty constructor.static URLReturns the URL represented bystr.static <T> TcreateValue(String str, Class<T> clazz) Returns theObjectof typeclazzwith the value ofstr.static ObjectcreateValue(String str, Object obj) Returns theObjectof typeobjwith the value ofstr.static FileInputStreamReturns the opened FileInputStream represented bystr.
-
Constructor Details
-
TypeHandler
public TypeHandler()
-
-
Method Details
-
createClass
Returns the class whose name isclassName.- Parameters:
className- the class name- Returns:
- The class if it is found
- Throws:
ParseException- if the class could not be found
-
createDate
Returns the date represented bystr.This method is not yet implemented and always throws an
UnsupportedOperationException.- Parameters:
str- the date string- Returns:
- The date if
stris a valid date string, otherwise return null. - Throws:
UnsupportedOperationException- always
-
createFile
Returns the File represented bystr.- Parameters:
str- the File location- Returns:
- The file represented by
str.
-
createFiles
Returns the File[] represented bystr.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
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- ifstris not a number
-
createObject
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
Returns the URL represented bystr.- Parameters:
str- the URL string- Returns:
- The URL in
stris well-formed - Throws:
ParseException- if the URL instris not well-formed
-
createValue
Returns theObjectof typeclazzwith the value ofstr.- Type Parameters:
T- type of argument- Parameters:
str- the command line valueclazz- the class representing the type of argument- Returns:
- The instance of
clazzinitialized with the value ofstr. - Throws:
ParseException- if the value creation for the given class failed
-
createValue
Returns theObjectof typeobjwith the value ofstr.- Parameters:
str- the command line valueobj- the type of argument- Returns:
- The instance of
objinitialized with the value ofstr. - Throws:
ParseException- if the value creation for the given object type failed
-
openFile
Returns the opened FileInputStream represented bystr.- Parameters:
str- the file location- Returns:
- The file input stream represented by
str. - Throws:
ParseException- if the file is not exist or not readable
-