ex1
Class DefnFileParser

java.lang.Object
  extended byorg.xml.sax.helpers.DefaultHandler
      extended byex1.DefnFileParser
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

public class DefnFileParser
extends org.xml.sax.helpers.DefaultHandler

This is the parser for the DEFN config files. This holds all the parameter meta-information.


Constructor Summary
DefnFileParser(java.lang.String defnFile, boolean isCrop)
          Creates a new instance of DefnFileParser
 
Method Summary
 void characters(char[] buf, int offset, int len)
          Part of SAX processing that gets called to get the contents inside an xml tag.
 void endDocument()
          Part of SAX processing...
 void endElement(java.lang.String namespaceURI, java.lang.String sName, java.lang.String qName)
          Part of SAX processing that gets called when an ending xml tag is encountered.
 int findChoiceVal(ParamDef p, java.lang.String ch)
          From a choice string find the value that is linked to it.
 ex1.OpAction findOpAction(java.lang.String code, int id)
          Get the process structure that matches the specified code and numeric identifier.
 ex1.OpAction findOpAction(java.lang.String code, java.lang.String id)
          Get the process structure that matches the specified code and String numeric identifier.
 ex1.OpAction getAction(int ind)
          Get the process structure at the specified index.
 java.lang.String getActionCode(int ind)
          Get the single character code O,G,P for the process at the specified index.
 int getActionId(int ind)
          Get the numeric part of the process at the specified index
 java.lang.String getActionName(int ind)
          Get the name of a process at a specific location.
 int getActionNameCount()
          Get the number of unique process names.
 java.util.Collection getAllParms()
           
 java.lang.String getChoice(int col, int ch)
          This function returns one choice string from the list of choices for a parameter.
 int getChoiceCount(int col)
          This gets the number of choices for a parameter that is a choice list
 java.lang.Class getClass(int col)
          Return the Class of this parameter for crop data (either a string or combobox)
 ParamDef getColumn(int col)
          Get the parameter meta information for a specific column in a crop table
 java.lang.String getFullActionName(int ind)
          Get the name of the process with the the id and code tacked on the front.
 java.lang.String getFullActionName(java.lang.String code, java.lang.String id)
          Get the name of the process with the the id and code tacked on the front.
 java.lang.String getOpChoice(int ind, int pind, int ch)
          Get a specific dropdown choice within a process.
 int getOpChoiceCount(int ind, int pind)
          Get the number of choices that a dropdown list in process contains
 int getOpParmCode(int ind)
          Get the numeric part of the process at this location
 char getOpParmCodeType(int ind)
          Get the character part of the process at this location.
 int getOpParmCount(int ind)
          Get number of parameters for a process.
 java.lang.String getOpParmPrompt(int ind, int pind, boolean altUnits)
          Get the prompt(header) for an operation parameter.
 int getOpParmType(int ind, int pind)
          Get the type of a specific parameter in a process.
 ParamDef getParamDef(java.lang.String name)
          Given a parameter name finds the structure holding its information.
 int getParmCount()
          Get the number of parameters defined in the DEFN file
 java.lang.String getParmPrompt(int col, boolean altUnits)
          This gets the field for a parameter declaration and appeands any units information if it exists.
 int getType(int col)
           
 void setAddEnd(java.lang.String name, float adder)
          As part of the alternate (metric to english) conversion this may be added after the factor is applied.
 void setAltUnit(java.lang.String name, java.lang.String altUnit)
          Set string to display when alternate units are dispalyed.
 void setChoice(java.lang.String name, int val, java.lang.String choice)
          Add a choice to this parameter.
 void setFactor(java.lang.String name, float factor)
          Sets the factor that is used to go from regular to alternate units.
 void setPromptName(java.lang.String name, java.lang.String prompt)
          Sets the user prompt that should be displayed with this parameter.
 void startDocument()
          Part of SAX XML processing...
 void startElement(java.lang.String namespaceURI, java.lang.String lName, java.lang.String qName, org.xml.sax.Attributes attrs)
          Part of SAX processing that gets called at the when an opening xml tag is encountered.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefnFileParser

public DefnFileParser(java.lang.String defnFile,
                      boolean isCrop)
Creates a new instance of DefnFileParser

Parameters:
defnFile - the XML config file to load
isCrop - true if this is for CROP data parser.
Method Detail

getParmCount

public int getParmCount()
Get the number of parameters defined in the DEFN file

Returns:
the number of parameters

getAllParms

public java.util.Collection getAllParms()

getParmPrompt

public java.lang.String getParmPrompt(int col,
                                      boolean altUnits)
This gets the field for a parameter declaration and appeands any units information if it exists. These strings form the column headers in the tables the users sees. This version is for crop data only.

Parameters:
col - - column (index of parameter) to get prompt for
altUnits - - true if English version, false for metric
Returns:
the prompt attached to this column with units appended

startDocument

public void startDocument()
                   throws org.xml.sax.SAXException
Part of SAX XML processing... Called automatically by SAX parser

Throws:
org.xml.sax.SAXException

endDocument

public void endDocument()
                 throws org.xml.sax.SAXException
Part of SAX processing... Called automatically by SAX parser

Throws:
org.xml.sax.SAXException

startElement

public void startElement(java.lang.String namespaceURI,
                         java.lang.String lName,
                         java.lang.String qName,
                         org.xml.sax.Attributes attrs)
                  throws org.xml.sax.SAXException
Part of SAX processing that gets called at the when an opening xml tag is encountered. We will filter out the ones we are interested and set the flags for what the character function should grab and where it will be stored.

Throws:
org.xml.sax.SAXException

endElement

public void endElement(java.lang.String namespaceURI,
                       java.lang.String sName,
                       java.lang.String qName)
                throws org.xml.sax.SAXException
Part of SAX processing that gets called when an ending xml tag is encountered.

Throws:
org.xml.sax.SAXException

characters

public void characters(char[] buf,
                       int offset,
                       int len)
                throws org.xml.sax.SAXException
Part of SAX processing that gets called to get the contents inside an xml tag.

Throws:
org.xml.sax.SAXException

getParamDef

public ParamDef getParamDef(java.lang.String name)
Given a parameter name finds the structure holding its information.

Parameters:
name - name of the parameter to find
Returns:
structure holding all info about this parameter

setPromptName

public void setPromptName(java.lang.String name,
                          java.lang.String prompt)
Sets the user prompt that should be displayed with this parameter.

Parameters:
name - name of the parameter
prompt - prompt string to attach to it

setAltUnit

public void setAltUnit(java.lang.String name,
                       java.lang.String altUnit)
Set string to display when alternate units are dispalyed.

Parameters:
name - name of the parameter
altUnit - string to attach to alternate units

setFactor

public void setFactor(java.lang.String name,
                      float factor)
Sets the factor that is used to go from regular to alternate units.

Parameters:
name - parameter name
factor - value to multiply base value by to get alt value (generally mettric to english)

setAddEnd

public void setAddEnd(java.lang.String name,
                      float adder)
As part of the alternate (metric to english) conversion this may be added after the factor is applied.

Parameters:
name - name of the parameter
adder - value to add at the end

setChoice

public void setChoice(java.lang.String name,
                      int val,
                      java.lang.String choice)
Add a choice to this parameter.

Parameters:
name - name of the parameter
val - value of the particular choice
choice - name of string to display with this val in a choice list

getChoiceCount

public int getChoiceCount(int col)
This gets the number of choices for a parameter that is a choice list

Parameters:
col - column in crop table
Returns:
number of choicees for the dropdown

getChoice

public java.lang.String getChoice(int col,
                                  int ch)
This function returns one choice string from the list of choices for a parameter.

Parameters:
col - column in crop data
ch - index of choice string to get
Returns:
the choice value at this specific index

getType

public int getType(int col)

getClass

public java.lang.Class getClass(int col)
Return the Class of this parameter for crop data (either a string or combobox)

Parameters:
col - column in crop data
Returns:
either String or JComboBox depending on column type

findChoiceVal

public int findChoiceVal(ParamDef p,
                         java.lang.String ch)
From a choice string find the value that is linked to it.

Parameters:
p - parameter definition
ch - choice string to search for
Returns:
value that goes with selected choice string

getActionNameCount

public int getActionNameCount()
Get the number of unique process names.

Returns:
the number of weps process and group types possible.

getOpParmCode

public int getOpParmCode(int ind)
Get the numeric part of the process at this location

Parameters:
ind - index in action/process name list
Returns:
the numeric part of the process name or -1 on error

getOpParmCodeType

public char getOpParmCodeType(int ind)
Get the character part of the process at this location.

Parameters:
ind - index in action/process name list
Returns:
the single charcter O,G,P part of the process name

getOpParmCount

public int getOpParmCount(int ind)
Get number of parameters for a process.

Parameters:
ind - index in action/process name list
Returns:
number of operation parameters under this process

getOpParmType

public int getOpParmType(int ind,
                         int pind)
Get the type of a specific parameter in a process.

Parameters:
ind - index in action/process name list
pind - index of parameter within the process
Returns:
the type of the parameter

getOpChoiceCount

public int getOpChoiceCount(int ind,
                            int pind)
Get the number of choices that a dropdown list in process contains

Parameters:
ind - index in action/process name list
pind - index of parameter within the process
Returns:
number of choices for the list.

getOpChoice

public java.lang.String getOpChoice(int ind,
                                    int pind,
                                    int ch)
Get a specific dropdown choice within a process.

Parameters:
ind - index in action/process name list
pind - index of parameter within the process
ch - choice list element to get
Returns:
the choice list string that the specified location

getOpParmPrompt

public java.lang.String getOpParmPrompt(int ind,
                                        int pind,
                                        boolean altUnits)
Get the prompt(header) for an operation parameter.

Parameters:
ind - index in action/process name list
pind - index of parameter within the process
altUnits - true if alternate(english) units are to be used
Returns:
the header for the operation parameter with units appended

getActionName

public java.lang.String getActionName(int ind)
Get the name of a process at a specific location.

Parameters:
ind - index in action/process name list
Returns:
the full name of the process

getAction

public ex1.OpAction getAction(int ind)
Get the process structure at the specified index.

Parameters:
ind - index in action/process name list
Returns:
structure containing process information

getFullActionName

public java.lang.String getFullActionName(int ind)
Get the name of the process with the the id and code tacked on the front.

Parameters:
ind - index in action/process name list
Returns:
full name such as 'P11 - Break Crust'

getFullActionName

public java.lang.String getFullActionName(java.lang.String code,
                                          java.lang.String id)
Get the name of the process with the the id and code tacked on the front.

Parameters:
code - single character code to match
id - numeric id to match.
Returns:
full name such as 'P11 - Break Crust'

findOpAction

public ex1.OpAction findOpAction(java.lang.String code,
                                 java.lang.String id)
Get the process structure that matches the specified code and String numeric identifier.

Parameters:
code - single charcter code to match
id - numeric (as String) id to match
Returns:
process structure with information

findOpAction

public ex1.OpAction findOpAction(java.lang.String code,
                                 int id)
Get the process structure that matches the specified code and numeric identifier.

Parameters:
code - single charcter code to match
id - numeric id to match
Returns:
process structure with information

getActionCode

public java.lang.String getActionCode(int ind)
Get the single character code O,G,P for the process at the specified index.

Parameters:
ind - index in action/process name list
Returns:
the code as a string

getActionId

public int getActionId(int ind)
Get the numeric part of the process at the specified index

Parameters:
ind - index in action/process name list
Returns:
numeric part of process name

getColumn

public ParamDef getColumn(int col)
Get the parameter meta information for a specific column in a crop table

Parameters:
col - column information to get
Returns:
the ParamDef structure for this column.