01: /*
02: * Copyright 2002-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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;
18:
19: import java.io.Serializable;
20: import java.lang.reflect.Method;
21:
22: /**
23: * Canonical MethodMatcher instance that matches all methods.
24: *
25: * @author Rod Johnson
26: */
27: class TrueMethodMatcher implements MethodMatcher, Serializable {
28:
29: public static final TrueMethodMatcher INSTANCE = new TrueMethodMatcher();
30:
31: /**
32: * Enforce Singleton pattern.
33: */
34: private TrueMethodMatcher() {
35: }
36:
37: public boolean isRuntime() {
38: return false;
39: }
40:
41: public boolean matches(Method method, Class targetClass) {
42: return true;
43: }
44:
45: public boolean matches(Method method, Class targetClass,
46: Object[] args) {
47: // Should never be invoked as isRuntime returns false.
48: throw new UnsupportedOperationException();
49: }
50:
51: /**
52: * Required to support serialization. Replaces with canonical
53: * instance on deserialization, protecting Singleton pattern.
54: * Alternative to overriding <code>equals()</code>.
55: */
56: private Object readResolve() {
57: return INSTANCE;
58: }
59:
60: public String toString() {
61: return "MethodMatcher.TRUE";
62: }
63:
64: }
|