Class ForNameStringParser
- java.lang.Object
-
- com.martiansoftware.jsap.StringParser
-
- com.martiansoftware.jsap.stringparsers.ForNameStringParser
-
public class ForNameStringParser extends StringParser
AStringParser
that passes the argument to a static method of signatureforName(String)
of a specified class.Note that, for instance, this parser can be used with
Class
(resulting in a string parser identical toClassStringParser
), but alsoCharset
, and more generally, any class using theforName(String)
convention.- Author:
- Sebastiano Vigna
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ForNameStringParser
getParser(Class klass)
Returns a classforName()
string parser.Object
parse(String arg)
Parses the specified argument into an Object of the appropriate type.-
Methods inherited from class com.martiansoftware.jsap.StringParser
setUp, tearDown
-
-
-
-
Method Detail
-
getParser
public static ForNameStringParser getParser(Class klass) throws SecurityException, NoSuchMethodException
Returns a classforName()
string parser.When required to parse an argument, the returned string parser will return the object obtain by means of a call to a static method of
klass
of signatureforName(String)
.- Parameters:
klass
- a class with a static method of signatureforName(String)
.- Throws:
SecurityException
NoSuchMethodException
-
parse
public Object parse(String arg) throws ParseException
Description copied from class:StringParser
Parses the specified argument into an Object of the appropriate type. If the specified argument cannot be converted into the desired Object, a ParseException should be thrown.
Note: this method MAY BE CALLED with a null argument. Take this into consideration when subclassing!- Specified by:
parse
in classStringParser
- Parameters:
arg
- the argument to convert to an Object of class appropriate to the StringParser subclass.- Returns:
- the Object resulting from the parsed argument.
- Throws:
ParseException
- if the specified argument cannot be parsed.
-
-