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 org.springframework.aop.ClassFilter;
  18. import org.springframework.aop.MethodMatcher;
  19. import org.springframework.aop.Pointcut;
  20. /**
  21. * Convenient class for building up pointcuts.
  22. * All methods return ComposablePointcut, so we can use a concise
  23. * idiom like:
  24. * <code>
  25. * Pointcut pc = new ComposablePointcut().union(classFilter).intersection(methodMatcher).intersection(pointcut);
  26. * </code>
  27. * There is no union() method on this class. Use the Pointcuts.union()
  28. * method for this.
  29. * @author Rod Johnson
  30. * @since 11-Nov-2003
  31. * @version $Id: ComposablePointcut.java,v 1.5 2004/03/18 02:46:11 trisberg Exp $
  32. */
  33. public class ComposablePointcut implements Pointcut {
  34. private ClassFilter classFilter;
  35. private MethodMatcher methodMatcher;
  36. public ComposablePointcut() {
  37. this.classFilter = ClassFilter.TRUE;
  38. this.methodMatcher = MethodMatcher.TRUE;
  39. }
  40. public ComposablePointcut(ClassFilter classFilter, MethodMatcher methodMatcher) {
  41. this.classFilter = classFilter;
  42. this.methodMatcher = methodMatcher;
  43. }
  44. public ComposablePointcut union(ClassFilter filter) {
  45. this.classFilter = ClassFilters.union(this.classFilter, filter);
  46. return this;
  47. }
  48. public ComposablePointcut intersection(ClassFilter filter) {
  49. this.classFilter = ClassFilters.intersection(this.classFilter, filter);
  50. return this;
  51. }
  52. public ComposablePointcut union(MethodMatcher mm) {
  53. this.methodMatcher = MethodMatchers.union(this.methodMatcher, mm);
  54. return this;
  55. }
  56. public ComposablePointcut intersection(MethodMatcher mm) {
  57. this.methodMatcher = MethodMatchers.intersection(this.methodMatcher, mm);
  58. return this;
  59. }
  60. public ComposablePointcut intersection(Pointcut other) {
  61. this.classFilter = ClassFilters.intersection(this.classFilter, other.getClassFilter());
  62. this.methodMatcher = MethodMatchers.intersection(this.methodMatcher, other.getMethodMatcher());
  63. return this;
  64. }
  65. public ClassFilter getClassFilter() {
  66. return this.classFilter;
  67. }
  68. public MethodMatcher getMethodMatcher() {
  69. return this.methodMatcher;
  70. }
  71. }