Package org.apache.commons.cli
Class TypeHandler
java.lang.Object
org.apache.commons.cli.TypeHandler
TypeHandler will handle the pluggable conversion and verification of Option types. It handles the mapping of classes to bot converters and verifiers. It
provides the default conversion and verification methods when converters and verifiers are not explicitly set.
If Options are serialized and deserialized their converters and verifiers will revert to the defaults defined in this class. To correctly de-serialize Options with custom converters and/or verifiers, using the default serialization methods, this class should be properly configured with the custom converters and verifiers for the specific class.
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a default initialized instance.TypeHandler(Map<Class<?>, Converter<?, ? extends Throwable>> converterMap) Constructs a default initialized instance. -
Method Summary
Modifier and TypeMethodDescriptionstatic Class<?>createClass(String className) Returns the class whose name isclassName.static DatecreateDate(String string) Returns the date represented bystring.Creates a default converter map.static FilecreateFile(String string) Returns the File represented bystring.static File[]createFiles(String string) Deprecated.with no replacementstatic NumbercreateNumber(String string) Deprecated.static ObjectcreateObject(String className) Deprecated.static URLCreates the URL represented bystring.static <T> TcreateValue(String string, Class<T> clazz) Creates the @code Object} of typeclazzwith the value ofstring.static ObjectcreateValue(String string, Object obj) Deprecated.<T> Converter<T,?> getConverter(Class<T> clazz) Gets the registered converter for the the Class, orConverter.DEFAULTif absent.static TypeHandlerGets the default TypeHandler.static FileInputStreamDeprecated.
-
Constructor Details
-
TypeHandler
public TypeHandler()Constructs a default initialized instance. -
TypeHandler
Constructs a default initialized instance.For each entry, that Class' type must match the Converter's first type.
- Parameters:
converterMap- The converter map, not null.- Since:
- 1.7.0
-
-
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 bystring.This method is not yet implemented and always throws an
UnsupportedOperationException.- Parameters:
string- the date string- Returns:
- The date if
stringis a valid date string, otherwise return null.
-
createDefaultMap
Creates a default converter map.- Returns:
- a default converter map.
- Since:
- 1.7.0
-
createFile
Returns the File represented bystring.- Parameters:
string- the File location- Returns:
- The file represented by
string.
-
createFiles
Deprecated.with no replacementCreates the File[] represented bystring.This method is not yet implemented and always throws an
UnsupportedOperationException.- Parameters:
string- the paths to the files- Returns:
- The File[] represented by
string. - Throws:
UnsupportedOperationException- always
-
createNumber
Deprecated.Creates a number from a String. If a '.' is present, it creates a Double, otherwise a Long.- Parameters:
string- the value- Returns:
- the number represented by
string - Throws:
ParseException- ifstringis not a number
-
createObject
Deprecated.Creates 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
Creates the URL represented bystring.- Parameters:
string- the URL string- Returns:
- The URL in
stringis well-formed - Throws:
ParseException- if the URL instringis not well-formed
-
createValue
Creates the @code Object} of typeclazzwith the value ofstring.- Type Parameters:
T- type of argument- Parameters:
string- the command line valueclazz- the class representing the type of argument- Returns:
- The instance of
clazzinitialized with the value ofstring. - Throws:
ParseException- if the value creation for the given class threw an exception.
-
createValue
Deprecated.Creates theObjectof typeobjwith the value ofstring.- Parameters:
string- the command line valueobj- the type of argument- Returns:
- The instance of
objinitialized with the value ofstring. - Throws:
ParseException- if the value creation for the given object type failed
-
getDefault
Gets the default TypeHandler.- Returns:
- the default TypeHandler.
- Since:
- 1.7.0
-
openFile
Deprecated.Returns the opened FileInputStream represented bystring.- Parameters:
string- the file location- Returns:
- The file input stream represented by
string. - Throws:
ParseException- if the file is not exist or not readable
-
getConverter
Gets the registered converter for the the Class, orConverter.DEFAULTif absent.- Type Parameters:
T- The Class parameter type.- Parameters:
clazz- The Class to get the Converter for.- Returns:
- the registered converter if any,
Converter.DEFAULTotherwise. - Since:
- 1.7.0
-