public class ScriptRepository
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private int |
overrideRuleCount
a count of how many rules there are in the script repository which employ injection into hierarchies
|
private java.util.Map<java.lang.String,RuleScript> |
ruleNameIndex
a 1-m mapping from rule names which appear in rules to a script object holding the
rule details
|
private boolean |
skipOverrideRules
a flag derived from the transformer which enables us to avoid testing superclass rules for
matches if it is set
|
private java.util.Map<java.lang.String,java.util.List<RuleScript>> |
targetClassIndex
a 1-1 mapping from target class names which appear in rules to a script object holding the
rule details
|
private java.util.Map<java.lang.String,java.util.List<RuleScript>> |
targetInterfaceIndex
a 1-m mapping from target interface names which appear in rules to a script object holding the
rule details
|
Constructor and Description |
---|
ScriptRepository(boolean skipOverrideRules) |
Modifier and Type | Method and Description |
---|---|
private void |
add(java.util.List<RuleScript> entries,
RuleScript script)
add a rule script to start or end of the index list according to its location type.
|
RuleScript |
addScript(RuleScript script)
add a rule script to the repository returning any existing script with the same name or null
if no such script can be found.
|
boolean |
checkInterfaces()
see if we need to do any transformation of interfaces
|
java.util.List<RuleScript> |
currentRules()
return a list containing all the currently installed rule scripts.
|
private void |
indexTarget(RuleScript script,
java.util.Map<java.lang.String,java.util.List<RuleScript>> index)
insert a script into the index using the script target class name as the index key.
|
boolean |
matchClass(java.lang.Class<?> clazz)
return true if there is a rule which applies to the supplied class otherwise false
|
private boolean |
matchTarget(java.lang.String name,
java.lang.Class<?> clazz,
boolean isInterface,
boolean isOverride)
return true if there are any scripts indexed under name which meet the required matching conditions
|
java.util.List<RuleScript> |
processScripts(java.lang.String scriptText,
java.lang.String scriptFile)
Split the text of a script file into a list of individual rule scripts
|
private void |
reindexTarget(RuleScript script,
RuleScript previous,
java.util.Map<java.lang.String,java.util.List<RuleScript>> index)
replace a script in the index using the script target class name as the index key.
|
RuleScript |
removeScript(RuleScript script)
remove a rule script from the repository returning the script if it is found or null
if is not found.
|
RuleScript |
removeScript(java.lang.String name)
remove a rule script from the repository by name returning the script if it is found or null
if is not found.
|
RuleScript |
scriptForRuleName(java.lang.String name)
locate a rule script with a given name
|
java.util.List<RuleScript> |
scriptsForClassName(java.lang.String name)
return a list of all class scripts indexed using the supplied name.
|
java.util.List<RuleScript> |
scriptsForInterfaceName(java.lang.String name)
return a list of all interface scripts indexed using the supplied name.
|
boolean |
skipOverrideRules() |
private void |
unindexTarget(RuleScript script,
java.util.Map<java.lang.String,java.util.List<RuleScript>> index)
remove a script from the index using the script target class name as the index key.
|
private final java.util.Map<java.lang.String,java.util.List<RuleScript>> targetClassIndex
private final java.util.Map<java.lang.String,java.util.List<RuleScript>> targetInterfaceIndex
private final java.util.Map<java.lang.String,RuleScript> ruleNameIndex
private final boolean skipOverrideRules
private int overrideRuleCount
public java.util.List<RuleScript> processScripts(java.lang.String scriptText, java.lang.String scriptFile) throws java.lang.Exception
scriptText
- the text obtained from a script filescriptFile
- teh name of the file containing teh textjava.lang.Exception
- if there is an error in the format of the script file tesxtpublic RuleScript addScript(RuleScript script)
script
- the script to be added to the repositorypublic RuleScript removeScript(RuleScript script)
script
- the script to be removed from the repository.public RuleScript removeScript(java.lang.String name)
name
- the name of the script to be removed from the repositorypublic RuleScript scriptForRuleName(java.lang.String name)
name
- the name of the rule scriptpublic java.util.List<RuleScript> scriptsForClassName(java.lang.String name)
name
- public java.util.List<RuleScript> scriptsForInterfaceName(java.lang.String name)
name
- public boolean matchClass(java.lang.Class<?> clazz) throws java.lang.Exception
clazz
- java.lang.Exception
public java.util.List<RuleScript> currentRules()
private boolean matchTarget(java.lang.String name, java.lang.Class<?> clazz, boolean isInterface, boolean isOverride)
name
- the name under which the scripts are indexedclazz
- a class which should be checked for a method whose name matches the script method nameisInterface
- true if we are interested in matching interface rules false if we are interested in
matching class rulesisOverride
- true if we are only interested in rules which apply to overriding methods false
if we are happy with any ruleprivate void indexTarget(RuleScript script, java.util.Map<java.lang.String,java.util.List<RuleScript>> index)
script
- index
- private void unindexTarget(RuleScript script, java.util.Map<java.lang.String,java.util.List<RuleScript>> index)
script
- index
- private void reindexTarget(RuleScript script, RuleScript previous, java.util.Map<java.lang.String,java.util.List<RuleScript>> index)
script
- index
- private void add(java.util.List<RuleScript> entries, RuleScript script)
entries
- script
- public boolean checkInterfaces()
public boolean skipOverrideRules()