|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.objectweb.jac.core.Pointcut | +--org.objectweb.jac.core.MethodPointcut
This class can be used by JAC aspect components to easily define a set of method points on the base program that the aspects will use to modify its behavior.
A method pointcut is defined through four pointcut
expressions. For the moment, these pointcut expressions are a
simple extension of regular expressions -- in an EMACS_LISP syntax
(see the GNU-regexp tutorial) that can be combined with the
&&
operator (in this case all the regexps must match)
or the ||
operator (in this case, only one regexp must
match). Before a regexp, you can use the !
(not)
operator to inverse the matching.
Depending on the pointcut expression, you can also
use keywords that will be dynamically interpreted. We intend to
provide a more complete and suited desciption language. Note that
for the moment, the tricky cases that cannot be handled by these
expressions can be treated by programming the
AspectComponent.whenUsingNewInstance
method.
".*"
and the wrappee-class expression should be used."A || B"
says that only the classes that are
named A or B belong to the pointcut; packagename.* &&
classname
matches the class that belong to
packagename
and that are named
classname
."set.*(int):void"
matches all the methods that have
name that begins with "set", that take only one integer argument,
and that return nothing. The regular expression can contain several
builtin keywords to automatically match methods with special
semantics (for instance, ALL
: all the methods of the
class, MODIFIERS
: all the state modifiers,
ACCESSORS
: all the state setters,
GETTERS(fielname1,fieldname2)
: the getter for the
given field, SETTERS(...)
: the setter for the given
field), WRITERS(...)
: all the methods which modify the
given field. For instance, FIELDSETTERS && !.*(int).*
matches all the field setters, excluding the ones for the integer
fields.For more informations on pointcut expressions, please see the Renaud Pawlak
AspectComponent
,
Serialized Form
Constructor Summary | |
MethodPointcut(AspectComponent aspectComponent,
String wrappeeExpr,
String wrappeeClassExpr,
String wrappeeMethodExpr,
Wrapper initWrapper,
String wrappingClassName,
String methodName,
Object[] methodArgs,
String hostExpr,
String exceptionHandler,
boolean one2one)
Instantiates a new pointcut with the given characterisitics. |
Method Summary | |
void |
applyTo(Wrappee wrappee,
ClassItem cl)
Applies this pointcut to the given wrappee. |
static gnu.regexp.RE |
buildRegexp(String pattern)
|
protected void |
filterMethodKeywords(Object wrappee,
ClassItem cli,
String expr,
boolean inv,
Collection source,
Collection dest)
Adds methods from source that match an expression to a collection |
static Collection |
filterObjects(Collection initial,
String filter)
Filters a collection of objects regarding an expression. |
protected Collection |
getMatchingMethodsFor(Wrappee wrappee,
ClassItem cli)
Gets the methods of the wrappee that are modified by this pointcut. |
protected Collection |
getMatchingStaticMethodsFor(ClassItem cli)
|
static Collection |
getRelatedObjects(Collection initial,
String relationExpr)
Gets all the objects that are related to a set of objects through relations that match the given expression. |
boolean |
isClassMatching(Wrappee wrappee,
ClassItem cl)
Tests if the given component class is modified (in a way or another) by this pointcut. |
boolean |
isHostMatching(Wrappee wrappee,
ClassItem cl)
Tests if the given component is modified (in a way or another) by this pointcut. |
static boolean |
isInPath(Object candidate,
String pathExpr)
Tells if this object is reachable for the given object path expression. |
boolean |
isMethodMatching(AbstractMethodItem method)
Tests if the given method item is modified (in a way or another) by this pointcut. |
boolean |
isNameMatching(Wrappee wrappee,
ClassItem cl)
Tests if the given component is modified (in a way or another) by this pointcut. |
boolean |
isNameMatching(Wrappee wrappee,
String name)
|
static boolean |
isPathExpression(String expr)
Tells if this expression is a path expression (of the form o/r/o...). |
protected String |
parseKeyword(Wrappee wrappee,
ClassItem cli,
String keywordExpr,
List parameters)
Parses a keyword expression and returns its actual value as a regular expression regarding the context. |
Collection |
parseMethodExpr(Wrappee wrappee,
ClassItem cli,
String expr)
|
String |
toString()
Returns a readable description of the pointcut. |
Methods inherited from class org.objectweb.jac.core.Pointcut |
parseExpr, replaceTags |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public MethodPointcut(AspectComponent aspectComponent, String wrappeeExpr, String wrappeeClassExpr, String wrappeeMethodExpr, Wrapper initWrapper, String wrappingClassName, String methodName, Object[] methodArgs, String hostExpr, String exceptionHandler, boolean one2one)
aspectComponent
- the aspect component this pointcut
belongs towrappeeExpr
- the wrappee definition that matches the names
as defined by the naming aspectwrappeeClassExpr
- the wrappee class expression (matches
the fully qualified class name)wrappeeMethodExpr
- the wrappee method expression (matches
the full method name as defined by the rtti)initWrapper
- the instance of the wrapper used by this
pointcut, if null a new one is automatically created depending
on the one2one flagwrappingClassName
- the name of the wrapper classmethodName
- the name of the aspect component
method to upcall when a mathing object is usedmethodArgs
- the argument values for this method
method to upcall when a matching object is usedhostExpr
- a regular expression that macthes the hosts
where the pointcut has to be applied (if null or empty string,
default is ".*" which means that the pointcut will be applied on
all the hosts)one2one
- true if each new wrapped instance corresponds to
one different wrapper (it has no effect if
initWrapper
is not nullMethod Detail |
public String toString()
toString
in class Object
public static gnu.regexp.RE buildRegexp(String pattern) throws gnu.regexp.REException
gnu.regexp.REException
public void applyTo(Wrappee wrappee, ClassItem cl)
The pointcut application consists in wrapping the wrappee accordingly to the pointcut description. Note that in JAC, the pointcut is usually applied on a per-component basis, and when the component (wrappee) is used for the first time.
applyTo
in class Pointcut
wrappee
- the component the pointcut is applied tocl
- class the pointcut is applied toprotected Collection getMatchingMethodsFor(Wrappee wrappee, ClassItem cli)
wrappee
- the component to testcli
- the class of the wrappee
protected Collection getMatchingStaticMethodsFor(ClassItem cli)
public Collection parseMethodExpr(Wrappee wrappee, ClassItem cli, String expr)
wrappee
- the object the pointcut applies tocli
- the class the pointcut applies to (in case
wrappee==null, for static methods)expr
- the pointcut expression
protected void filterMethodKeywords(Object wrappee, ClassItem cli, String expr, boolean inv, Collection source, Collection dest)
wrappee
- object to match withcli
- class to macth with, used if wrappee==nullexpr
- the expression to matchinv
- wether to keep or reject matching methodssource
- method items to chose fromdest
- collection to add the matching methods topublic boolean isClassMatching(Wrappee wrappee, ClassItem cl)
wrappee
- the component to test
public boolean isNameMatching(Wrappee wrappee, ClassItem cl)
Contrary to the class-based matching, this matching works on a per-component basis and not on a per-class basis. This is posible by using the naming aspect of the system (assuming it is there). If the naming aspect appears not to be woven, then all the components should mathes here.
wrappee
- the component to test
public boolean isNameMatching(Wrappee wrappee, String name)
public static boolean isPathExpression(String expr)
expr
- the expression to check
public static boolean isInPath(Object candidate, String pathExpr)
candidate
- the candidate objectpathExpr
- the path expression
public static Collection getRelatedObjects(Collection initial, String relationExpr)
initial
- the initial objectsrelationExpr
- the expression that matches the relations
public static Collection filterObjects(Collection initial, String filter)
initial
- the collection to filterfilter
- the filtering expression
public boolean isHostMatching(Wrappee wrappee, ClassItem cl)
Contrary to the class-based matching, this matching works on a per-component basis and not on a per-class basis. This is posible by using the naming aspect of the system (assuming it is there). If the naming aspect appears not to be woven, then all the components should mathes here.
wrappee
- the component to testcl
- the class, in case of static method
public boolean isMethodMatching(AbstractMethodItem method)
method
- the method to test
protected String parseKeyword(Wrappee wrappee, ClassItem cli, String keywordExpr, List parameters)
Pointcut
parseKeyword
in class Pointcut
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |