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.aopalliance.aop.Advice;
  18. import org.springframework.aop.Pointcut;
  19. import org.springframework.aop.PointcutAdvisor;
  20. import org.springframework.core.Ordered;
  21. /**
  22. * Convenient pointcut-driven advisor implementation, implementing
  23. * the getPointcut() and isPerInstance() methods.
  24. *
  25. * <p>This is the most commonly used Advisor implementation. It can be
  26. * used with any pointcut and advice type, except for introductions.
  27. *
  28. * @author Rod Johnson
  29. * @version $Id: DefaultPointcutAdvisor.java,v 1.7 2004/03/23 14:29:45 jhoeller Exp $
  30. */
  31. public class DefaultPointcutAdvisor implements PointcutAdvisor, Ordered {
  32. private int order = Integer.MAX_VALUE;
  33. private Pointcut pointcut;
  34. private Advice advice;
  35. public DefaultPointcutAdvisor() {
  36. }
  37. public DefaultPointcutAdvisor(Advice advice) {
  38. this(Pointcut.TRUE, advice);
  39. }
  40. public DefaultPointcutAdvisor(Pointcut pointcut, Advice advice) {
  41. this.pointcut = pointcut;
  42. this.advice = advice;
  43. }
  44. public void setOrder(int order) {
  45. this.order = order;
  46. }
  47. public int getOrder() {
  48. return order;
  49. }
  50. public void setAdvice(Advice advice) {
  51. this.advice = advice;
  52. }
  53. public Advice getAdvice() {
  54. return advice;
  55. }
  56. public Pointcut getPointcut() {
  57. return pointcut;
  58. }
  59. public void setPointcut(Pointcut pointcut) {
  60. this.pointcut = pointcut;
  61. }
  62. public boolean isPerInstance() {
  63. throw new UnsupportedOperationException("perInstance property of Advisor is not yet supported in Spring");
  64. }
  65. public boolean equals(Object o) {
  66. if (!(o instanceof DefaultPointcutAdvisor)) {
  67. return false;
  68. }
  69. DefaultPointcutAdvisor other = (DefaultPointcutAdvisor) o;
  70. return other.advice.equals(this.advice) && other.pointcut.equals(this.pointcut);
  71. }
  72. public String toString() {
  73. return "DefaultPointcutAdvisor: pointcut=[" + pointcut + "] advice=[" + advice + "]";
  74. }
  75. }