Java Doc for BeanUtilsBean.java in  » Library » Apache-commons-beanutils-1.8.0-BETA-src » org » apache » commons » beanutils » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Library » Apache commons beanutils 1.8.0 BETA src » org.apache.commons.beanutils 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.apache.commons.beanutils.BeanUtilsBean

All known Subclasses:   org.apache.commons.beanutils.locale.LocaleBeanUtilsBean,  org.apache.commons.beanutils.BeanUtilsBean2,
BeanUtilsBean
public class BeanUtilsBean (Code)

JavaBean property population methods.

This class provides implementations for the utility methods in BeanUtils . Different instances can be used to isolate caches between classloaders and to vary the value converters registered.


author:
   Craig R. McClanahan
author:
   Ralph Schaer
author:
   Chris Audley
author:
   Rey Francois
author:
   Gregor Rayman
version:
   $Revision: 556229 $ $Date: 2007-07-14 07:11:19 +0100 (Sat, 14 Jul 2007) $
See Also:   BeanUtils
since:
   1.7



Constructor Summary
public  BeanUtilsBean()
    
public  BeanUtilsBean(ConvertUtilsBean convertUtilsBean)
    
public  BeanUtilsBean(ConvertUtilsBean convertUtilsBean, PropertyUtilsBean propertyUtilsBean)
    

Method Summary
public  ObjectcloneBean(Object bean)
    

Clone a bean based on the available property getters and setters, even if the bean class itself does not implement Cloneable.

Note: this method creates a shallow clone.

protected  Objectconvert(Object value, Class type)
    
public  voidcopyProperties(Object dest, Object orig)
    

Copy property values from the origin bean to the destination bean for all cases where the property names are the same.

public  voidcopyProperty(Object bean, String name, Object value)
    

Copy the specified property value to the specified destination bean, performing any type conversion that is required.

public  Mapdescribe(Object bean)
    

Return the entire set of properties for which the specified bean provides a read method.

public  String[]getArrayProperty(Object bean, String name)
     Return the value of the specified array property of the specified bean, as a String array.
public  ConvertUtilsBeangetConvertUtils()
     Gets the ConvertUtilsBean instance used to perform the conversions.
public  StringgetIndexedProperty(Object bean, String name)
     Return the value of the specified indexed property of the specified bean, as a String.
public  StringgetIndexedProperty(Object bean, String name, int index)
     Return the value of the specified indexed property of the specified bean, as a String.
public static  BeanUtilsBeangetInstance()
     Gets the instance which provides the functionality for BeanUtils .
public  StringgetMappedProperty(Object bean, String name)
     Return the value of the specified indexed property of the specified bean, as a String.
public  StringgetMappedProperty(Object bean, String name, String key)
     Return the value of the specified mapped property of the specified bean, as a String.
public  StringgetNestedProperty(Object bean, String name)
     Return the value of the (possibly nested) property of the specified name, for the specified bean, as a String.
public  StringgetProperty(Object bean, String name)
     Return the value of the specified property of the specified bean, no matter which property reference format is used, as a String.
public  PropertyUtilsBeangetPropertyUtils()
     Gets the PropertyUtilsBean instance used to access properties.
public  StringgetSimpleProperty(Object bean, String name)
     Return the value of the specified simple property of the specified bean, converted to a String.
public  booleaninitCause(Throwable throwable, Throwable cause)
     If we're running on JDK 1.4 or later, initialize the cause for the given throwable.
Parameters:
  throwable - The throwable.
Parameters:
  cause - The cause of the throwable.
public  voidpopulate(Object bean, Map properties)
    

Populate the JavaBeans properties of the specified bean, based on the specified name/value pairs.

public static  voidsetInstance(BeanUtilsBean newInstance)
     Sets the instance which provides the functionality for BeanUtils .
public  voidsetProperty(Object bean, String name, Object value)
    

Set the specified property value, performing type conversions as required to conform to the type of the destination property.

If the property is read only then the method returns without throwing an exception.

If null is passed into a property expecting a primitive value, then this will be converted as if it were a null string.

WARNING - The logic of this method is customized to meet the needs of populate(), and is probably not what you want for general property copying with type conversion.



Constructor Detail
BeanUtilsBean
public BeanUtilsBean()(Code)

Constructs an instance using new property and conversion instances.




BeanUtilsBean
public BeanUtilsBean(ConvertUtilsBean convertUtilsBean)(Code)

Constructs an instance using given conversion instances and new PropertyUtilsBean instance.


Parameters:
  convertUtilsBean - use this ConvertUtilsBean to perform conversions from one object to another
since:
   1.8.0



BeanUtilsBean
public BeanUtilsBean(ConvertUtilsBean convertUtilsBean, PropertyUtilsBean propertyUtilsBean)(Code)

Constructs an instance using given property and conversion instances.


Parameters:
  convertUtilsBean - use this ConvertUtilsBean to perform conversions from one object to another
Parameters:
  propertyUtilsBean - use this PropertyUtilsBeanto access properties




Method Detail
cloneBean
public Object cloneBean(Object bean) throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException(Code)

Clone a bean based on the available property getters and setters, even if the bean class itself does not implement Cloneable.

Note: this method creates a shallow clone. In other words, any objects referred to by the bean are shared with the clone rather than being cloned in turn.


Parameters:
  bean - Bean to be cloned the cloned bean
exception:
  IllegalAccessException - if the caller does not haveaccess to the property accessor method
exception:
  InstantiationException - if a new instance of the bean'sclass cannot be instantiated
exception:
  InvocationTargetException - if the property accessor methodthrows an exception
exception:
  NoSuchMethodException - if an accessor method for thisproperty cannot be found



convert
protected Object convert(Object value, Class type)(Code)

Convert the value to an object of the specified class (if possible).


Parameters:
  value - Value to be converted (may be null)
Parameters:
  type - Class of the value to be converted to The converted value
exception:
  ConversionException - if thrown by an underlying Converter



copyProperties
public void copyProperties(Object dest, Object orig) throws IllegalAccessException, InvocationTargetException(Code)

Copy property values from the origin bean to the destination bean for all cases where the property names are the same. For each property, a conversion is attempted as necessary. All combinations of standard JavaBeans and DynaBeans as origin and destination are supported. Properties that exist in the origin bean, but do not exist in the destination bean (or are read-only in the destination bean) are silently ignored.

If the origin "bean" is actually a Map, it is assumed to contain String-valued simple property names as the keys, pointing at the corresponding property values that will be converted (if necessary) and set in the destination bean. Note that this method is intended to perform a "shallow copy" of the properties and so complex properties (for example, nested ones) will not be copied.

This method differs from populate(), which was primarily designed for populating JavaBeans from the map of request parameters retrieved on an HTTP request, is that no scalar->indexed or indexed->scalar manipulations are performed. If the origin property is indexed, the destination property must be also.

If you know that no type conversions are required, the copyProperties() method in PropertyUtils will execute faster than this method.

FIXME - Indexed and mapped properties that do not have getter and setter methods for the underlying array or Map are not copied by this method.


Parameters:
  dest - Destination bean whose properties are modified
Parameters:
  orig - Origin bean whose properties are retrieved
exception:
  IllegalAccessException - if the caller does not haveaccess to the property accessor method
exception:
  IllegalArgumentException - if the dest ororig argument is null or if the dest property type is different from the source type and the relevantconverter has not been registered.
exception:
  InvocationTargetException - if the property accessor methodthrows an exception



copyProperty
public void copyProperty(Object bean, String name, Object value) throws IllegalAccessException, InvocationTargetException(Code)

Copy the specified property value to the specified destination bean, performing any type conversion that is required. If the specified bean does not have a property of the specified name, or the property is read only on the destination bean, return without doing anything. If you have custom destination property types, register Converter s for them by calling the register() method of ConvertUtils .

IMPLEMENTATION RESTRICTIONS:

  • Does not support destination properties that are indexed, but only an indexed setter (as opposed to an array setter) is available.
  • Does not support destination properties that are mapped, but only a keyed setter (as opposed to a Map setter) is available.
  • The desired property type of a mapped setter cannot be determined (since Maps support any data type), so no conversion will be performed.

Parameters:
  bean - Bean on which setting is to be performed
Parameters:
  name - Property name (can be nested/indexed/mapped/combo)
Parameters:
  value - Value to be set
exception:
  IllegalAccessException - if the caller does not haveaccess to the property accessor method
exception:
  InvocationTargetException - if the property accessor methodthrows an exception



describe
public Map describe(Object bean) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException(Code)

Return the entire set of properties for which the specified bean provides a read method. This map contains the to String converted property values for all properties for which a read method is provided (i.e. where the getReadMethod() returns non-null).

This map can be fed back to a call to BeanUtils.populate() to reconsitute the same set of properties, modulo differences for read-only and write-only properties, but only if there are no indexed properties.

Warning: if any of the bean property implementations contain (directly or indirectly) a call to this method then a stack overflow may result. For example:

 class MyBean
 {
 public Map getParameterMap()
 {
 BeanUtils.describe(this);
 }
 }
 
will result in an infinite regression when getParametersMap is called. It is recommended that such methods are given alternative names (for example, parametersMap).


Parameters:
  bean - Bean whose properties are to be extracted Map of property descriptors
exception:
  IllegalAccessException - if the caller does not haveaccess to the property accessor method
exception:
  InvocationTargetException - if the property accessor methodthrows an exception
exception:
  NoSuchMethodException - if an accessor method for thisproperty cannot be found



getArrayProperty
public String[] getArrayProperty(Object bean, String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException(Code)
Return the value of the specified array property of the specified bean, as a String array.
Parameters:
  bean - Bean whose property is to be extracted
Parameters:
  name - Name of the property to be extracted The array property value
exception:
  IllegalAccessException - if the caller does not haveaccess to the property accessor method
exception:
  InvocationTargetException - if the property accessor methodthrows an exception
exception:
  NoSuchMethodException - if an accessor method for thisproperty cannot be found



getConvertUtils
public ConvertUtilsBean getConvertUtils()(Code)
Gets the ConvertUtilsBean instance used to perform the conversions. The ConvertUtils bean instance



getIndexedProperty
public String getIndexedProperty(Object bean, String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException(Code)
Return the value of the specified indexed property of the specified bean, as a String. The zero-relative index of the required value must be included (in square brackets) as a suffix to the property name, or IllegalArgumentException will be thrown.
Parameters:
  bean - Bean whose property is to be extracted
Parameters:
  name - propertyname[index] of the property valueto be extracted The indexed property's value, converted to a String
exception:
  IllegalAccessException - if the caller does not haveaccess to the property accessor method
exception:
  InvocationTargetException - if the property accessor methodthrows an exception
exception:
  NoSuchMethodException - if an accessor method for thisproperty cannot be found



getIndexedProperty
public String getIndexedProperty(Object bean, String name, int index) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException(Code)
Return the value of the specified indexed property of the specified bean, as a String. The index is specified as a method parameter and must *not* be included in the property name expression
Parameters:
  bean - Bean whose property is to be extracted
Parameters:
  name - Simple property name of the property value to be extracted
Parameters:
  index - Index of the property value to be extracted The indexed property's value, converted to a String
exception:
  IllegalAccessException - if the caller does not haveaccess to the property accessor method
exception:
  InvocationTargetException - if the property accessor methodthrows an exception
exception:
  NoSuchMethodException - if an accessor method for thisproperty cannot be found



getInstance
public static BeanUtilsBean getInstance()(Code)
Gets the instance which provides the functionality for BeanUtils . This is a pseudo-singleton - an single instance is provided per (thread) context classloader. This mechanism provides isolation for web apps deployed in the same container. The (pseudo-singleton) BeanUtils bean instance



getMappedProperty
public String getMappedProperty(Object bean, String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException(Code)
Return the value of the specified indexed property of the specified bean, as a String. The String-valued key of the required value must be included (in parentheses) as a suffix to the property name, or IllegalArgumentException will be thrown.
Parameters:
  bean - Bean whose property is to be extracted
Parameters:
  name - propertyname(index) of the property valueto be extracted The mapped property's value, converted to a String
exception:
  IllegalAccessException - if the caller does not haveaccess to the property accessor method
exception:
  InvocationTargetException - if the property accessor methodthrows an exception
exception:
  NoSuchMethodException - if an accessor method for thisproperty cannot be found



getMappedProperty
public String getMappedProperty(Object bean, String name, String key) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException(Code)
Return the value of the specified mapped property of the specified bean, as a String. The key is specified as a method parameter and must *not* be included in the property name expression
Parameters:
  bean - Bean whose property is to be extracted
Parameters:
  name - Simple property name of the property value to be extracted
Parameters:
  key - Lookup key of the property value to be extracted The mapped property's value, converted to a String
exception:
  IllegalAccessException - if the caller does not haveaccess to the property accessor method
exception:
  InvocationTargetException - if the property accessor methodthrows an exception
exception:
  NoSuchMethodException - if an accessor method for thisproperty cannot be found



getNestedProperty
public String getNestedProperty(Object bean, String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException(Code)
Return the value of the (possibly nested) property of the specified name, for the specified bean, as a String.
Parameters:
  bean - Bean whose property is to be extracted
Parameters:
  name - Possibly nested name of the property to be extracted The nested property's value, converted to a String
exception:
  IllegalAccessException - if the caller does not haveaccess to the property accessor method
exception:
  IllegalArgumentException - if a nested reference to aproperty returns null
exception:
  InvocationTargetException - if the property accessor methodthrows an exception
exception:
  NoSuchMethodException - if an accessor method for thisproperty cannot be found



getProperty
public String getProperty(Object bean, String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException(Code)
Return the value of the specified property of the specified bean, no matter which property reference format is used, as a String.
Parameters:
  bean - Bean whose property is to be extracted
Parameters:
  name - Possibly indexed and/or nested name of the propertyto be extracted The property's value, converted to a String
exception:
  IllegalAccessException - if the caller does not haveaccess to the property accessor method
exception:
  InvocationTargetException - if the property accessor methodthrows an exception
exception:
  NoSuchMethodException - if an accessor method for thisproperty cannot be found



getPropertyUtils
public PropertyUtilsBean getPropertyUtils()(Code)
Gets the PropertyUtilsBean instance used to access properties. The ConvertUtils bean instance



getSimpleProperty
public String getSimpleProperty(Object bean, String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException(Code)
Return the value of the specified simple property of the specified bean, converted to a String.
Parameters:
  bean - Bean whose property is to be extracted
Parameters:
  name - Name of the property to be extracted The property's value, converted to a String
exception:
  IllegalAccessException - if the caller does not haveaccess to the property accessor method
exception:
  InvocationTargetException - if the property accessor methodthrows an exception
exception:
  NoSuchMethodException - if an accessor method for thisproperty cannot be found



initCause
public boolean initCause(Throwable throwable, Throwable cause)(Code)
If we're running on JDK 1.4 or later, initialize the cause for the given throwable.
Parameters:
  throwable - The throwable.
Parameters:
  cause - The cause of the throwable. true if the cause was initialized, otherwise false.



populate
public void populate(Object bean, Map properties) throws IllegalAccessException, InvocationTargetException(Code)

Populate the JavaBeans properties of the specified bean, based on the specified name/value pairs. This method uses Java reflection APIs to identify corresponding "property setter" method names, and deals with setter arguments of type String, boolean, int, long, float, and double. In addition, array setters for these types (or the corresponding primitive types) can also be identified.

The particular setter method to be called for each property is determined using the usual JavaBeans introspection mechanisms. Thus, you may identify custom setter methods using a BeanInfo class that is associated with the class of the bean itself. If no such BeanInfo class is available, the standard method name conversion ("set" plus the capitalized name of the property in question) is used.

NOTE: It is contrary to the JavaBeans Specification to have more than one setter method (with different argument signatures) for the same property.

WARNING - The logic of this method is customized for extracting String-based request parameters from an HTTP request. It is probably not what you want for general property copying with type conversion. For that purpose, check out the copyProperties() method instead.


Parameters:
  bean - JavaBean whose properties are being populated
Parameters:
  properties - Map keyed by property name, with thecorresponding (String or String[]) value(s) to be set
exception:
  IllegalAccessException - if the caller does not haveaccess to the property accessor method
exception:
  InvocationTargetException - if the property accessor methodthrows an exception



setInstance
public static void setInstance(BeanUtilsBean newInstance)(Code)
Sets the instance which provides the functionality for BeanUtils . This is a pseudo-singleton - an single instance is provided per (thread) context classloader. This mechanism provides isolation for web apps deployed in the same container.
Parameters:
  newInstance - The (pseudo-singleton) BeanUtils bean instance



setProperty
public void setProperty(Object bean, String name, Object value) throws IllegalAccessException, InvocationTargetException(Code)

Set the specified property value, performing type conversions as required to conform to the type of the destination property.

If the property is read only then the method returns without throwing an exception.

If null is passed into a property expecting a primitive value, then this will be converted as if it were a null string.

WARNING - The logic of this method is customized to meet the needs of populate(), and is probably not what you want for general property copying with type conversion. For that purpose, check out the copyProperty() method instead.

WARNING - PLEASE do not modify the behavior of this method without consulting with the Struts developer community. There are some subtleties to its functionality that are not documented in the Javadoc description above, yet are vital to the way that Struts utilizes this method.


Parameters:
  bean - Bean on which setting is to be performed
Parameters:
  name - Property name (can be nested/indexed/mapped/combo)
Parameters:
  value - Value to be set
exception:
  IllegalAccessException - if the caller does not haveaccess to the property accessor method
exception:
  InvocationTargetException - if the property accessor methodthrows an exception



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.