TrueMethodMatcher.java
上传用户:jiancairen
上传日期:2007-08-27
资源大小:26458k
文件大小:2k
源码类别:

Java编程

开发平台:

Java

  1. /*
  2.  * Copyright 2002-2004 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. package org.springframework.aop;
  17. import java.io.ObjectStreamException;
  18. import java.io.Serializable;
  19. import java.lang.reflect.Method;
  20. /**
  21.  * Canonical MethodMatcher instance that matches all methods.
  22.  * @author Rod Johnson
  23.  */
  24. class TrueMethodMatcher implements MethodMatcher, Serializable {
  25. public static final TrueMethodMatcher INSTANCE = new TrueMethodMatcher();
  26. /**
  27.  * Enforce Singleton
  28.  */
  29. private TrueMethodMatcher() {
  30. }
  31. public boolean isRuntime() {
  32. return false;
  33. }
  34. public boolean matches(Method m, Class targetClass) {
  35. return true;
  36. }
  37. public boolean matches(Method m, Class targetClass, Object[] args) {
  38. // should never be invoked as isRuntime returns false
  39. throw new UnsupportedOperationException();
  40. }
  41. /**
  42.  * Required to support serialization.
  43.  * Replaces with canonical instance on deserialization,
  44.  * protecting Singleton pattern. 
  45.  * Alternative to overriding equals().
  46.  */
  47. private Object readResolve() throws ObjectStreamException {
  48. return INSTANCE;
  49. }
  50. public String toString() {
  51. return "MethodMatcher.TRUE";
  52. }
  53. }