org.springframework.aop.target
Class AbstractBeanFactoryBasedTargetSource

java.lang.Object
  extended byorg.springframework.aop.target.AbstractBeanFactoryBasedTargetSource
All Implemented Interfaces:
BeanFactoryAware, Serializable, TargetSource
Direct Known Subclasses:
AbstractPrototypeBasedTargetSource, LazyInitTargetSource

public abstract class AbstractBeanFactoryBasedTargetSource
extends Object
implements TargetSource, BeanFactoryAware, Serializable

Base class for TargetSource implementations that are based on a Spring BeanFactory, delegating to Spring-managed bean instances.

Subclasses can create prototype instances or lazily access a singleton target, for example. See LazyInitTargetSource and AbstractPrototypeBasedTargetSource's subclasses for concrete strategies.

BeanFactoryBasedTargetSources are serializable. This involves disconnecting the current target and turning into a SingletonTargetSource.

Since:
1.1.4
Author:
Juergen Hoeller, Rod Johnson
See Also:
BeanFactory.getBean(java.lang.String), LazyInitTargetSource, PrototypeTargetSource, ThreadLocalTargetSource, CommonsPoolTargetSource, Serialized Form

Field Summary
protected  Log logger
           
 
Constructor Summary
AbstractBeanFactoryBasedTargetSource()
           
 
Method Summary
 BeanFactory getBeanFactory()
          Return the owning BeanFactory.
 String getTargetBeanName()
          Return the name of the target bean in the factory.
 Class getTargetClass()
          Return the type of targets returned by this TargetSource.
 boolean isStatic()
          Will all calls to getTarget() return the same object?
 void releaseTarget(Object target)
          Release the given target object obtained from the getTarget() method.
 void setBeanFactory(BeanFactory beanFactory)
          Set the owning BeanFactory.
 void setTargetBeanName(String targetBeanName)
          Set the name of the target bean in the factory.
protected  Object writeReplace()
          Replaces this object with a SingletonTargetSource on serialization.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.springframework.aop.TargetSource
getTarget
 

Field Detail

logger

protected final Log logger
Constructor Detail

AbstractBeanFactoryBasedTargetSource

public AbstractBeanFactoryBasedTargetSource()
Method Detail

setTargetBeanName

public void setTargetBeanName(String targetBeanName)
Set the name of the target bean in the factory. This bean should be a prototype, or the same instance will always be obtained from the factory, resulting in the same behavior as the SingletonTargetSource.

Parameters:
targetBeanName - name of the target bean in the BeanFactory that owns this interceptor
See Also:
SingletonTargetSource

getTargetBeanName

public String getTargetBeanName()
Return the name of the target bean in the factory.


setBeanFactory

public void setBeanFactory(BeanFactory beanFactory)
                    throws BeansException
Set the owning BeanFactory. We need to save a reference so that we can use the getBean method on every invocation.

Specified by:
setBeanFactory in interface BeanFactoryAware
Parameters:
beanFactory - owning BeanFactory (may not be null). The bean can immediately call methods on the factory.
Throws:
BeansException - in case of initialization errors
See Also:
BeanInitializationException

getBeanFactory

public BeanFactory getBeanFactory()
Return the owning BeanFactory.


getTargetClass

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

releaseTarget

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

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

writeReplace

protected Object writeReplace()
                       throws ObjectStreamException
Replaces this object with a SingletonTargetSource on serialization. Protected as otherwise it won't be invoked for subclasses. (The writeReplace() method must be visible to the class being serialized.)

With this implementation of this method, there is no need to mark non-serializable fields in this class or subclasses as transient.

Throws:
ObjectStreamException


Copyright (C) 2003-2004 The Spring Framework Project.