org.springframework.beans.factory.config.PropertyPathFactoryBean Maven / Gradle / Ivy
/*
* Copyright 2002-2017 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
*
* https://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.beans.factory.config;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeansException;
import org.springframework.beans.PropertyAccessorFactory;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* {@link FactoryBean} that evaluates a property path on a given target object.
*
* The target object can be specified directly or via a bean name.
*
*
Usage examples:
*
*
<!-- target bean to be referenced by name -->
* <bean id="tb" class="org.springframework.beans.TestBean" singleton="false">
* <property name="age" value="10"/>
* <property name="spouse">
* <bean class="org.springframework.beans.TestBean">
* <property name="age" value="11"/>
* </bean>
* </property>
* </bean>
*
* <!-- will result in 12, which is the value of property 'age' of the inner bean -->
* <bean id="propertyPath1" class="org.springframework.beans.factory.config.PropertyPathFactoryBean">
* <property name="targetObject">
* <bean class="org.springframework.beans.TestBean">
* <property name="age" value="12"/>
* </bean>
* </property>
* <property name="propertyPath" value="age"/>
* </bean>
*
* <!-- will result in 11, which is the value of property 'spouse.age' of bean 'tb' -->
* <bean id="propertyPath2" class="org.springframework.beans.factory.config.PropertyPathFactoryBean">
* <property name="targetBeanName" value="tb"/>
* <property name="propertyPath" value="spouse.age"/>
* </bean>
*
* <!-- will result in 10, which is the value of property 'age' of bean 'tb' -->
* <bean id="tb.age" class="org.springframework.beans.factory.config.PropertyPathFactoryBean"/>
*
* If you are using Spring 2.0 and XML Schema support in your configuration file(s),
* you can also use the following style of configuration for property path access.
* (See also the appendix entitled 'XML Schema-based configuration' in the Spring
* reference manual for more examples.)
*
*
<!-- will result in 10, which is the value of property 'age' of bean 'tb' -->
* <util:property-path id="name" path="testBean.age"/>
*
* Thanks to Matthias Ernst for the suggestion and initial prototype!
*
* @author Juergen Hoeller
* @since 1.1.2
* @see #setTargetObject
* @see #setTargetBeanName
* @see #setPropertyPath
*/
public class PropertyPathFactoryBean implements FactoryBean