abbot.script
Class ArgumentParser

java.lang.Object
  |
  +--abbot.script.ArgumentParser

public class ArgumentParser
extends Object

Provide parsing of a String into an array of appropriately typed arguments. Arrays are indicated by square brackets, and arguments are separated by commas, e.g.
An empty String array (length zero): "[]"
Three arguments "one,two,three"
An array of three arguments, with embedded comma: "[one\,one,two,three]"
An argument with square brackets: "\[one\]"
A single null argument: "null"


Method Summary
static Object[] eval(Resolver resolver, String[] args, Class[] params)
          Evaluate the given set of arguments into the given set of types.
static Object eval(Resolver resolver, String arg, Class cls)
          Convert the given string into the given class, if possible, using any available parsers if conversion to basic types fails.
static abbot.script.parsers.Parser getParser(Class cls)
          Find a string parser for the given class.
static String[] parseArgumentList(String encodedArgs)
          Convert the given encoded String into an array of Strings.
static String replace(String str, String s1, String s2)
          Replace all instances in the given String of s1 with s2.
static abbot.script.parsers.Parser setParser(Class cls, abbot.script.parsers.Parser parser)
          Set the parser for a given class.
static String substitute(Resolver resolver, String arg)
          Performs property substitutions on the argument priort to evaluating it.
(package private) static String unescapeBrackets(String arg)
           
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

setParser

public static abbot.script.parsers.Parser setParser(Class cls,
                                                    abbot.script.parsers.Parser parser)
Set the parser for a given class. Returns the old one, if any.

getParser

public static abbot.script.parsers.Parser getParser(Class cls)
Find a string parser for the given class. Returns null if none found.

parseArgumentList

public static String[] parseArgumentList(String encodedArgs)
Convert the given encoded String into an array of Strings. Interprets strings of the format "[el1,el2,el3]" to be a single (array) argument.

Explicit commas and square brackets in arguments must be escaped by preceding the character with a backslash ('\'). The strings '(null)' and 'null' are interpreted as the value null.

Explicit spaces should be protected by double quotes, e.g. " an argument bounded by spaces ".


substitute

public static String substitute(Resolver resolver,
                                String arg)
Performs property substitutions on the argument priort to evaluating it. Substitutions are not recursive.

eval

public static Object eval(Resolver resolver,
                          String arg,
                          Class cls)
                   throws IllegalArgumentException,
                          NoSuchReferenceException,
                          ComponentSearchException
Convert the given string into the given class, if possible, using any available parsers if conversion to basic types fails. The Resolver could be a parser, but it would need to adapt automatically to whatever is the current context.

Performs property substitution on the argument prior to evaluating it.


eval

public static Object[] eval(Resolver resolver,
                            String[] args,
                            Class[] params)
                     throws IllegalArgumentException,
                            NoSuchReferenceException,
                            ComponentSearchException
Evaluate the given set of arguments into the given set of types.

unescapeBrackets

static String unescapeBrackets(String arg)

replace

public static String replace(String str,
                             String s1,
                             String s2)
Replace all instances in the given String of s1 with s2.


Copyright © 2002-2003 Timothy Wall. All Rights Reserved.
Abbot is hosted on

SourceForge