Most Java developers are used to creating Java classes that conform to the
JavaBeans naming patterns for property getters and setters. It is natural to
then access these methods directly, using calls to the corresponding
getXxx
and setXxx
methods. However, there are some
occasions where dynamic access to Java object properties (without compiled-in
knowledge of the property getter and setter methods to be called) is needed.
Example use cases include:
server.xml
file).The Java language provides Reflection and Introspection
APIs (see the java.lang.reflect
and java.beans
packages in the JDK Javadocs). However, these APIs can be quite complex to
understand and utilize. The proposed BeanUtils component provides
easy-to-use wrappers around these capabilities.
This proposal is to create a package of Java utility methods for accessing and modifying the properties of arbitrary JavaBeans. No dependencies outside of the JDK are required, so the use of this package is very lightweight.
In addition to wrapping the reflection and introspection APIs of the standard JDK, BeanUtils components shall support a syntax for directly accessing nested and indexed properties, in a manner that will be familar to users of scripting languages like JavaScript. For example, the following property accessor expressions are supported:
getCustomer()
.getCustomer().getAddress()
.getCustomer().getAddress(2).getStreet()
(access to indexed
properties also works if the underlying property is an array rather than
providing indexed getter and setter methods).BeanUtils relies only on standard JDK 1.2 (or later) APIs for production deployment. It utilizes the JUnit unit testing framework for developing and executing unit tests, but this is of interest only to developers of the component. BeanUtils will also be a dependency for several future proposed components for the Jakarta Commons subproject.
No external configuration files are utilized.
The three original Java classes (BeanUtils
,
ConvertUtils
, and PropertyUtils
) are an integral
part of the Struts Framework.
However, they have very few dependencies on other aspects of Struts, and
those dependencies have been removed in the proposed code base.
Once accepted and released as a Jakarta Commons component, Struts will
be modified to use the Commons version of these classes, and its internal
versions will be deprecated.
The proposed package name for the new component is
org.apache.commons.beanutils
.
beanutils
in the
jakarta-commons
CVS repository. All initial committers
are already committers on jakarta-commons
, so no
additional user setups are required.The initial committers on the BeanUtils component shall be Craig McClanahan and Geir Magnusson Jr.