/*
 * Copyright 2002-2005 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.aop.target;

import org.springframework.beans.BeansException;

/**
 * TargetSource that lazily accesses a singleton from a BeanFactory.
 *
 * <p>Useful when a proxy reference is needed on initialization but
 * the actual target object should not be initialized until first use.
 * The target bean must me marked as "lazy-init" too, else it would get
 * instantiated by the BeanFactory on startup. For example:
 *
 * <pre>
 * &lt;bean id="serviceTarget" class="example.MyService" lazy-init="true"&gt;
 *   ...
 * &lt;/bean&gt;
 *
 * &lt;bean id="service" class="org.springframework.aop.framework.ProxyFactoryBean"&gt;
 *   &lt;property name="targetSource"&gt;
 *     &lt;bean class="org.springframework.aop.target.LazyInitTargetSource"&gt;
 *       &lt;property name="targetBeanName"&gt;&lt;idref local="serviceTarget"/&gt;&lt;/property&gt;
 *     &lt;/bean&gt;
 *   &lt;/property&gt;
 * &lt;/bean&gt;</pre>
 *
 * The "serviceTarget" bean will not get initialized until a method on the
 * "service" proxy gets invoked.
 *
 * <p>Sub-classes can extend this class and override the {@link #postProcessTargetObject(Object)} to
 * perform some additional processing with the target object when it is first loaded.
 *
 * @author Juergen Hoeller
 * @author Rob Harrop
 * @since 1.1.4
 * @see #postProcessTargetObject(Object)
 */
public class LazyInitTargetSource extends AbstractBeanFactoryBasedTargetSource {

	private Object target;

	public synchronized Object getTarget() throws BeansException {
		if (this.target == null) {
			this.target = getBeanFactory().getBean(getTargetBeanName());
			postProcessTargetObject(this.target);
		}
		return this.target;
	}

	/**
	 * Sub-classes may override this method to perform additional processing on
	 * the target object when it is first loaded.
	 */
	protected void postProcessTargetObject(Object targetObject) {
	}

}

@@ -713,16 +713,47 @@
 %0A/**%0A * 
+%7B@link org.springframework.aop.
 TargetSo
@@ -756,16 +756,17 @@
 etSource
+%7D
  that la
@@ -778,16 +778,19 @@
 accesses
+%0A *
  a singl
@@ -798,15 +798,61 @@
 ton 
+bean 
 from a 
+%7B@link org.springframework.beans.factory.
 Bean
@@ -858,16 +858,17 @@
 nFactory
+%7D
 .%0A *%0A * 
@@ -1006,17 +1006,22 @@
 use.%0A * 
-T
+When t
 he targe
@@ -1031,14 +1031,180 @@
 ean 
-must m
+is defined in an%0A * %7B@link org.springframework.context.ApplicationContext%7D (or a%0A * %3Ccode%3EBeanFactory%3C/code%3E that is eagerly pre-instantiating singleton beans)%0A * it must b
 e ma
@@ -1241,19 +1241,14 @@
 it w
-ould get%0A *
+ill be
  ins
@@ -1260,20 +1260,66 @@
 ated by 
-the 
+said%0A * %3Ccode%3EApplicationContext%3C/code%3E (or %3Ccode%3E
 BeanFact
@@ -1321,16 +1321,24 @@
 nFactory
+%3C/code%3E)
  on star
@@ -1341,17 +1341,23 @@
 startup.
- 
+%0A * %3Cp%3E
 For exam
@@ -2736,16 +2736,107 @@
 loaded.%0A
+%09 * @param targetObject the target object that has just been instantiated (and configured)%0A
 %09 */%0A%09pr

Corrected Javadoc typo.