Use the Rule and Rule.Builder Classes
A Rule
defines a set of classes to instrument. Your iSDK code returns a
java.util.List
of Rule
objects from a method named
initializeRules
. Rules
are created using the builder
pattern, and a Rule.Builder
object is created using a match
string:
Rule.Builder builder = new Rule.Builder("com.mynamespace.MyClass");
See the javadocs for all classes referenced in this section.
This is similar to what you have to do in the UI. For example, in the Add Information
Point configuration screen, you must specify a name to match on – either a concrete
class name, abstract class name, interface name or annotation name. The argument to the
Rule.Builder
constructor is the same as what you would specify in
the UI (in the Class matching text box).
You then modify the Rule.Builder
by calling APIs on the
Rule.Builder
class. Rule.Builder
support fluent
style so that your code can be compact.
You need the following:
- Class match string: Given in the constructor to
Rule.Builder
. - Class match type: Set the
SDKClassMatchType
usingbuilder.setClassMatchType
. - Class match string match type: Set the
SDKStringMatchType
for the method usingbuilder.classStringMatchType
. - Method match string using
builder.setMethodMatchString
. - Method match type: Set the
SDKStringMatchType
for the method usingbuilder.methodStringMatchType
.
The following is a screenshot of an initializeRules()
method for creating an arbitrary
interceptor. Note the following:
- The style is a mixture of fluent and iterative (lines have chained invocations, but multiple lines are still used)
- The class match is for an exact classname match to a concrete class
(
SDKClassMatchType.MATCHES_CLASS
andSDKStringMatchType.EQUALS
forclassStringMatchType
). - The method match is for an exact method name string match
(
SDKStringMatchType.EQUALS
formethodStringMatchType
).