jena.cmdline
Class CommandLine

java.lang.Object
  |
  +--jena.cmdline.CommandLine

public class CommandLine
extends java.lang.Object

Command line argument processing based on a trigger model. An action is called whenever an argument is encountered. Example: public static void main (String[] args) { CommandLine cl = new CommandLine() ; cl.add(false, "verbose") .add(true, "--file") ; cl.process(args) ; for ( Iterator iter = cl.args() ; iter.hasNext() ; ) ... } A gloabl hook is provided to inspect arguments just before the action. Tracing is enabled by setting this to a suitable function such as that provided by trace(): cl.setHook(cl.trace()) ;

Version:
$Id: CommandLine.java,v 1.1 2002/11/27 14:57:12 andy_seaborne Exp $
Author:
Andy Seaborne

Constructor Summary
CommandLine()
          Creates new CommandLine
 
Method Summary
 CommandLine add(ArgDecl arg)
          Add an argument object
 CommandLine add(java.lang.String argName, boolean hasValue)
          Add an argument to those to be accepted on the command line
 java.util.List args()
           
 boolean contains(ArgDecl argDecl)
          Test whether an argument was seen.
 boolean contains(java.lang.String s)
          Test whether an argument was seen.
 Arg getArg(ArgDecl argDecl)
          Get the argument associated with the argurment declaration.
 Arg getArg(java.lang.String s)
           
 java.io.PrintStream getOutput()
           
 java.util.List items()
           
static void main(java.lang.String[] argv)
           
 void process(java.lang.String[] argv)
          Process a set of command line arguments.
 void setHook(ArgHandler argHandler)
          Set the global argument handler.
 void setOutput(java.io.PrintStream out)
          Set the output stream, or null for silent.
 void setUsage(java.lang.String usageMessage)
           
 ArgHandler trace()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CommandLine

public CommandLine()
Creates new CommandLine

Method Detail

setHook

public void setHook(ArgHandler argHandler)
Set the global argument handler. Called on every valid argument.

Parameters:
argHandler - Handler

setOutput

public void setOutput(java.io.PrintStream out)
Set the output stream, or null for silent. Default value is System.err


getOutput

public java.io.PrintStream getOutput()

setUsage

public void setUsage(java.lang.String usageMessage)

args

public java.util.List args()

items

public java.util.List items()

process

public void process(java.lang.String[] argv)
             throws java.lang.IllegalArgumentException
Process a set of command line arguments.

Parameters:
argv - The words of the command line.
Throws:
java.lang.IllegalArgumentException - Throw when something is wrong (no value found, action fails).

contains

public boolean contains(ArgDecl argDecl)
Test whether an argument was seen.


contains

public boolean contains(java.lang.String s)
Test whether an argument was seen.


getArg

public Arg getArg(ArgDecl argDecl)
Get the argument associated with the argurment declaration. Actually retruns the LAST one seen

Parameters:
argDecl - Argument declaration to find
Returns:
Last argument that matched.

getArg

public Arg getArg(java.lang.String s)

add

public CommandLine add(java.lang.String argName,
                       boolean hasValue)
Add an argument to those to be accepted on the command line

Parameters:
argName - Name
Returns:
The CommandLine processor object

add

public CommandLine add(ArgDecl arg)
Add an argument object

Parameters:
arg - Argument to add
Returns:
The CommandLine processor object

trace

public ArgHandler trace()

main

public static void main(java.lang.String[] argv)


Copyright © 2001 Hewlett-Packard. All Rights Reserved.