KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > aop > framework > MethodMatchers


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.aop.framework;
18
19 import java.lang.reflect.Method JavaDoc;
20
21 import org.springframework.aop.MethodMatcher;
22
23 /**
24  * Static methods useful for composing Pointcuts.
25  * A MethodMatcher may be evaluated statically (based on Method and target class)
26  * or need further evaluation dynamically (based on arguments at the time of
27  * method invocation).
28  *
29  * @author Rod Johnson
30  * @since 11.11.2003
31  */

32 public abstract class MethodMatchers {
33
34     public static MethodMatcher union(MethodMatcher a, MethodMatcher b) {
35         return new UnionMethodMatcher(a, b);
36     }
37     public static MethodMatcher intersection(MethodMatcher a, MethodMatcher b) {
38         return new IntersectionMethodMatcher(a, b);
39     }
40     
41     
42     private static class UnionMethodMatcher implements MethodMatcher {
43         
44         private MethodMatcher a;
45         private MethodMatcher b;
46         
47         public UnionMethodMatcher(MethodMatcher a, MethodMatcher b) {
48             this.a = a;
49             this.b = b;
50         }
51
52         public boolean matches(Method JavaDoc m, Class JavaDoc targetClass) {
53             return a.matches(m, targetClass) || b.matches(m, targetClass);
54         }
55         
56         public boolean isRuntime() {
57             return a.isRuntime() || b.isRuntime();
58         }
59         
60         public boolean matches(Method JavaDoc m, Class JavaDoc targetClass, Object JavaDoc[] args) {
61             return a.matches(m, targetClass, args) || b.matches(m, targetClass, args);
62         }
63         
64     }
65     
66     private static class IntersectionMethodMatcher implements MethodMatcher {
67         
68         private MethodMatcher a;
69         private MethodMatcher b;
70     
71         public IntersectionMethodMatcher(MethodMatcher a, MethodMatcher b) {
72             this.a = a;
73             this.b = b;
74         }
75
76
77         public boolean matches(Method JavaDoc m, Class JavaDoc targetClass) {
78             return a.matches(m, targetClass) && b.matches(m, targetClass);
79         }
80         
81         public boolean isRuntime() {
82             return a.isRuntime() || b.isRuntime();
83         }
84         
85         public boolean matches(Method JavaDoc m, Class JavaDoc targetClass, Object JavaDoc[] args) {
86             return a.matches(m, targetClass, args) && b.matches(m, targetClass, args);
87         }
88     
89     }
90
91 }
92
Popular Tags