com.martiansoftware.jsap.stringparsers
Class FileStringParser

java.lang.Object
  extended bycom.martiansoftware.jsap.StringParser
      extended bycom.martiansoftware.jsap.PropertyStringParser
          extended bycom.martiansoftware.jsap.stringparsers.FileStringParser

public class FileStringParser
extends PropertyStringParser

A StringParser for parsing File objects. The parse() method delegates the actual parsing to new File(String). If new File(String) throws a NullPointerException, it is encapsulated in a ParseException and re-thrown.

Since:
1.4
Author:
Marty Lamb, Edward Glen ([email protected]) (modified URLStringParser), Eric Sword (made setters return "this", fixed bug triggered when file does not exist)
See Also:
StringParser, URL

Field Summary
static String MUSTBEDIRECTORY
           
static String MUSTBEFILE
           
static String MUSTEXIST
           
 
Constructor Summary
FileStringParser()
          Deprecated. use getParser().
 
Method Summary
static FileStringParser getParser()
          Returns a new FileStringParser.
 boolean mustBeDirectory()
           
 boolean mustBeFile()
           
 boolean mustExist()
           
 Object parse(String arg)
          Parses the specified argument into a File.
 FileStringParser setMustBeDirectory(boolean mustBeDirectory)
           
 FileStringParser setMustBeFile(boolean mustBeFile)
           
 FileStringParser setMustExist(boolean mustExist)
           
 void setUp()
          Performs any initialization not handled by this StringParser's constructor.
 void tearDown()
          Performs any cleanup necessary for this StringParser.
 
Methods inherited from class com.martiansoftware.jsap.PropertyStringParser
getProperty, getProperty, setProperty
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MUSTBEFILE

public static final String MUSTBEFILE
See Also:
Constant Field Values

MUSTBEDIRECTORY

public static final String MUSTBEDIRECTORY
See Also:
Constant Field Values

MUSTEXIST

public static final String MUSTEXIST
See Also:
Constant Field Values
Constructor Detail

FileStringParser

public FileStringParser()
Deprecated. use getParser().

Creates a new FileStringParser.

Method Detail

getParser

public static FileStringParser getParser()
Returns a new FileStringParser.

Returns:
a new FileStringParser.

setUp

public void setUp()
           throws ParseException
Description copied from class: StringParser
Performs any initialization not handled by this StringParser's constructor. The contract for this method is that it will be called AT LEAST once before this object's parse() method is called.

In the JSAP API, this method is called every time an Option containing this StringParser is registered with a JSAP. If there is an initialization error, this method should throw a JSAPException to prevent the Option from being registered.

Overrides:
setUp in class StringParser
Throws:
ParseException

setMustBeDirectory

public FileStringParser setMustBeDirectory(boolean mustBeDirectory)

setMustBeFile

public FileStringParser setMustBeFile(boolean mustBeFile)

setMustExist

public FileStringParser setMustExist(boolean mustExist)

mustBeDirectory

public boolean mustBeDirectory()

mustBeFile

public boolean mustBeFile()

mustExist

public boolean mustExist()

tearDown

public void tearDown()
Description copied from class: StringParser
Performs any cleanup necessary for this StringParser. The contract for this method is that it MAY be called at any time after the setUp method has been called. It may be called more than once.

In the JSAP API, this method is called every time an Option containing this StringParser is unregistered from a JSAP. During finalization, any registered Options are unregistered from a JSAP.

Overrides:
tearDown in class StringParser

parse

public Object parse(String arg)
             throws ParseException
Parses the specified argument into a File. This method delegates the actual parsing to new File(arg). If new File(arg) throws a NullPointerException, it is encapsulated in a ParseException and re-thrown.

Specified by:
parse in class StringParser
Parameters:
arg - the argument to parse
Returns:
a File as specified by arg.
Throws:
ParseException - if new File(arg) throws a NullPointerException.
See Also:
File, StringParser.parse(String)


Copyright © 2002-2006, Martian Software, Inc.. All Rights Reserved.
For the latest version and documentation, please visit http://www.martiansoftware.com/jsap