org.springframework.aop.target
Class AbstractLazyInitTargetSource

java.lang.Object
  extended by org.springframework.aop.target.AbstractLazyInitTargetSource
All Implemented Interfaces:
TargetSource

public abstract class AbstractLazyInitTargetSource
extends Object
implements TargetSource

TargetSource that will lazy initialize a user-managed object.

Creation of the lazy target object is controlled by the user by implementing the createObject() method. This TargetSource will invoke this method the first time the proxy is accessed.

Useful when you need to pass a reference to some dependency to an object but you don't actually want the dependency to be created until it is first used. A typical scenario for this is a connection to a remote resource

Since:
1.2.4
Author:
Rob Harrop
See Also:
createObject()

Field Summary
protected  Log logger
          Log instance for this class and sub-classes
 
Constructor Summary
AbstractLazyInitTargetSource()
           
 
Method Summary
protected abstract  Object createObject()
          Sub-classes should implement this method to return the lazy initialized object.
 Object getTarget()
          Returns the lazy-initialized target object, creating it if it doesn't exist.
 Class getTargetClass()
          Default implementation returns null if the target is null (it is hasn't yet been initialized) or the target class if the target has already been initialized.
 boolean isStatic()
          Will all calls to getTarget() return the same object?
 void releaseTarget(Object target)
          No need to release target - no op.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final Log logger
Log instance for this class and sub-classes

Constructor Detail

AbstractLazyInitTargetSource

public AbstractLazyInitTargetSource()
Method Detail

getTargetClass

public Class getTargetClass()
Default implementation returns null if the target is null (it is hasn't yet been initialized) or the target class if the target has already been initialized. Sub-classes may wish to override this method to provide more meaningful values when the target is still null.

Specified by:
getTargetClass in interface TargetSource

isStatic

public boolean isStatic()
Description copied from interface: TargetSource
Will all calls to getTarget() return the same object? In that case, there will be no need to invoke releaseTarget, and the AOP framework can cache the return value of getTarget().

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

getTarget

public Object getTarget()
                 throws Exception
Returns the lazy-initialized target object, creating it if it doesn't exist.

Specified by:
getTarget in interface TargetSource
Returns:
the target object, whicch contains the joinpoint
Throws:
Exception - if the target object can't be resolved
See Also:
createObject()

releaseTarget

public void releaseTarget(Object target)
                   throws Exception
No need to release target - no op.

Specified by:
releaseTarget in interface TargetSource
Parameters:
target - object obtained from a call to getTarget()
Throws:
Exception - if the object can't be released
See Also:
TargetSource.getTarget()

createObject

protected abstract Object createObject()
                                throws Exception
Sub-classes should implement this method to return the lazy initialized object. Called the first time the proxy is invoked.

Throws:
Exception


Copyright (c) 2002-2005 The Spring Framework Project.