org.omegahat.Environment.Interpreter
Class Options

java.lang.Object
  |
  +--java.util.Dictionary
        |
        +--java.util.Hashtable
              |
              +--java.util.Properties
                    |
                    +--org.omegahat.Environment.Utils.TrimmedProperties
                          |
                          +--org.omegahat.Environment.Interpreter.Options
All Implemented Interfaces:
java.lang.Cloneable, java.util.Map, java.io.Serializable

public class Options
extends TrimmedProperties

A collection of property name-value pairs containing String values that provide access to some evaluator-related properties and a general table into which arbitrary options can be added and retrieved by other objects.

This class processes the different property values by removing leading and trailing white space when the values are set. This simplifies using the property values in many situations.

In addition to retrieving values from its own table, this class optionally allows callers to retrieve values from this or the system properties.

While it is possible, this class should probably not be considered as a location for setting values that other objects can read later in the evaluation of expressions or tasks. A more explicit communication mechanism should be considered as it is relatively easy to use the databases of an evaluator, or extend classes to provide hooks for the information. This is easier than in languages such as S, R, Matlab, etc. due to the seamless boundary between native (Java) and interpreted objects.

See Also:
Serialized Form

Inner classes inherited from class java.util.Map
java.util.Map.Entry
 
Field Summary
static int CONTINUE
           
static int CONTINUE_PROMPT
          Symbolic constant identiying the continuation prompt which is used when we encounter incomplete, but valid input.
 java.lang.String DebugProperty
          The name of the property that controls whether general debugging information is shown or not.
static java.lang.String DefaultPrompt
          The default prompt setting that is copied into instance-specific field of each object of this class.
static int NORMAL
           
protected  boolean parsePrompt
           
protected  boolean parserDebug
          Flag indicating whether we want debugging information regarding the parser displayed or not.
 java.lang.String ParserDebugProperty
          The name of the property controlling whether parsing debugging information is shown.
static int PROMPT
          Symbolic constant identifying the normal prompt.
 
Fields inherited from class org.omegahat.Environment.Utils.TrimmedProperties
booleanStrings, stripQuotes
 
Fields inherited from class java.util.Properties
defaults
 
Constructor Summary
Options()
          Initialize from the standard options list locating the file containing the properties either from the system property OMEGA_CONFIG_FILE value or by reading the contents of the class resource OmegaOptions.
Options(java.io.File file)
          Read the properties and values from the specified File.
Options(java.io.InputStream stream)
          Read the property name and value pairs from the specified input stream.
Options(java.lang.String text)
          Read the contents of the property table from the specified string as a file and if that is not accessible, interpret the text as a collection of property name and value pairs.
 
Method Summary
 java.lang.String getProperty(java.lang.String name)
          Get the value of the specified property looking in this table first and then in the system properties table.
 java.lang.String getProperty(java.lang.String name, boolean systemFirst)
          Retrieve the value of the property with the given name by looking in this table or the system properties, the order of the lookup being controlled by the systemFirst argument.
 java.lang.String getProperty(java.lang.String name, java.lang.String dflt, boolean systemFirst)
          Get the value of the property identified by the specified name by looking in this table or the system properties and returing the dflt value if no value is found.
 void load(java.io.InputStream in)
          Read the property name-value pairs from the specified input stream and process the results removing leading and trailing white space.
 boolean parserDebug()
           
 boolean parserDebug(boolean val)
           
 int processProperties()
          Hook called to examine the values of the properties, setting fields, etc.
 java.lang.String prompt()
          Retrieve the default value for the normal prompt.
 java.lang.String prompt(int which)
          Retrieve the prompt, either the normal or continuation prompt, indicated by the symbolic constant passed as the value for which
 
Methods inherited from class org.omegahat.Environment.Utils.TrimmedProperties
asBoolean, isBoolean, load, merge, merge, parse, processElement, processElements, stringList, stringList, stripQuotes, stripQuotes, trim
 
Methods inherited from class java.util.Properties
getProperty, list, list, propertyNames, save, setProperty, store
 
Methods inherited from class java.util.Hashtable
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, put, putAll, rehash, remove, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

NORMAL

public static int NORMAL

CONTINUE

public static int CONTINUE

DebugProperty

public java.lang.String DebugProperty
The name of the property that controls whether general debugging information is shown or not. This can be specified in the OmegaOptions file (or the file identified by the OMEGA_CONFIG_FILE system property) as a logical value.

ParserDebugProperty

public java.lang.String ParserDebugProperty
The name of the property controlling whether parsing debugging information is shown. Again, this can be set in the file that is used to specify the values for this object.

PROMPT

public static final int PROMPT
Symbolic constant identifying the normal prompt.

CONTINUE_PROMPT

public static final int CONTINUE_PROMPT
Symbolic constant identiying the continuation prompt which is used when we encounter incomplete, but valid input.

DefaultPrompt

public static java.lang.String DefaultPrompt
The default prompt setting that is copied into instance-specific field of each object of this class.

parserDebug

protected boolean parserDebug
Flag indicating whether we want debugging information regarding the parser displayed or not.

parsePrompt

protected boolean parsePrompt
Constructor Detail

Options

public Options()
Initialize from the standard options list locating the file containing the properties either from the system property OMEGA_CONFIG_FILE value or by reading the contents of the class resource OmegaOptions.

Options

public Options(java.io.File file)
Read the properties and values from the specified File.
Parameters:
file - the file containing the property name and values.

Options

public Options(java.lang.String text)
Read the contents of the property table from the specified string as a file and if that is not accessible, interpret the text as a collection of property name and value pairs.
Parameters:
text - the name of a file or the text containing the property name and value pairs.

Options

public Options(java.io.InputStream stream)
Read the property name and value pairs from the specified input stream.
Parameters:
stream - the stream containing the property table.
Method Detail

load

public void load(java.io.InputStream in)
Read the property name-value pairs from the specified input stream and process the results removing leading and trailing white space.
Overrides:
load in class TrimmedProperties

processProperties

public int processProperties()
Hook called to examine the values of the properties, setting fields, etc. based on the values of some of the properties.

prompt

public java.lang.String prompt()
Retrieve the default value for the normal prompt. This is an String which could be an expression which evaluates to a String to be used as the actual prompt value.

prompt

public java.lang.String prompt(int which)
Retrieve the prompt, either the normal or continuation prompt, indicated by the symbolic constant passed as the value for which
Parameters:
which - value indicating which prompt to return, the normal or continuation prompt.
See Also:
NORMAL, CONTINUE_PROMPT

parserDebug

public boolean parserDebug(boolean val)

parserDebug

public boolean parserDebug()

getProperty

public java.lang.String getProperty(java.lang.String name)
Get the value of the specified property looking in this table first and then in the system properties table.
Overrides:
getProperty in class java.util.Properties

getProperty

public java.lang.String getProperty(java.lang.String name,
                                    boolean systemFirst)
Retrieve the value of the property with the given name by looking in this table or the system properties, the order of the lookup being controlled by the systemFirst argument.
Parameters:
systemFirst - control whether we look in this table or the system properties before looking in the other.

getProperty

public java.lang.String getProperty(java.lang.String name,
                                    java.lang.String dflt,
                                    boolean systemFirst)
Get the value of the property identified by the specified name by looking in this table or the system properties and returing the dflt value if no value is found. Which table is examined first - the system or this - is controlled by the argument systemFirst.
Parameters:
name - name of the property being queried
dflt - value to be used if no property is defined with the given name.
systemFirst - flag indicating whether to look in the system properties or this table first. true indicates the system properties should be queried before this table.