Save This Page
Home » spring-framework-2.5.5-with-dependencies » org.springframework » beans » factory » config » [javadoc | source]
org.springframework.beans.factory.config
public class: PropertyPathFactoryBean [javadoc | source]
java.lang.Object
   org.springframework.beans.factory.config.PropertyPathFactoryBean

All Implemented Interfaces:
    BeanFactoryAware, BeanNameAware, FactoryBean

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!
Method from org.springframework.beans.factory.config.PropertyPathFactoryBean Summary:
getObject,   getObjectType,   isSingleton,   setBeanFactory,   setBeanName,   setPropertyPath,   setResultType,   setTargetBeanName,   setTargetObject
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.springframework.beans.factory.config.PropertyPathFactoryBean Detail:
 public Object getObject() throws BeansException 
 public Class getObjectType() 
 public boolean isSingleton() 
    While this FactoryBean will often be used for singleton targets, the invoked getters for the property path might return a new object for each call, so we have to assume that we're not returning the same object for each #getObject() call.
 public  void setBeanFactory(BeanFactory beanFactory) 
 public  void setBeanName(String beanName) 
    The bean name of this PropertyPathFactoryBean will be interpreted as "beanName.property" pattern, if neither "targetObject" nor "targetBeanName" nor "propertyPath" have been specified. This allows for concise bean definitions with just an id/name.
 public  void setPropertyPath(String propertyPath) 
    Specify the property path to apply to the target.
 public  void setResultType(Class resultType) 
    Specify the type of the result from evaluating the property path.

    Note: This is not necessary for directly specified target objects or singleton target beans, where the type can be determined through introspection. Just specify this in case of a prototype target, provided that you need matching by type (for example, for autowiring).

 public  void setTargetBeanName(String targetBeanName) 
    Specify the name of a target bean to apply the property path to. Alternatively, specify a target object directly.
 public  void setTargetObject(Object targetObject) 
    Specify a target object to apply the property path to. Alternatively, specify a target bean name.