1 16 17 package org.springframework.aop.target; 18 19 import java.io.Serializable ; 20 21 import org.springframework.aop.TargetSource; 22 import org.springframework.util.ObjectUtils; 23 24 32 public class EmptyTargetSource implements TargetSource, Serializable { 33 34 35 private static final long serialVersionUID = 3680494563553489691L; 36 37 38 42 45 public static final EmptyTargetSource INSTANCE = new EmptyTargetSource(null); 46 47 48 53 public static EmptyTargetSource forClass(Class targetClass) { 54 return (targetClass == null ? INSTANCE : new EmptyTargetSource(targetClass)); 55 } 56 57 58 62 private final Class targetClass; 63 64 65 71 private EmptyTargetSource(Class targetClass) { 72 this.targetClass = targetClass; 73 } 74 75 78 public Class getTargetClass() { 79 return this.targetClass; 80 } 81 82 85 public boolean isStatic() { 86 return true; 87 } 88 89 92 public Object getTarget() { 93 return null; 94 } 95 96 99 public void releaseTarget(Object target) { 100 } 101 102 103 107 private Object readResolve() { 108 return (this.targetClass == null ? INSTANCE : this); 109 } 110 111 public boolean equals(Object other) { 112 return (this == other || (other instanceof EmptyTargetSource && 113 ObjectUtils.nullSafeEquals(this.targetClass, ((EmptyTargetSource) other).targetClass))); 114 } 115 116 public int hashCode() { 117 return EmptyTargetSource.class.hashCode() * 13 + ObjectUtils.nullSafeHashCode(this.targetClass); 118 } 119 120 public String toString() { 121 return "EmptyTargetSource: " + 122 (this.targetClass != null ? "target class [" + this.targetClass + "]" : "no target class"); 123 } 124 125 } 126 | Popular Tags |