testInvoke(proxy);
System.out.println("Test 3");
pc.intersection(new GetAgeMethodMatcher());
proxy = getProxy(pc, target);
testInvoke(proxy);
}
private static SampleBean getProxy(ComposablePointcut pc,
SampleBean target) {
// create the advisor
Advisor advisor = new DefaultPointcutAdvisor(pc,
new SimpleBeforeAdvice());
// create the proxy
ProxyFactory pf = new ProxyFactory();
pf.setTarget(target);
pf.addAdvisor(advisor);
return (SampleBean) pf.getProxy();
}
private static void testInvoke(SampleBean proxy) {
proxy.getAge();
proxy.getName();
proxy.setName("Clarence Ho");
}
private static class GetterMethodMatcher extends StaticMethodMatcher {
public boolean matches(Method method, Class<?> cls) {
return (method.getName().startsWith("get"));
}
}
private static class GetAgeMethodMatcher extends StaticMethodMatcher {
public boolean matches(Method method, Class<?> cls) {
return "getAge".equals(method.getName());
}
}
private static class SetterMethodMatcher extends StaticMethodMatcher {
public boolean matches(Method method, Class<?> cls) {
return (method.getName().startsWith("set"));
}
}
}
The first thing to notice in this example is the set of three private MethodMatcher implementations.
The GetterMethodMatcher matches all methods that start with get. This is the default MethodMatcher that
we use to assemble the ComposablePointcut. Because of this, we expect that the first round of invocations
on the SampleBean methods will result in only the getAge() and getName() methods being advised.
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home