Package org.jboss.byteman.agent
Class ScriptRepository
- java.lang.Object
-
- org.jboss.byteman.agent.ScriptRepository
-
public class ScriptRepository extends java.lang.Object
Class to manage indexing and lookup of rule scripts by rule name and by either class or interface name
-
-
Field Summary
Fields Modifier and Type Field Description private int
overrideRuleCount
a count of how many rules there are in the script repository which employ injection into hierarchiesprivate 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 detailsprivate boolean
skipOverrideRules
a flag derived from the transformer which enables us to avoid testing superclass rules for matches if it is setprivate 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 detailsprivate 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 Summary
Constructors Constructor Description ScriptRepository(boolean skipOverrideRules)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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 interfacesjava.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 falseprivate 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 conditionsjava.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 scriptsprivate 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(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
removeScript(RuleScript script)
remove a rule script from the repository 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 namejava.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()
check whether any overriding rules are currently loadedprivate 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.
-
-
-
Field Detail
-
targetClassIndex
private final 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
-
targetInterfaceIndex
private final 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
-
ruleNameIndex
private final 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
-
skipOverrideRules
private final boolean skipOverrideRules
a flag derived from the transformer which enables us to avoid testing superclass rules for matches if it is set
-
overrideRuleCount
private int overrideRuleCount
a count of how many rules there are in the script repository which employ injection into hierarchies
-
-
Method Detail
-
processScripts
public java.util.List<RuleScript> processScripts(java.lang.String scriptText, java.lang.String scriptFile) throws java.lang.Exception
Split the text of a script file into a list of individual rule scripts- Parameters:
scriptText
- the text obtained from a script filescriptFile
- teh name of the file containing teh text- Returns:
- a list of rule scripts
- Throws:
java.lang.Exception
- if there is an error in the format of the script file tesxt
-
addScript
public 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. if a script is returned it will have been deactivated.- Parameters:
script
- the script to be added to the repository- Returns:
- any previous script with the same name or null
-
removeScript
public RuleScript removeScript(RuleScript script)
remove a rule script from the repository returning the script if it is found or null if is not found. if a script is returned it will have been deactivated.- Parameters:
script
- the script to be removed from the repository.- Returns:
- the script if it was found in the repository and removed successfully or null if it had already been removed.
-
removeScript
public 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. if a script is returned it will have been deactivated.- Parameters:
name
- the name of the script to be removed from the repository- Returns:
- the script if it was found in the repository or null if none was found
-
scriptForRuleName
public RuleScript scriptForRuleName(java.lang.String name)
locate a rule script with a given name- Parameters:
name
- the name of the rule script- Returns:
- the script with that name or null if no such script can be found
-
scriptsForClassName
public java.util.List<RuleScript> scriptsForClassName(java.lang.String name)
return a list of all class scripts indexed using the supplied name. note that if name is package qualified then only scripts with the full package qualificaton will be returned whereas if name is not package qualified then only scripts with the unqualified name will be returned. Note that the returned list can be iterated safely but will not reflect later additions to or deletions from the list.- Parameters:
name
- the name of the class for which scripts should be listed- Returns:
- the list of scripts for that name
-
scriptsForInterfaceName
public java.util.List<RuleScript> scriptsForInterfaceName(java.lang.String name)
return a list of all interface scripts indexed using the supplied name. note that if name is package qualified then only scripts with the full package qualificaton will be returned whereas if name is not package qualified then only scripts with the unqualified name will be returned. Note that the returned list can be iterated safely but will not reflect later additions to or deletions from the list.- Parameters:
name
- the name of the interface for which scripts should be listed- Returns:
- the list of scripts for that name
-
matchClass
public boolean matchClass(java.lang.Class<?> clazz) throws java.lang.Exception
return true if there is a rule which applies to the supplied class otherwise false- Parameters:
clazz
- the name of the class for which rules are being sought- Returns:
- true if there is a rule which applies
- Throws:
java.lang.Exception
- if an error occurs during class lookup
-
currentRules
public java.util.List<RuleScript> currentRules()
return a list containing all the currently installed rule scripts.- Returns:
- the list of all installed scripts
-
matchTarget
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- Parameters:
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 rule- Returns:
- true if any scripts are found otherwise false
-
indexTarget
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.- Parameters:
script
-index
-
-
unindexTarget
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.- Parameters:
script
-index
-
-
reindexTarget
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.- Parameters:
script
-index
-
-
add
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. AT ENTRY rules are pushed so they are sorted in reverse load order. other rules are appended so they are sorted in load order.- Parameters:
entries
-script
-
-
checkInterfaces
public boolean checkInterfaces()
see if we need to do any transformation of interfaces- Returns:
- true if there are any interface rules false if there are none
-
skipOverrideRules
public boolean skipOverrideRules()
check whether any overriding rules are currently loaded- Returns:
- true if there are no overriding rules false if there are any
-
-