Overview | Package | Class | Tree | Deprecated | Index | Help
| Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.springframework.aop.target
Class AbstractLazyCreationTargetSource

    java.lang.Object
      org.springframework.aop.target.AbstractLazyCreationTargetSource

All Implemented Interfaces:
  TargetClassAware, TargetSource

    public abstract class AbstractLazyCreationTargetSource

extends java.lang.Object
implements TargetSource

`TargetSource` implementation that will lazily create 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, Juergen Hoeller
See Also:
  `isInitialized()`, `createObject()`

Field Summary
`protected org.apache.commons.logging.Log` | `logger` Logger available to subclasses

Constructor Summary
`AbstractLazyCreationTargetSource()`

Method Summary
`protected abstract java.lang.Object` | `createObject()` Subclasses should implement this method to return the lazy initialized object.
`java.lang.Object` | `getTarget()` Returns the lazy-initialized target object, creating it on-the-fly if it doesn't exist already.
`java.lang.Class<?>` | `getTargetClass()` This 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` | `isInitialized()` Return whether the lazy target object of this TargetSource has already been fetched.
`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.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### logger

    protected final org.apache.commons.logging.Log logger

  Logger available to subclasses

Constructor Detail

### AbstractLazyCreationTargetSource

    public AbstractLazyCreationTargetSource()

Method Detail

### isInitialized

    public boolean isInitialized()

  Return whether the lazy target object of this TargetSource has already been fetched.

### getTargetClass

    public java.lang.Class<?> getTargetClass()

  This 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.

  Subclasses may wish to override this method in order to provide a meaningful value when the target is still `null`.

  Specified by:
    `getTargetClass` in interface `TargetClassAware`
  Specified by:
    `getTargetClass` in interface `TargetSource`
  Returns:
    the type of targets returned by this `TargetSource`
  See Also:
    `isInitialized()`

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

### getTarget

    public java.lang.Object getTarget()
                               throws java.lang.Exception

  Returns the lazy-initialized target object, creating it on-the-fly if it doesn't exist already.

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

### releaseTarget

    public void releaseTarget(java.lang.Object target)
                       throws java.lang.Exception

  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()`
  Throws:
    `java.lang.Exception` - if the object can't be released

### createObject

    protected abstract java.lang.Object createObject()
                                              throws java.lang.Exception

  Subclasses should implement this method to return the lazy initialized object. Called the first time the proxy is invoked.

  Returns:
    the created object
  Throws:
    `java.lang.Exception` - if creation failed

Overview | Package | Class | Tree | Deprecated | Index | Help
| Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD