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.support;
  17. import java.lang.reflect.Method;
  18. import org.springframework.aop.MethodMatcher;
  19. import org.springframework.aop.Pointcut;
  20. /**
  21. * Static methods useful for manipulating and evaluating pointcuts.
  22. * This methods are particularly useful for composing pointcuts
  23. * using the union and intersection methods.
  24. * @author Rod Johnson
  25. * @version $Id: Pointcuts.java,v 1.5 2004/03/18 02:46:11 trisberg Exp $
  26. */
  27. public abstract class Pointcuts {
  28. public static Pointcut union(Pointcut a, Pointcut b) {
  29. return new UnionPointcut(a, b);
  30. }
  31. public static Pointcut intersection(Pointcut a, Pointcut b) {
  32. return new ComposablePointcut(a.getClassFilter(), a.getMethodMatcher()).intersection(b);
  33. }
  34. /**
  35. * Perform the least expensive check for a match.
  36. */
  37. public static boolean matches(Pointcut pc, Method m, Class targetClass, Object[] arguments) {
  38. if (pc == Pointcut.TRUE) {
  39. return true;
  40. }
  41. if (pc.getClassFilter().matches(targetClass)) {
  42. // Only check if it gets past first hurdle
  43. MethodMatcher mm = pc.getMethodMatcher();
  44. if (mm.matches(m, targetClass)) {
  45. // We may need additional runtime (argument) check
  46. return mm.isRuntime() ? mm.matches(m, targetClass, arguments) : true;
  47. }
  48. }
  49. return false;
  50. }
  51. public static boolean equals(Pointcut a, Pointcut b) {
  52. return a.getClassFilter() == b.getClassFilter() &&
  53. a.getMethodMatcher() == b.getMethodMatcher();
  54. }
  55. }