public class WorkingMemoryRuleGenerator
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private java.util.List<java.lang.String> |
globals
Important globals which shall be included for runtime rule base to java communication.
|
private java.util.List<java.lang.String> |
imports
The path of imports of external java classes and enumerations which shall be included to the rule base.
|
private java.util.List<java.lang.String> |
packageName
The package name of the rules base package itself.
|
private java.util.List<java.lang.String> |
rules
The rules in
String format which will be part of the rule base. |
Constructor and Description |
---|
WorkingMemoryRuleGenerator(java.lang.String sourceFile)
This constructor gains the actual defined properties as XML parameter and automatically generates the necessary
rule base code in JBoss Drools script language.
|
Modifier and Type | Method and Description |
---|---|
private java.lang.String |
buildMsg(java.lang.String instruction,
java.lang.String xPath,
java.lang.String message)
Builds a messages containing the supplied parameters and returns this message as
String . |
private void |
droolsAddRuleLine(java.util.List<java.lang.String> code)
Adds lines of rule code to the known lines of rule code.
|
private void |
droolsAddRuleLine(java.lang.String[] code)
Adds lines of rule code to the known lines of rule code.
|
private java.util.List<java.lang.String> |
droolsComment(java.lang.String[] comments)
Converts a
String array of simple strings to JBoss Drools comment lines and returns them as a
List of String . |
private java.util.List<java.lang.String> |
droolsComment(java.lang.String[] comments,
java.util.List<java.lang.String> lines)
Converts a
String array of simple strings to JBoss Drools comment lines and adds them to a given
List of code lines. |
private java.util.List<java.lang.String> |
droolsComment(java.lang.String comment,
java.util.List<java.lang.String> lines)
Converts a simple
String to a JBoss Drools comment line and adds it to a given List of code
lines. |
private java.lang.String |
droolsConcatParts(java.lang.String[] parts)
Concatenates JBoss Drools code parts to a single JBoss Drools formatted code
String . |
private void |
droolsGlobal(java.lang.String[][] pairs)
Generates global definitions for multiple key-value pairs from the given two dimensional
String array by
using droolsGlobal(String, String) . |
private void |
droolsGlobal(java.lang.String type,
java.lang.String name)
Encapsulates the JBoss Drools script code representation of an global definition.
|
private void |
droolsGroupRule(de.hawhamburg.reachability.enumeration.ReachabilityGroup group)
Adds a definition of a reachability groups default rules by using
droolsAddRuleLine(String[]) which
actually does nothing by extending the "meta" rule Default. |
private void |
droolsImport(java.util.List<java.lang.String> clazzes)
|
private void |
droolsImport(java.lang.String clazz)
Encapsulates the JBoss Drools script code representation of an import definition.
|
private java.lang.String |
droolsLines(java.util.List<java.lang.String> lines)
Converts a
List of code lines in String format to a single JBoss Drools code String ,
which is quite easy and nothing but adding a newline (\n) to each line. |
private void |
droolsMetaRules(java.util.List<java.lang.String> loads)
Adds a definition of a so called "meta" rules by using
droolsMetaRules(String[]) which simply loads
different required variables for rule evaluation. |
private void |
droolsMetaRules(java.lang.String[] loads)
Adds a definition of a so called "meta" rules by using
droolsAddRuleLine(List) which simply loads
different required variables for rule evaluation. |
private void |
droolsPackageName(java.lang.String thePackageName)
Encapsulates the JBoss Drools script code representation of a package name definition.
|
private void |
droolsRule(de.hawhamburg.reachability.enumeration.ReachabilityGroup group,
de.hawhamburg.reachability.enumeration.ReachabilityStatus status,
java.lang.String[] conditions,
boolean fullReplace)
Adds the certain definition of a rule to determining exact a single
ReachabilityStatus in common with one
ReachabilityGroup by using droolsAddRuleLine(String[]) . |
private void |
error(java.lang.String instruction,
java.lang.String xPath,
java.lang.String message)
Handles an info while runtime by using
buildMsg(String, String, String) and
OutputUtil.error(String) . |
private java.lang.String |
getCondition(org.w3c.dom.Document properties,
org.w3c.dom.Element node,
java.lang.String xPath)
Determines the conditions for a certain user defined rule.
|
private java.lang.String |
getPlainCodeLine(org.w3c.dom.Element code,
java.lang.String instruction,
java.lang.String xPath)
Extracts a plain code line from a given user defined code element.
|
private java.util.List<java.lang.String> |
getPlainCodeLines(org.w3c.dom.NodeList codes,
java.lang.String instruction,
java.lang.String xPath)
Extracts multiple plain code lines from given user defined code elements.
|
private java.lang.String |
getSingleCondition(org.w3c.dom.Element node,
java.lang.String instruction,
java.lang.String xPath)
Builds a single condition (Tags:
alternative or condition ) by evaluating the elements
text content and attributes. |
private void |
info(java.lang.String instruction,
java.lang.String xPath,
java.lang.String message)
Handles an info while runtime by using
buildMsg(String, String, String) and
OutputUtil.info(String) . |
private void |
loadDefaultRule(org.w3c.dom.Document properties)
Handles the user defined loading instructions which will be located in the common default rule and which defines
variables accessible in all other rules.
|
private void |
loadDetectionRules(org.w3c.dom.Document properties)
Loads the detection rule definitions from user defined xml source and translates them into drools code by using
droolsGroupRule(ReachabilityGroup) and
droolsRule(ReachabilityGroup, ReachabilityStatus, String[], boolean) . |
private void |
loadImports(org.w3c.dom.Document properties)
Loads default and user defined import paths to
imports by using loadImports(Document) . |
java.lang.String |
toString()
Finalizes the output form of the new rule base code
String and returns it. |
private java.util.List<java.lang.String> packageName
private java.util.List<java.lang.String> imports
private java.util.List<java.lang.String> globals
private java.util.List<java.lang.String> rules
String
format which will be part of the rule base.public WorkingMemoryRuleGenerator(java.lang.String sourceFile)
toString()
method.sourceFile
- The path to the source file as String
.private void loadImports(org.w3c.dom.Document properties)
imports
by using loadImports(Document)
.properties
- The user defined XML file as Document
.private void loadDefaultRule(org.w3c.dom.Document properties)
properties
- The user defined XML file as Document
.private void loadDetectionRules(org.w3c.dom.Document properties)
droolsGroupRule(ReachabilityGroup)
and
droolsRule(ReachabilityGroup, ReachabilityStatus, String[], boolean)
.properties
- The user defined XML file as Document
.private java.lang.String getCondition(org.w3c.dom.Document properties, org.w3c.dom.Element node, java.lang.String xPath)
getPlainCodeLine(Element, String, String)
and/or
getSingleCondition(Element, String, String)
.properties
- The user defined XML file as Document
.node
- The current condition node within the Document
as Element
.xPath
- The current xPath which leads to the Element
as String
.String
formatted in drools notation.private java.lang.String getSingleCondition(org.w3c.dom.Element node, java.lang.String instruction, java.lang.String xPath)
alternative
or condition
) by evaluating the elements
text content and attributes. The required attribute is dimension. The attribute value is required
if the element has no text content. The default value is eval(false)
.node
- The current node (alternative
or condition
) as
Element
.instruction
- A text describing the current instruction for logging reasons as String
.xPath
- The xPath loading to the current node as String
String
.private java.lang.String getPlainCodeLine(org.w3c.dom.Element code, java.lang.String instruction, java.lang.String xPath)
code
- The user defined code element as Element
.instruction
- A text describing the current instruction for logging reasons as String
.xPath
- The xPath leading to the current code element as String
.String
.private java.util.List<java.lang.String> getPlainCodeLines(org.w3c.dom.NodeList codes, java.lang.String instruction, java.lang.String xPath)
codes
- The user defined code elements as NodeList
.instruction
- A text describing the current instruction for logging reasons as String
.xPath
- The xPath leading to the current code elements as String
.List
of String
.private void droolsPackageName(java.lang.String thePackageName)
thePackageName
- A String
representing the rule bases package name.private void droolsImport(java.util.List<java.lang.String> clazzes)
clazzes
- A List
of String
containing multiple import paths.private void droolsImport(java.lang.String clazz)
clazz
- A String
representing the path to the class or enumeration which shall be
imported.private void droolsGlobal(java.lang.String[][] pairs)
String
array by
using droolsGlobal(String, String)
.pairs
- A String
array containing multiple key-value pairs for globals.private void droolsGlobal(java.lang.String type, java.lang.String name)
type
- A String
representing the globals type.name
- A String
representing the name of the global.private java.util.List<java.lang.String> droolsComment(java.lang.String[] comments)
String
array of simple strings to JBoss Drools comment lines and returns them as a
List
of String
.comments
- A String
array containing some lines which shall be displayed as comments.List
of JBoss Drools formatted comment lines.private java.util.List<java.lang.String> droolsComment(java.lang.String[] comments, java.util.List<java.lang.String> lines)
String
array of simple strings to JBoss Drools comment lines and adds them to a given
List
of code lines.comments
- A String
array containing some lines which shall be displayed as comments.lines
- A List
of code lines to which the comment lines shall be appended.List
of JBoss Drools formatted comment lines.private java.util.List<java.lang.String> droolsComment(java.lang.String comment, java.util.List<java.lang.String> lines)
String
to a JBoss Drools comment line and adds it to a given List
of code
lines.comment
- A String
which shall be displayed as comment.lines
- A List
of code lines to which the comment line shall be appended.List
of JBoss Drools formatted comment lines.private void droolsMetaRules(java.util.List<java.lang.String> loads)
droolsMetaRules(String[])
which simply loads
different required variables for rule evaluation.loads
- A list of String
representing the different required variables.private void droolsMetaRules(java.lang.String[] loads)
droolsAddRuleLine(List)
which simply loads
different required variables for rule evaluation.loads
- A String
array representing the different required variables.private void droolsGroupRule(de.hawhamburg.reachability.enumeration.ReachabilityGroup group)
droolsAddRuleLine(String[])
which
actually does nothing by extending the "meta" rule Default. These rules will by named as combination of
Default and the groups name. It will be extended by the specific rules later.group
- A ReachabilityGroup
representing the name of the group for which this default
rule shall be defined.private void droolsRule(de.hawhamburg.reachability.enumeration.ReachabilityGroup group, de.hawhamburg.reachability.enumeration.ReachabilityStatus status, java.lang.String[] conditions, boolean fullReplace)
ReachabilityStatus
in common with one
ReachabilityGroup
by using droolsAddRuleLine(String[])
. The rule will be named be the
combination of ReachabilityGroup
and ReachabilityStatus
and it extends the default rule of the
related ReachabilityGroup
.group
- A ReachabilityGroup
for which the rule shall be created.status
- A ReachabilityStatus
for which the rule shall be created.conditions
- A String
array containing the conditions under which this
ReachabilityStatus
shall be set for the ReachabilityGroup
.fullReplace
- If set to true
the then
part of the rule will be replaced
by the user defined code as well, otherwise not.private void droolsAddRuleLine(java.lang.String[] code)
code
- A String
array containing rule lines of code which shall be registered.private void droolsAddRuleLine(java.util.List<java.lang.String> code)
code
- A List
of String
containing rule lines of code which shall be
registered.private java.lang.String droolsLines(java.util.List<java.lang.String> lines)
List
of code lines in String
format to a single JBoss Drools code String
,
which is quite easy and nothing but adding a newline (\n) to each line.lines
- A List
of String
which shall be converted to a single JBoss Drools line.String
as result of the conversion process in JBoss Drools format.private java.lang.String droolsConcatParts(java.lang.String[] parts)
String
.parts
- A String
array containing the code parts which shall be concatenated.String
containing a single JBoss Drools formatted code line.private void info(java.lang.String instruction, java.lang.String xPath, java.lang.String message)
buildMsg(String, String, String)
and
OutputUtil.info(String)
.instruction
- The instruction of the user defined code which was handled as String
.xPath
- The current xPath within the user defined XML-File as String
.message
- The info message which shall be published or logged as String
private void error(java.lang.String instruction, java.lang.String xPath, java.lang.String message)
buildMsg(String, String, String)
and
OutputUtil.error(String)
.instruction
- The instruction of the user defined code which was handled as String
.xPath
- The current xPath within the user defined XML-File as String
.message
- The error message which shall be published or logged as String
private java.lang.String buildMsg(java.lang.String instruction, java.lang.String xPath, java.lang.String message)
String
.instruction
- The instruction of the user defined code which was handled as String
.xPath
- The current xPath within the user defined XML-File as String
.message
- The message which shall be published or logged as String
String
.public final java.lang.String toString()
String
and returns it.toString
in class java.lang.Object