pds.ruleset
Class PPIRuleset

java.lang.Object
  |
  +--pds.ruleset.PPIRuleset

public class PPIRuleset
extends java.lang.Object

PPIRuleset is a class that contians methods for parsing and running rulesets and generating output which defined by the ruleset. A ruleset can be defined in a file or be generated by external applications. Templates are used to determine the form and structure of any output generated.

Since:
1.0

Field Summary
 java.util.ArrayList mActionList
          The list of elements in the label
 int mLineCount
          Tracks which line in a file (or list) is currently being processed
 int mOptionEqualAt
          Indicates the alignment position of the equal sign following a keyword.
 boolean mOptionForceUpper
          Indicates that file names will be forced to uppercase
 int mOptionIndent
          Indicates the number of spaces to pad the beginning of a line which has been wrapped.
 boolean mOptionPadFile
          Indicates whether to pad the output file.
 int mOptionPadWidth
          Indicates tThe width in characters to pad each line in a file.
 int mOptionWrapLine
          Indicates the width in characters that each line will be wrapped
 java.lang.String mOutputName
          The name for the output file
 java.lang.String mSourceName
          The name of the ruleset source
 pds.label.PDSLabel mTemplate
          The current label template
 java.util.ArrayList mVariableList
          The list of variables defined during the execution of a rule set
 boolean mWriteOutput
          The name of the ruleset source
 
Constructor Summary
PPIRuleset()
          Creates an instance of a Ruleset
 
Method Summary
 java.util.ArrayList argSplit(java.lang.String buffer)
          Split a string into one or more substrings by parsing on whitespace.
 boolean convertYesNo(java.lang.String value)
          Converts a string to a boolean state.
 void dump(boolean doAction)
          Prints out the current rule set in tokenized form.
 boolean evalCondition(java.util.ArrayList stack)
          Evaluate a condition that is coded into a array.
 boolean findAndSet(pds.ruleset.PPIVariable variable)
          Finds a variable in the variable list and set its value.
 boolean findAndSet(java.lang.String name, java.lang.String value)
          Finds a variable in the variable list and set its value.
 java.lang.String getValue(java.lang.String name)
          Finds a variable in the variable list and returns its value.
 java.lang.String getValue(java.lang.String name, boolean blank)
          Finds a variable in the variable list and returns its value.
 java.lang.String makeRegex(java.lang.String pattern)
          Converts a string to a regular expression pattern.
static java.lang.String makeRule(int type, java.lang.String arg1, java.lang.String arg2)
          Creates a syntactically correct rule with the parameters passed.
 void output()
          Writes the template to the output files.
 boolean parse(java.lang.String pathName)
          Parses a file containing a ruleset into its constitute elments.
 boolean parseLine(java.lang.String buffer)
          Parses a string containing a single ruleset into its constitute elments.
 java.lang.String readLine(java.io.FileInputStream file)
          Parses the next line from a file stream.
 java.lang.String replaceVariable(java.lang.String buffer)
          Searches the passed string for variables and replaces each variable with its current value.
 void reset()
          Clear all variables, rules and states in the ruleset.
 boolean run(java.lang.String pathname)
          Run the current rule set.
 void setOption(java.lang.String name, java.lang.String value)
          Sets the value of an option.
static void show(java.lang.String message)
          Prints text to the display.
 void showMessage(boolean location, java.lang.String message)
          Prints and error message to the display.
static void showRule(int type, java.lang.String arg1)
          Prints text to the display.
static void showRule(int type, java.lang.String arg1, java.lang.String arg2)
          Prints text to the display.
 java.lang.String unquote(java.lang.String buffer)
          Removes quotes from a string if the string starts with and ends with a quote character (").
 void update()
          Update the current template by replacing all variables with the defined values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mActionList

public java.util.ArrayList mActionList
The list of elements in the label


mVariableList

public java.util.ArrayList mVariableList
The list of variables defined during the execution of a rule set


mTemplate

public pds.label.PDSLabel mTemplate
The current label template


mOptionPadFile

public boolean mOptionPadFile
Indicates whether to pad the output file.


mOptionPadWidth

public int mOptionPadWidth
Indicates tThe width in characters to pad each line in a file.


mOptionIndent

public int mOptionIndent
Indicates the number of spaces to pad the beginning of a line which has been wrapped.


mOptionEqualAt

public int mOptionEqualAt
Indicates the alignment position of the equal sign following a keyword.


mOptionWrapLine

public int mOptionWrapLine
Indicates the width in characters that each line will be wrapped


mOptionForceUpper

public boolean mOptionForceUpper
Indicates that file names will be forced to uppercase


mOutputName

public java.lang.String mOutputName
The name for the output file


mLineCount

public int mLineCount
Tracks which line in a file (or list) is currently being processed


mSourceName

public java.lang.String mSourceName
The name of the ruleset source


mWriteOutput

public boolean mWriteOutput
The name of the ruleset source

Constructor Detail

PPIRuleset

public PPIRuleset()
Creates an instance of a Ruleset

Method Detail

parse

public boolean parse(java.lang.String pathName)
Parses a file containing a ruleset into its constitute elments. The path and name of the file are passed to the method which is opened and parsed.

Parameters:
pathName - the fully qualified path and name of the file to parse.
Returns:
true if the file could be opened; false otherwise.
Since:
1.0

parseLine

public boolean parseLine(java.lang.String buffer)
Parses a string containing a single ruleset into its constitute elments.

Parameters:
buffer - the line of text to parse.
Returns:
true if the file could be opened; false otherwise.
Since:
1.0

run

public boolean run(java.lang.String pathname)
Run the current rule set.

Parameters:
pathname - the pathname of the file to run the rule set on.
Returns:
true if an variable was set or added; false if error occured. The variable mWriteOutput is set to true if output is to generated, false otherwise.
Since:
1.0

evalCondition

public boolean evalCondition(java.util.ArrayList stack)
Evaluate a condition that is coded into a array. Returns the result of the evaliation.

Parameters:
stack - the array containing the tokens for the condition to check.
Returns:
true if an variable was set or added; false if unable to add the variable.
Since:
1.0

makeRegex

public java.lang.String makeRegex(java.lang.String pattern)
Converts a string to a regular expression pattern. All "*" in the string are converted to ".*" and all "." are made literal.

Parameters:
pattern - the string containing "nice" tokens for wild cards.
Returns:
the string altered to be a regular expression.
Since:
1.0

dump

public void dump(boolean doAction)
Prints out the current rule set in tokenized form.

Parameters:
doAction - the type of list to dump. If true then the action list will be dumped, otherwise the variable list will be dumped.
Since:
1.0

argSplit

public java.util.ArrayList argSplit(java.lang.String buffer)
Split a string into one or more substrings by parsing on whitespace. Arguments in quotes are kept intack.

Parameters:
buffer - the string to parse.
Returns:
ArrayList an array of arguments.
Since:
1.0

convertYesNo

public boolean convertYesNo(java.lang.String value)
Converts a string to a boolean state. If the string contains "YES" then the state returned is true. If it is anything else then false is returned.

Parameters:
value - the string to convert.
Returns:
true if the string is "YES"; false if string is anything else.
Since:
1.0

setOption

public void setOption(java.lang.String name,
                      java.lang.String value)
Sets the value of an option.

Parameters:
name - the name of the variable to set.
value - the value to set for the variable.
Since:
1.0

findAndSet

public boolean findAndSet(pds.ruleset.PPIVariable variable)
Finds a variable in the variable list and set its value. If the variable does not exist one is added.

Parameters:
variable - the name of the variable to set.
Returns:
true if an variable was set or added; false if unable to add the variable.
Since:
1.0

findAndSet

public boolean findAndSet(java.lang.String name,
                          java.lang.String value)
Finds a variable in the variable list and set its value. If the variable does not exist one is added.

Parameters:
name - the name of the variable to set.
value - the value to set for the variable.
Returns:
true if an variable was set or added; false if unable to add the variable.
Since:
1.0

getValue

public java.lang.String getValue(java.lang.String name)
Finds a variable in the variable list and returns its value. If the variable does not exist null is returned.

Parameters:
name - the name of the variable to set.
Returns:
null if an variable does not exist; the value assigned to the variable if it does.
Since:
1.0

getValue

public java.lang.String getValue(java.lang.String name,
                                 boolean blank)
Finds a variable in the variable list and returns its value. If the variable does not exist null is returned.

Parameters:
name - the name of the variable to set.
blank - indicates whether to return a blank string if not the variable is not found. If true a blank is returned.
Returns:
null if an variable does not exist and blank is false. Returns a blank string if blank is true; the value assigned to the variable if it does.
Since:
1.0

readLine

public java.lang.String readLine(java.io.FileInputStream file)
Parses the next line from a file stream. A logical line can span multiple physical lines when quotes (") or tag delimiters (<>) are used.

Parameters:
file - the input file stream
Returns:
true if an element was parsed from the stream; false if the end of file or an error was encountered.
Since:
1.0
See Also:
FileInputStream

reset

public void reset()
Clear all variables, rules and states in the ruleset.

Since:
1.0

replaceVariable

public java.lang.String replaceVariable(java.lang.String buffer)
Searches the passed string for variables and replaces each variable with its current value. The string is passed through only once.

Parameters:
buffer - the string to search for variables.
Returns:
the string with all variables replaced with the current value.
Since:
1.0

showMessage

public void showMessage(boolean location,
                        java.lang.String message)
Prints and error message to the display. Adds information to the message to help identify where the error occurred.

Parameters:
location - indicates whether location information should be displayed before the message.
message - the text of the message to display.
Since:
1.0

show

public static void show(java.lang.String message)
Prints text to the display.

Parameters:
message - the text of the message to display.
Since:
1.0

showRule

public static void showRule(int type,
                            java.lang.String arg1)
Prints text to the display. May be used for rules that require only one argument.

Parameters:
type - the type of rule to create. See PPIAction for valid types.
arg1 - the first argument for the rule. If argument is not set pass null.
Since:
1.0

showRule

public static void showRule(int type,
                            java.lang.String arg1,
                            java.lang.String arg2)
Prints text to the display. Used for rules which require multiple arguments. If an argument is not defined or not required pass null as the value.

Parameters:
type - the type of rule to create. See PPIAction for valid types.
arg1 - the first argument for the rule. If argument is not set pass null.
arg2 - the second argument for the rule. If argument is not set pass null.
Since:
1.0

update

public void update()
Update the current template by replacing all variables with the defined values. The template is a PDS label and only the values assigned to an element may contain variables.

Since:
1.0

output

public void output()
Writes the template to the output files. The name and format for the output file is controlled by various global options.

Since:
1.0

unquote

public java.lang.String unquote(java.lang.String buffer)
Removes quotes from a string if the string starts with and ends with a quote character (").

Parameters:
buffer - the string to remove the quotes from.
Returns:
the string with the quotes removed, or the orginal string of it is not quoted.
Since:
1.0

makeRule

public static java.lang.String makeRule(int type,
                                        java.lang.String arg1,
                                        java.lang.String arg2)
Creates a syntactically correct rule with the parameters passed.

Parameters:
type - the type of rule to create. See PPIAction for valid types.
arg1 - the first argument for the rule. If argument is not set pass null.
arg2 - the second argument for the rule. If argument is not set pass null.
Returns:
the string with the fully formed rule or null if the type is unknown.
Since:
1.0