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.
- Version:
- $Id: TypeHandler.java 1677452 2015-05-03 17:10:00Z ggregory $
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Class<?>
createClass
(String classname) Returns the class whose name isclassname
.static Date
createDate
(String str) Returns the date represented bystr
.static File
createFile
(String str) Returns the File represented bystr
.static File[]
createFiles
(String str) Returns the File[] represented bystr
.static Number
createNumber
(String str) Create a number from a String.static Object
createObject
(String classname) Create an Object from the classname and empty constructor.static URL
Returns the URL represented bystr
.static Object
createValue
(String str, Class<?> clazz) Returns theObject
of typeclazz
with the value ofstr
.static Object
createValue
(String str, Object obj) Returns theObject
of typeobj
with the value ofstr
.
-
Constructor Details
-
TypeHandler
public TypeHandler()
-
-
Method Details
-
createValue
Returns theObject
of typeobj
with the value ofstr
.- Parameters:
str
- the command line valueobj
- the type of argument- Returns:
- The instance of
obj
initialised with the value ofstr
. - Throws:
ParseException
- if the value creation for the given object type failed
-
createValue
Returns theObject
of typeclazz
with the value ofstr
.- Parameters:
str
- the command line valueclazz
- the type of argument- Returns:
- The instance of
clazz
initialised with the value ofstr
. - Throws:
ParseException
- if the value creation for the given class failed
-
createObject
Create an Object from the classname and empty constructor.- Parameters:
classname
- the argument value- Returns:
- the initialised object
- Throws:
ParseException
- if the class could not be found or the object could not be created
-
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
- ifstr
is not a number
-
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
str
is a valid date string, otherwise return null. - Throws:
UnsupportedOperationException
- always
-
createURL
Returns the URL represented bystr
.- Parameters:
str
- the URL string- Returns:
- The URL in
str
is well-formed - Throws:
ParseException
- if the URL instr
is not well-formed
-
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
-