public final class ConfigLoader
extends java.lang.Object
TODO: this class uses a very unstructured method of reading the DOM, with the assumption that we will eventually validate configuration XML documents against a DTD prior to loading the data into the pattern engine.
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
ATTR_ACCESS
XML access attribute name
|
private static java.lang.String |
ATTR_CLASS
XML class attribute name
|
private static java.lang.String |
ATTR_DEPTH
XML depth attribute name
|
private static java.lang.String |
ATTR_DIRECTORY
XML directory attribute name
|
private static java.lang.String |
ATTR_FILESPEC
XML file-spec attribute name
|
private static java.lang.String |
ATTR_HONOR
Honor hidden mode attribute name.
|
private static java.lang.String |
ATTR_INIT
XML initializer attribute name
|
private static java.lang.String |
ATTR_INPUT
XML input attribute name
|
private static java.lang.String |
ATTR_LC
Load condition attribute name
|
private static java.lang.String |
ATTR_MODE
XML mode attribute name
|
private static java.lang.String |
ATTR_NAME
XML name attribute name
|
private static java.lang.String |
ATTR_NAMESPACE
XML namespace attribute name
|
private static java.lang.String |
ATTR_ON
XML on attribute name
|
private static java.lang.String |
ATTR_OPT
Terse mode attribute name
|
private static java.lang.String |
ATTR_TYPE
XML type attribute name
|
private static java.lang.String[] |
CONVERSION_RES_LOCATIONS
Location of the conversion-related resources at server run time.
|
private static java.lang.String |
ELEM_ACTION
XML action element tag
|
private static java.lang.String |
ELEM_ASCENTRULES
XML ascent-rules element tag
|
private static java.lang.String |
ELEM_ASTSPEC
XML ast-spec element tag
|
private static java.lang.String |
ELEM_BREAK
XML break element tag
|
private static java.lang.String |
ELEM_CFG
XML cfg element tag
|
private static java.lang.String |
ELEM_CONTINUE
XML continue element tag
|
private static java.lang.String |
ELEM_DESCENTRULES
XML descent-rules element tag
|
private static java.lang.String |
ELEM_EXPRESSION
XML expression element tag
|
private static java.lang.String |
ELEM_FUNCLIB
XML func-library element tag
|
private static java.lang.String |
ELEM_FUNCTION
XML function element tag
|
private static java.lang.String |
ELEM_INCLUDE
XML include element tag
|
private static java.lang.String |
ELEM_INITRULES
XML init-rules element tag
|
private static java.lang.String |
ELEM_NEXTCHILDRULES
XML next-child-rules element tag
|
private static java.lang.String |
ELEM_PARAMETER
XML parameter element tag
|
private static java.lang.String |
ELEM_POSTRULES
XML post-rules element tag
|
private static java.lang.String |
ELEM_RETURN
XML return element tag
|
private static java.lang.String |
ELEM_RULE
XML rule element tag
|
private static java.lang.String |
ELEM_RULESET
XML rule-set element tag
|
private static java.lang.String |
ELEM_VARIABLE
XML variable element tag
|
private static java.lang.String |
ELEM_WALKRULES
XML walk-rules element tag
|
private static java.lang.String |
ELEM_WHILE
XML while element tag
|
private static java.lang.String |
ELEM_WORKER
XML worker element tag
|
private org.w3c.dom.Element |
element
XML element currently being processed.
|
private PatternEngine |
engine
Pattern engine object being configured.
|
private java.lang.String |
fileName
The originating file name of the currently processed DOM element.
|
private RuleContainer |
firstRuleSet
First RuleSet processed.
|
private boolean |
inLoop
Are we nested within a loop?
|
private NamedFunction |
lastNamedFunction
Named expression last processed.
|
private Rule |
lastRule
Rule last added to the ruleset.
|
private RuleContainer |
lastRuleContainer
Rule container last processed.
|
private static java.lang.String |
PATPATH_KEY
Key used to obtain the pattern config file search path
|
private static java.util.Map |
RULE_TYPES
Map of rule type strings to integer constants
|
private int |
ruleType
Rule type for rules last processed.
|
private static java.lang.String |
SUFFIX_RULES
File suffix for ruleset-level configuration files
|
private static java.lang.String |
SUFFIX_XML
File suffix for top-level configuration files
|
private java.util.Set |
tags
Set of tags which should be processed at the top level.
|
private static java.lang.String |
VAL_FALSE
Data value constant for false
|
private static java.lang.String |
VAL_PRIVATE
Data value constant for private
|
private static java.lang.String |
VAL_PUBLIC
Data value constant for public
|
private static java.lang.String |
VAL_TREE
Data value constant for tree
|
private static java.lang.String |
VAL_TRUE
Data value constant for true
|
private static java.lang.String |
VAL_VIEW
Data value constant for view
|
Modifier | Constructor and Description |
---|---|
|
ConfigLoader(PatternEngine engine)
Constructor called by pattern engine; accepts the ruleset object to be
initialized.
|
private |
ConfigLoader(PatternEngine engine,
RuleContainer last,
java.util.Set tags)
Private constructor called to load nested rulesets, for expression
library includes, for instance.
|
Modifier and Type | Method and Description |
---|---|
private void |
action()
Load an action into the last rule created in response to an
action element. |
private void |
ascentRules()
Prepare to load a list of AST ascent rules from inside of an
ascent-rules element. |
private void |
astSpec()
Load an AST spec definition from an
ast-spec element in a
top-level profile definition. |
private void |
changeLoopAction(boolean isBreak)
Load a break or continue action into the last rule created in response
to
break or continue elements, respectively. |
private void |
descentRules()
Prepare to load a list of AST descent rules from inside of a
descent-rules element. |
private void |
expression()
Add a user-defined expression to a named function definition.
|
static java.io.File |
findConfigurationFile(java.lang.String name,
java.lang.String suffix)
Searches the
patpath for a file with a root name of
name and a suffix of suffix . |
private void |
function()
Load a named function into the ruleset currently being processed from
the
function element. |
static java.io.InputStream |
getConversionResource(java.lang.String name,
java.lang.String suffix)
Get conversion-related resource at server run time as an input stream.
|
private int |
getLineNumber()
Returns the line number of the currently processed DOM element.
|
private void |
include()
Process the
include element by including an expression
library (and any nested includes) from an external rule container
definition. |
private boolean |
inEngineScope()
Determines if the element currently being processed is within the scope
of the top-level, engine configuration (as opposed to being within the
the scope of a lower-level, ruleset configuration.
|
private void |
initRules()
Prepare to load a set of initialization rules from inside of an
init-rules element. |
private void |
library()
Load a named expression library from a
library element. |
void |
load(java.lang.String name)
Load the top-level configuration profile from an XML file.
|
void |
loadImpl(java.lang.String name,
java.lang.String suffix)
Load the top-level or ruleset-level configuration profile from an XML
file.
|
private void |
nextChildRules()
Prepare to load a list of AST next child rules from inside of an
next-child-rules element. |
private void |
parameter()
Load a user parameter definition from a
parameter element
contained in an expression element of a profile
definition. |
private void |
postRules()
Prepare to load a set of termination rules from inside of an
post-rules element. |
private void |
processChildElements(boolean ruleContainerLevel)
Processes the child elements of the element last traversed in the DOM.
|
private void |
rule(boolean loop)
Load a new rule definition from a
rule element. |
private void |
ruleSet()
Load a ruleset definition from a
rule-set element in either
a top-level or ruleset-level profile definition. |
private void |
setLastRuleContainer(RuleContainer container)
Update the container which will be the target of any configuration
to follow, such as registering variables, pattern workers, etc.
|
private void |
variable(boolean ret)
Load a user variable definition from a
variable element in
a top-level or ruleset-level profile definition. |
private void |
walkRules()
Prepare to load a set of AST walking rules from inside of a
walk-rules element. |
private void |
worker()
Load a pattern worker helper class definition from a
worker
element in a top-level profile definition. |
private static final java.lang.String PATPATH_KEY
private static final java.lang.String SUFFIX_XML
private static final java.lang.String SUFFIX_RULES
private static final java.lang.String ELEM_CFG
private static final java.lang.String ELEM_ASTSPEC
private static final java.lang.String ELEM_WORKER
private static final java.lang.String ELEM_VARIABLE
private static final java.lang.String ELEM_PARAMETER
private static final java.lang.String ELEM_RETURN
private static final java.lang.String ELEM_EXPRESSION
private static final java.lang.String ELEM_RULESET
private static final java.lang.String ELEM_INCLUDE
private static final java.lang.String ELEM_FUNCLIB
private static final java.lang.String ELEM_FUNCTION
private static final java.lang.String ELEM_INITRULES
private static final java.lang.String ELEM_WALKRULES
private static final java.lang.String ELEM_ASCENTRULES
private static final java.lang.String ELEM_DESCENTRULES
private static final java.lang.String ELEM_NEXTCHILDRULES
private static final java.lang.String ELEM_POSTRULES
private static final java.lang.String ELEM_RULE
private static final java.lang.String ELEM_WHILE
private static final java.lang.String ELEM_BREAK
private static final java.lang.String ELEM_CONTINUE
private static final java.lang.String ELEM_ACTION
private static final java.lang.String ATTR_DIRECTORY
private static final java.lang.String ATTR_FILESPEC
private static final java.lang.String ATTR_INPUT
private static final java.lang.String ATTR_DEPTH
private static final java.lang.String ATTR_NAME
private static final java.lang.String ATTR_OPT
private static final java.lang.String ATTR_LC
private static final java.lang.String ATTR_HONOR
private static final java.lang.String ATTR_ACCESS
private static final java.lang.String ATTR_CLASS
private static final java.lang.String ATTR_NAMESPACE
private static final java.lang.String ATTR_MODE
private static final java.lang.String ATTR_TYPE
private static final java.lang.String ATTR_ON
private static final java.lang.String ATTR_INIT
private static final java.lang.String VAL_TREE
private static final java.lang.String VAL_VIEW
private static final java.lang.String VAL_PRIVATE
private static final java.lang.String VAL_PUBLIC
private static final java.lang.String VAL_TRUE
private static final java.lang.String VAL_FALSE
private static final java.lang.String[] CONVERSION_RES_LOCATIONS
private static final java.util.Map RULE_TYPES
private java.util.Set tags
private PatternEngine engine
private org.w3c.dom.Element element
private java.lang.String fileName
private int ruleType
private RuleContainer lastRuleContainer
private RuleContainer firstRuleSet
private NamedFunction lastNamedFunction
private Rule lastRule
private boolean inLoop
public ConfigLoader(PatternEngine engine)
load(java.lang.String)
method is
called.engine
- Pattern engine to be configured with data from an XML
definition.private ConfigLoader(PatternEngine engine, RuleContainer last, java.util.Set tags)
rule-set
element) whose
tag names are included in tags
.engine
- Pattern engine to be configured with data from an XML
definition.tags
- Set of tag names which are to be processed at the top level.
Tag names encountered at the top level in an XML document are
ignored if not included in this set. However, this parameter
may be null
, which indicates all top-level tags
are to be processed.public static java.io.File findConfigurationFile(java.lang.String name, java.lang.String suffix) throws ConfigurationException
patpath
for a file with a root name of
name
and a suffix of suffix
.name
- Root of target filename.suffix
- Suffix of target filename.patpath
.ConfigurationException
- if the target file cannot be located.public static java.io.InputStream getConversionResource(java.lang.String name, java.lang.String suffix)
name
- Path to the resource, without file suffix. E.g. "schema/hibernate".suffix
- File suffix (typically ".xml").null
if the resource
couldn't be found.public void load(java.lang.String name) throws ConfigurationException
<name>.xml
. It must be located somewhere in
the path defined by the global configuration parameter
patpath
.name
- Root name of the XML file containing the top-level profile
information.ConfigurationException
- if any error occurs loading the configuration data into the
pattern engine.public void loadImpl(java.lang.String name, java.lang.String suffix) throws ConfigurationException
<name>.<suffix>
. it
must be located somewhere in the path defined by the global
configuration parameter patpath
.name
- Root name of the XML file containing the profile information.suffix
- Suffix of the name of the XML file containing the profile
information.ConfigurationException
- if any error occurs loading the configuration data into the
pattern engine.private void processChildElements(boolean ruleContainerLevel) throws ConfigurationException
If a limited set of tags is defined for this loader, AND we are not processing an element which represents a rule container, we only process child elements that match an entry in the limited set of tags. This feature is used, for instance, to process only the expression library elements and nested include elements in an included rule container definition.
ruleContainerLevel
- true
if the element currently being processed
represents a rule container, else false
.ConfigurationException
- if any error occurs loading the configuration data into the
pattern engine.private void astSpec() throws ConfigurationException
ast-spec
element in a
top-level profile definition.ConfigurationException
- if P2J_HOME
is not defined for this process.private void worker() throws ConfigurationException
worker
element in a top-level profile definition.ConfigurationException
- if any error occurs instantiating or registering the worker
object in the pattern engine.private void variable(boolean ret) throws ConfigurationException
variable
element in
a top-level or ruleset-level profile definition.ret
- true
if this is to process a return
value for a named function.ConfigurationException
- if variable's initializer value is invalid, or if
a user variable name collision occurs during registration.private void parameter() throws ConfigurationException
parameter
element
contained in an expression
element of a profile
definition.ConfigurationException
- if a parameter name collision occurs during registration.private void expression()
private void ruleSet() throws ConfigurationException
rule-set
element in either
a top-level or ruleset-level profile definition. This element can either
refer to a ruleset definition in an external file (if the
name
attribute is defined and the element has no child
elements), or it can define a ruleset's properties inline using child
elements. This method handles both cases.ConfigurationException
- if any error occurs loading the ruleset definition from the
current document or from an external document.private void include() throws ConfigurationException
include
element by including an expression
library (and any nested includes) from an external rule container
definition.ConfigurationException
- if any error occurs loading the included ruleset definition.private void library() throws ConfigurationException
library
element.
If we are currently processing an external document in response to an
include
element, we only load the library if it is not
private.ConfigurationException
- if any error occurs loading the library definition.include()
private void function() throws ConfigurationException
function
element.ConfigurationException
- if any error occurs loading the function definition.private void initRules() throws ConfigurationException
init-rules
element. This does not actually load the rules,
only sets state variables such that when the nested rule
tags are encountered, they are processed as init-rules for the correct
rule container.ConfigurationException
- if any error is encountered processing child elements.private void walkRules() throws ConfigurationException
walk-rules
element. This does not actually load the rules,
only sets state variables such that when the nested rule
tags are encountered, they are processed as walk-rules for the correct
rule container.ConfigurationException
- if any error is encountered processing child elements.private void ascentRules() throws ConfigurationException
ascent-rules
element. This does not actually load the
rules, only sets state variables such that when the nested
rule
tags are encountered, they are processed as
ascent-rules for the correct rule container.ConfigurationException
- if any error is encountered processing child elements.private void descentRules() throws ConfigurationException
descent-rules
element. This does not actually load the
rules, only sets state variables such that when the nested
rule
tags are encountered, they are processed as
descent-rules for the correct rule container.ConfigurationException
- if any error is encountered processing child elements.private void nextChildRules() throws ConfigurationException
next-child-rules
element. This does not actually load the
rules, only sets state variables such that when the nested
rule
tags are encountered, they are processed as
next-child-rules for the correct rule container.ConfigurationException
- if any error is encountered processing child elements.private void postRules() throws ConfigurationException
post-rules
element. This does not actually load the rules,
only sets state variables such that when the nested rule
tags are encountered, they are processed as post-rules for the correct
rule container.ConfigurationException
- if any error is encountered processing child elements.private void rule(boolean loop) throws ConfigurationException
rule
element. This only
creates the rule using its condition expression and remembers the last
rule created, to ensure that when nested action
tags are
encountered, they are processed as actions for this rule.loop
- If true
this rule should be implemented as a
while
loop instead of as an if/else
construct.ConfigurationException
- if any error is encountered processing child elements or
compiling the rule's condition expression.private void action() throws ConfigurationException
action
element. The action may be created to trigger on
the rule's condition evaluating to true
or to
false
, depending upon the value of the on
attribute. The default, if no such attribute is provided, is to
trigger on true
.ConfigurationException
- if the expression which defines the action cannot be compiled.private void changeLoopAction(boolean isBreak) throws ConfigurationException
break
or continue
elements, respectively.
The action may be created to trigger on the rule's condition evaluating
to true
or to false
, depending upon the value
of the on
attribute. The default, if no such attribute is
provided, is to trigger on true
.isBreak
- If true
, a break action is added; if
false
, a continue action is added.ConfigurationException
- if the expression which defines the action cannot be compiled.private boolean inEngineScope()
true
if our parent element is cfg
,
else false
.private void setLastRuleContainer(RuleContainer container)
container
- Rule container which will be the subject of any upcoming
configuration.private int getLineNumber()