org.springframework.aop.target
Class SingletonTargetSource

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

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

Implementation of the TargetSource interface that holds a given object. This is the default implementation of the TargetSource interface, as used by the Spring AOP framework. There is usually no need to create objects of this class in application code.

This class is serializable. However, the actual serializability of a SingletonTargetSource will depend on whether the target is serializable.

Author:
Rod Johnson, Juergen Hoeller
See Also:
AdvisedSupport.setTarget(Object), Serialized Form

Field Summary
private static long serialVersionUID
          use serialVersionUID from Spring 1.2 for interoperability
private  java.lang.Object target
          Target cached and invoked using reflection
 
Constructor Summary
SingletonTargetSource(java.lang.Object target)
          Create a new SingletonTargetSource for the given target.
 
Method Summary
 boolean equals(java.lang.Object other)
          Two invoker interceptors are equal if they have the same target or if the targets or the targets are equal.
 java.lang.Object getTarget()
          Return a target instance.
 java.lang.Class<?> getTargetClass()
          Return the type of targets returned by this TargetSource.
 int hashCode()
          SingletonTargetSource uses the hash code of the target object.
 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.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 final java.lang.Object target
Target cached and invoked using reflection

Constructor Detail

SingletonTargetSource

public SingletonTargetSource(java.lang.Object target)
Create a new SingletonTargetSource for the given target.

Parameters:
target - the target object
Method Detail

getTargetClass

public java.lang.Class<?> getTargetClass()
Description copied from interface: TargetSource
Return the type of targets returned by this TargetSource.

Can return null, although certain usages of a TargetSource might just work with a predetermined target class.

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

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()

isStatic

public 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()

equals

public boolean equals(java.lang.Object other)
Two invoker interceptors are equal if they have the same target or if the targets or the targets are equal.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
SingletonTargetSource uses the hash code of the target object.

Overrides:
hashCode in class java.lang.Object

toString

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