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. /**
  19. * Static methods useful for composing ClassFilters.
  20. * @author Rod Johnson
  21. * @since 11-Nov-2003
  22. * @version $Id: ClassFilters.java,v 1.3 2004/05/23 20:50:29 jhoeller Exp $
  23. */
  24. public abstract class ClassFilters {
  25. public static ClassFilter union(ClassFilter a, ClassFilter b) {
  26. return new UnionClassFilter(new ClassFilter[] { a, b } );
  27. }
  28. public static ClassFilter intersection(ClassFilter a, ClassFilter b) {
  29. return new IntersectionClassFilter(new ClassFilter[] { a, b } );
  30. }
  31. private static class UnionClassFilter implements ClassFilter {
  32. private ClassFilter[] filters;
  33. public UnionClassFilter(ClassFilter[] filters) {
  34. this.filters = filters;
  35. }
  36. public boolean matches(Class clazz) {
  37. for (int i = 0; i < filters.length; i++) {
  38. if (filters[i].matches(clazz)) {
  39. return true;
  40. }
  41. }
  42. return false;
  43. }
  44. }
  45. private static class IntersectionClassFilter implements ClassFilter {
  46. private ClassFilter[] filters;
  47. public IntersectionClassFilter(ClassFilter[] filters) {
  48. this.filters = filters;
  49. }
  50. public boolean matches(Class clazz) {
  51. for (int i = 0; i < filters.length; i++) {
  52. if (!filters[i].matches(clazz)) {
  53. return false;
  54. }
  55. }
  56. return true;
  57. }
  58. }
  59. }