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.target;
  17. import org.springframework.aop.TargetSource;
  18. /**
  19. * Implementation of the TargetSource interface that
  20. * holds a local object. This is the default implementation of TargetSource
  21. * used by the AOP framework. There is no need to create objects of this
  22. * class in application code.
  23. * @author Rod Johnson
  24. * @version $Id: SingletonTargetSource.java,v 1.5 2004/03/18 02:46:13 trisberg Exp $
  25. */
  26. public final class SingletonTargetSource implements TargetSource {
  27. /** Target cached and invoked using reflection */
  28. private Object target;
  29. public SingletonTargetSource(Object target) {
  30. this.target = target;
  31. }
  32. public Class getTargetClass() {
  33. return target.getClass();
  34. }
  35. public Object getTarget() {
  36. return this.target;
  37. }
  38. public void releaseTarget(Object o) {
  39. }
  40. public String toString() {
  41. return "Singleton target source (not dynamic): target=[" + target + "]";
  42. }
  43. /**
  44. * @see org.springframework.aop.TargetSource#isStatic()
  45. */
  46. public boolean isStatic() {
  47. return true;
  48. }
  49. /**
  50. * Two invoker interceptors are equal if they have the same target or if the targets
  51. * or the targets are equal.
  52. */
  53. public boolean equals(Object other) {
  54. if (this == other)
  55. return true;
  56. if (!(other instanceof SingletonTargetSource))
  57. return false;
  58. SingletonTargetSource b = (SingletonTargetSource) other;
  59. if (this.target == null)
  60. return b.target == null;
  61. return this.target.equals(b.target);
  62. }
  63. }