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.Assert; 23 24 38 public class HotSwappableTargetSource implements TargetSource, Serializable { 39 40 41 private static final long serialVersionUID = 7497929212653839187L; 42 43 44 45 private Object target; 46 47 48 52 public HotSwappableTargetSource(Object initialTarget) { 53 Assert.notNull(initialTarget, "Target object must not be null"); 54 this.target = initialTarget; 55 } 56 57 58 62 public synchronized Class getTargetClass() { 63 return this.target.getClass(); 64 } 65 66 public final boolean isStatic() { 67 return false; 68 } 69 70 public synchronized Object getTarget() { 71 return this.target; 72 } 73 74 public void releaseTarget(Object target) { 75 } 77 78 79 85 public synchronized Object swap(Object newTarget) throws IllegalArgumentException { 86 Assert.notNull(newTarget, "Target object must not be null"); 87 Object old = this.target; 88 this.target = newTarget; 89 return old; 90 } 91 92 93 97 public boolean equals(Object other) { 98 return (this == other || (other instanceof HotSwappableTargetSource && 99 this.target.equals(((HotSwappableTargetSource) other).target))); 100 } 101 102 public int hashCode() { 103 return HotSwappableTargetSource.class.hashCode(); 104 } 105 106 public String toString() { 107 return "HotSwappableTargetSource for target: " + this.target; 108 } 109 110 } 111 | Popular Tags |