org.springframework.aop.target
Class HotSwappableTargetSource

java.lang.Object
  extended by org.springframework.aop.target.HotSwappableTargetSource
All Implemented Interfaces:
java.io.Serializable, TargetClassAware, TargetSource

public class HotSwappableTargetSource
extends java.lang.Object
implements TargetSource, java.io.Serializable

TargetSource implementation that caches a local target object, but allows the target to be swapped while the application is running.

If configuring an object of this class in a Spring IoC container, use constructor injection.

This TargetSource is serializable if the target is at the time of serialization.

Author:
Rod Johnson, Juergen Hoeller
See Also:
Serialized Form

Field Summary
private static long serialVersionUID
          use serialVersionUID from Spring 1.2 for interoperability
private  java.lang.Object target
          The current target object
 
Constructor Summary
HotSwappableTargetSource(java.lang.Object initialTarget)
          Create a new HotSwappableTargetSource with the given initial target object.
 
Method Summary
 boolean equals(java.lang.Object other)
          Two HotSwappableTargetSources are equal if the current target objects are equal.
 java.lang.Object getTarget()
          Return a target instance.
 java.lang.Class<?> getTargetClass()
          Return the type of the current target object.
 int hashCode()
           
 boolean isStatic()
          Will all calls to TargetSource.getTarget() return the same object?
 void releaseTarget(java.lang.Object target)
          Release the given target object obtained from the TargetSource.getTarget() method.
 java.lang.Object swap(java.lang.Object newTarget)
          Swap the target, returning the old target object.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
use serialVersionUID from Spring 1.2 for interoperability

See Also:
Constant Field Values

target

private java.lang.Object target
The current target object

Constructor Detail

HotSwappableTargetSource

public HotSwappableTargetSource(java.lang.Object initialTarget)
Create a new HotSwappableTargetSource with the given initial target object.

Parameters:
initialTarget - the initial target object
Method Detail

getTargetClass

public java.lang.Class<?> getTargetClass()
Return the type of the current target object.

The returned type should usually be constant across all target objects.

Specified by:
getTargetClass in interface TargetClassAware
Specified by:
getTargetClass in interface TargetSource
Returns:
the type of targets returned by this TargetSource

isStatic

public final boolean isStatic()
Description copied from interface: TargetSource
Will all calls to TargetSource.getTarget() return the same object?

In that case, there will be no need to invoke TargetSource.releaseTarget(Object), and the AOP framework can cache the return value of TargetSource.getTarget().

Specified by:
isStatic in interface TargetSource
Returns:
true if the target is immutable
See Also:
TargetSource.getTarget()

getTarget

public java.lang.Object getTarget()
Description copied from interface: TargetSource
Return a target instance. Invoked immediately before the AOP framework calls the "target" of an AOP method invocation.

Specified by:
getTarget in interface TargetSource
Returns:
the target object, which contains the joinpoint

releaseTarget

public void releaseTarget(java.lang.Object target)
Description copied from interface: TargetSource
Release the given target object obtained from the TargetSource.getTarget() method.

Specified by:
releaseTarget in interface TargetSource
Parameters:
target - object obtained from a call to TargetSource.getTarget()

swap

public java.lang.Object swap(java.lang.Object newTarget)
                      throws java.lang.IllegalArgumentException
Swap the target, returning the old target object.

Parameters:
newTarget - the new target object
Returns:
the old target object
Throws:
java.lang.IllegalArgumentException - if the new target is invalid

equals

public boolean equals(java.lang.Object other)
Two HotSwappableTargetSources are equal if the current target objects are equal.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object