Java Doc for ReflectionToStringBuilder.java in  » Library » Apache-common-lang » org » apache » commons » lang » builder » 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 common lang » org.apache.commons.lang.builder 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.apache.commons.lang.builder.ToStringBuilder
      org.apache.commons.lang.builder.ReflectionToStringBuilder

ReflectionToStringBuilder
public class ReflectionToStringBuilder extends ToStringBuilder (Code)

Assists in implementing Object.toString methods using reflection.

This class uses reflection to determine the fields to append. Because these fields are usually private, the class uses java.lang.reflect.AccessibleObject.setAccessible(java.lang.reflect.AccessibleObject[]boolean) to change the visibility of the fields. This will fail under a security manager, unless the appropriate permissions are set up correctly.

A typical invocation for this method would look like:

 public String toString() {
 return ReflectionToStringBuilder.toString(this);
 }

You can also use the builder to debug 3rd party objects:

 System.out.println("An object: " + ReflectionToStringBuilder.toString(anObject));

A subclass can control field output by overriding the methods:

For example, this method does not include the password field in the returned String:

 public String toString() {
 return (new ReflectionToStringBuilder(this) {
 protected boolean accept(Field f) {
 return super.accept(f) && !f.getName().equals("password");
 }
 }).toString();
 }

The exact format of the toString is determined by the ToStringStyle passed into the constructor.


author:
   Gary Gregory
author:
   Stephen Colebourne
author:
   Pete Gieser
since:
   2.0
version:
   $Id: ReflectionToStringBuilder.java 501986 2007-01-31 20:54:26Z bayard $



Constructor Summary
public  ReflectionToStringBuilder(Object object)
    

Constructor.

public  ReflectionToStringBuilder(Object object, ToStringStyle style)
    

Constructor.

public  ReflectionToStringBuilder(Object object, ToStringStyle style, StringBuffer buffer)
    

Constructor.

public  ReflectionToStringBuilder(Object object, ToStringStyle style, StringBuffer buffer, Class reflectUpToClass, boolean outputTransients)
     Constructor.
public  ReflectionToStringBuilder(Object object, ToStringStyle style, StringBuffer buffer, Class reflectUpToClass, boolean outputTransients, boolean outputStatics)
     Constructor.

Method Summary
protected  booleanaccept(Field field)
     Returns whether or not to append the given Field.
Parameters:
  field - The Field to test.
protected  voidappendFieldsIn(Class clazz)
    

Appends the fields and values defined by the given object of the given Class.

public  String[]getExcludeFieldNames()
    
public  ClassgetUpToClass()
    

Gets the last super class to stop appending fields for.

protected  ObjectgetValue(Field field)
    

Calls java.lang.reflect.Field.get(Object).


Parameters:
  field - The Field to query.
public  booleanisAppendStatics()
    

Gets whether or not to append static fields.

public  booleanisAppendTransients()
    

Gets whether or not to append transient fields.

public  ToStringBuilderreflectionAppendArray(Object array)
    

Append to the toString an Object array.

public  voidsetAppendStatics(boolean appendStatics)
    

Sets whether or not to append static fields.

public  voidsetAppendTransients(boolean appendTransients)
    

Sets whether or not to append transient fields.

public  ReflectionToStringBuildersetExcludeFieldNames(String[] excludeFieldNamesParam)
     Sets the field names to exclude.
Parameters:
  excludeFieldNamesParam - The excludeFieldNames to excluding from toString or null.
public  voidsetUpToClass(Class clazz)
    

Sets the last super class to stop appending fields for.

static  String[]toNoNullStringArray(Collection collection)
     Converts the given Collection into an array of Strings.
static  String[]toNoNullStringArray(Object[] array)
     Returns a new array of Strings without null elements.
public static  StringtoString(Object object)
    

Builds a toString value using the default ToStringStyle through reflection.

It uses AccessibleObject.setAccessible to gain access to private fields.

public static  StringtoString(Object object, ToStringStyle style)
    

Builds a toString value through reflection.

It uses AccessibleObject.setAccessible to gain access to private fields.

public static  StringtoString(Object object, ToStringStyle style, boolean outputTransients)
    

Builds a toString value through reflection.

It uses AccessibleObject.setAccessible to gain access to private fields.

public static  StringtoString(Object object, ToStringStyle style, boolean outputTransients, boolean outputStatics)
    

Builds a toString value through reflection.

It uses AccessibleObject.setAccessible to gain access to private fields.

public static  StringtoString(Object object, ToStringStyle style, boolean outputTransients, boolean outputStatics, Class reflectUpToClass)
    

Builds a toString value through reflection.

It uses AccessibleObject.setAccessible to gain access to private fields.

public static  StringtoString(Object object, ToStringStyle style, boolean outputTransients, Class reflectUpToClass)
    

Builds a toString value through reflection.

It uses AccessibleObject.setAccessible to gain access to private fields.

public  StringtoString()
    

Gets the String built by this builder.

public static  StringtoStringExclude(Object object, String excludeFieldName)
     Builds a String for a toString method excluding the given field name.
public static  StringtoStringExclude(Object object, Collection excludeFieldNames)
     Builds a String for a toString method excluding the given field names.
Parameters:
  object - The object to "toString".
Parameters:
  excludeFieldNames - The field names to exclude.
public static  StringtoStringExclude(Object object, String[] excludeFieldNames)
     Builds a String for a toString method excluding the given field names.


Constructor Detail
ReflectionToStringBuilder
public ReflectionToStringBuilder(Object object)(Code)

Constructor.

This constructor outputs using the default style set with setDefaultStyle.


Parameters:
  object - the Object to build a toString for, must not be null
throws:
  IllegalArgumentException - if the Object passed in is null



ReflectionToStringBuilder
public ReflectionToStringBuilder(Object object, ToStringStyle style)(Code)

Constructor.

If the style is null, the default style is used.


Parameters:
  object - the Object to build a toString for, must not be null
Parameters:
  style - the style of the toString to create, may be null
throws:
  IllegalArgumentException - if the Object passed in is null



ReflectionToStringBuilder
public ReflectionToStringBuilder(Object object, ToStringStyle style, StringBuffer buffer)(Code)

Constructor.

If the style is null, the default style is used.

If the buffer is null, a new one is created.


Parameters:
  object - the Object to build a toString for
Parameters:
  style - the style of the toString to create, may be null
Parameters:
  buffer - the StringBuffer to populate, may be null
throws:
  IllegalArgumentException - if the Object passed in is null



ReflectionToStringBuilder
public ReflectionToStringBuilder(Object object, ToStringStyle style, StringBuffer buffer, Class reflectUpToClass, boolean outputTransients)(Code)
Constructor. ReflectionToStringBuilder.ReflectionToStringBuilder(Object,ToStringStyle,StringBuffer,Class,boolean,boolean)
Parameters:
  object - the Object to build a toString for
Parameters:
  style - the style of the toString to create, may be null
Parameters:
  buffer - the StringBuffer to populate, may be null
Parameters:
  reflectUpToClass - the superclass to reflect up to (inclusive), may be null
Parameters:
  outputTransients - whether to include transient fields



ReflectionToStringBuilder
public ReflectionToStringBuilder(Object object, ToStringStyle style, StringBuffer buffer, Class reflectUpToClass, boolean outputTransients, boolean outputStatics)(Code)
Constructor.
Parameters:
  object - the Object to build a toString for
Parameters:
  style - the style of the toString to create, may be null
Parameters:
  buffer - the StringBuffer to populate, may be null
Parameters:
  reflectUpToClass - the superclass to reflect up to (inclusive), may be null
Parameters:
  outputTransients - whether to include transient fields
Parameters:
  outputStatics - whether to include static fields
since:
   2.1




Method Detail
accept
protected boolean accept(Field field)(Code)
Returns whether or not to append the given Field.
Parameters:
  field - The Field to test. Whether or not to append the given Field.



appendFieldsIn
protected void appendFieldsIn(Class clazz)(Code)

Appends the fields and values defined by the given object of the given Class.

If a cycle is detected as an object is "toString()'ed", such an object is rendered as if Object.toString() had been called and not implemented by the object.


Parameters:
  clazz - The class of object parameter



getExcludeFieldNames
public String[] getExcludeFieldNames()(Code)
Returns the excludeFieldNames.



getUpToClass
public Class getUpToClass()(Code)

Gets the last super class to stop appending fields for.

The last super class to stop appending fields for.



getValue
protected Object getValue(Field field) throws IllegalArgumentException, IllegalAccessException(Code)

Calls java.lang.reflect.Field.get(Object).


Parameters:
  field - The Field to query. The Object from the given Field.
throws:
  IllegalArgumentException - see java.lang.reflect.Field.get(Object)
throws:
  IllegalAccessException - see java.lang.reflect.Field.get(Object)
See Also:   java.lang.reflect.Field.get(Object)



isAppendStatics
public boolean isAppendStatics()(Code)

Gets whether or not to append static fields.

Whether or not to append static fields.
since:
   2.1



isAppendTransients
public boolean isAppendTransients()(Code)

Gets whether or not to append transient fields.

Whether or not to append transient fields.



reflectionAppendArray
public ToStringBuilder reflectionAppendArray(Object array)(Code)

Append to the toString an Object array.


Parameters:
  array - the array to add to the toString this



setAppendStatics
public void setAppendStatics(boolean appendStatics)(Code)

Sets whether or not to append static fields.


Parameters:
  appendStatics - Whether or not to append static fields.
since:
   2.1



setAppendTransients
public void setAppendTransients(boolean appendTransients)(Code)

Sets whether or not to append transient fields.


Parameters:
  appendTransients - Whether or not to append transient fields.



setExcludeFieldNames
public ReflectionToStringBuilder setExcludeFieldNames(String[] excludeFieldNamesParam)(Code)
Sets the field names to exclude.
Parameters:
  excludeFieldNamesParam - The excludeFieldNames to excluding from toString or null. this



setUpToClass
public void setUpToClass(Class clazz)(Code)

Sets the last super class to stop appending fields for.


Parameters:
  clazz - The last super class to stop appending fields for.



toNoNullStringArray
static String[] toNoNullStringArray(Collection collection)(Code)
Converts the given Collection into an array of Strings. The returned array does not contain null entries. Note that Arrays.sort(Object[]) will throw an NullPointerException if an array element is null.
Parameters:
  collection - The collection to convert A new array of Strings.



toNoNullStringArray
static String[] toNoNullStringArray(Object[] array)(Code)
Returns a new array of Strings without null elements. Internal method used to normalize exclude lists (arrays and collections). Note that Arrays.sort(Object[]) will throw an NullPointerException if an array element is null.
Parameters:
  array - The array to check The given array or a new array without null.



toString
public static String toString(Object object)(Code)

Builds a toString value using the default ToStringStyle through reflection.

It uses AccessibleObject.setAccessible to gain access to private fields. This means that it will throw a security exception if run under a security manager, if the permissions are not set up correctly. It is also not as efficient as testing explicitly.

Transient members will be not be included, as they are likely derived. Static fields will not be included. Superclass fields will be appended.


Parameters:
  object - the Object to be output the String result
throws:
  IllegalArgumentException - if the Object is null



toString
public static String toString(Object object, ToStringStyle style)(Code)

Builds a toString value through reflection.

It uses AccessibleObject.setAccessible to gain access to private fields. This means that it will throw a security exception if run under a security manager, if the permissions are not set up correctly. It is also not as efficient as testing explicitly.

Transient members will be not be included, as they are likely derived. Static fields will not be included. Superclass fields will be appended.

If the style is null, the default ToStringStyle is used.


Parameters:
  object - the Object to be output
Parameters:
  style - the style of the toString to create, may be null the String result
throws:
  IllegalArgumentException - if the Object or ToStringStyle is null



toString
public static String toString(Object object, ToStringStyle style, boolean outputTransients)(Code)

Builds a toString value through reflection.

It uses AccessibleObject.setAccessible to gain access to private fields. This means that it will throw a security exception if run under a security manager, if the permissions are not set up correctly. It is also not as efficient as testing explicitly.

If the outputTransients is true, transient members will be output, otherwise they are ignored, as they are likely derived fields, and not part of the value of the Object.

Static fields will not be included. Superclass fields will be appended.

If the style is null, the default ToStringStyle is used.


Parameters:
  object - the Object to be output
Parameters:
  style - the style of the toString to create, may be null
Parameters:
  outputTransients - whether to include transient fields the String result
throws:
  IllegalArgumentException - if the Object is null



toString
public static String toString(Object object, ToStringStyle style, boolean outputTransients, boolean outputStatics)(Code)

Builds a toString value through reflection.

It uses AccessibleObject.setAccessible to gain access to private fields. This means that it will throw a security exception if run under a security manager, if the permissions are not set up correctly. It is also not as efficient as testing explicitly.

If the outputTransients is true, transient fields will be output, otherwise they are ignored, as they are likely derived fields, and not part of the value of the Object.

If the outputStatics is true, static fields will be output, otherwise they are ignored.

Static fields will not be included. Superclass fields will be appended.

If the style is null, the default ToStringStyle is used.


Parameters:
  object - the Object to be output
Parameters:
  style - the style of the toString to create, may be null
Parameters:
  outputTransients - whether to include transient fields
Parameters:
  outputStatics - whether to include transient fields the String result
throws:
  IllegalArgumentException - if the Object is null
since:
   2.1



toString
public static String toString(Object object, ToStringStyle style, boolean outputTransients, boolean outputStatics, Class reflectUpToClass)(Code)

Builds a toString value through reflection.

It uses AccessibleObject.setAccessible to gain access to private fields. This means that it will throw a security exception if run under a security manager, if the permissions are not set up correctly. It is also not as efficient as testing explicitly.

If the outputTransients is true, transient fields will be output, otherwise they are ignored, as they are likely derived fields, and not part of the value of the Object.

If the outputStatics is true, static fields will be output, otherwise they are ignored.

Superclass fields will be appended up to and including the specified superclass. A null superclass is treated as java.lang.Object.

If the style is null, the default ToStringStyle is used.


Parameters:
  object - the Object to be output
Parameters:
  style - the style of the toString to create, may be null
Parameters:
  outputTransients - whether to include transient fields
Parameters:
  outputStatics - whether to include static fields
Parameters:
  reflectUpToClass - the superclass to reflect up to (inclusive), may be null the String result
throws:
  IllegalArgumentException - if the Object is null
since:
   2.1



toString
public static String toString(Object object, ToStringStyle style, boolean outputTransients, Class reflectUpToClass)(Code)

Builds a toString value through reflection.

It uses AccessibleObject.setAccessible to gain access to private fields. This means that it will throw a security exception if run under a security manager, if the permissions are not set up correctly. It is also not as efficient as testing explicitly.

If the outputTransients is true, transient members will be output, otherwise they are ignored, as they are likely derived fields, and not part of the value of the Object.

Static fields will not be included. Superclass fields will be appended up to and including the specified superclass. A null superclass is treated as java.lang.Object.

If the style is null, the default ToStringStyle is used.

ReflectionToStringBuilder.toString(Object,ToStringStyle,boolean,boolean,Class)
Parameters:
  object - the Object to be output
Parameters:
  style - the style of the toString to create, may be null
Parameters:
  outputTransients - whether to include transient fields
Parameters:
  reflectUpToClass - the superclass to reflect up to (inclusive), may be null the String result
throws:
  IllegalArgumentException - if the Object is null
since:
   2.0



toString
public String toString()(Code)

Gets the String built by this builder.

the built string



toStringExclude
public static String toStringExclude(Object object, String excludeFieldName)(Code)
Builds a String for a toString method excluding the given field name.
Parameters:
  object - The object to "toString".
Parameters:
  excludeFieldName - The field name to exclude The toString value.



toStringExclude
public static String toStringExclude(Object object, Collection excludeFieldNames)(Code)
Builds a String for a toString method excluding the given field names.
Parameters:
  object - The object to "toString".
Parameters:
  excludeFieldNames - The field names to exclude. Null excludes nothing. The toString value.



toStringExclude
public static String toStringExclude(Object object, String[] excludeFieldNames)(Code)
Builds a String for a toString method excluding the given field names.
Parameters:
  object - The object to "toString".
Parameters:
  excludeFieldNames - The field names to exclude The toString value.



Methods inherited from org.apache.commons.lang.builder.ToStringBuilder
public ToStringBuilder append(boolean value)(Code)(Java Doc)
public ToStringBuilder append(boolean[] array)(Code)(Java Doc)
public ToStringBuilder append(byte value)(Code)(Java Doc)
public ToStringBuilder append(byte[] array)(Code)(Java Doc)
public ToStringBuilder append(char value)(Code)(Java Doc)
public ToStringBuilder append(char[] array)(Code)(Java Doc)
public ToStringBuilder append(double value)(Code)(Java Doc)
public ToStringBuilder append(double[] array)(Code)(Java Doc)
public ToStringBuilder append(float value)(Code)(Java Doc)
public ToStringBuilder append(float[] array)(Code)(Java Doc)
public ToStringBuilder append(int value)(Code)(Java Doc)
public ToStringBuilder append(int[] array)(Code)(Java Doc)
public ToStringBuilder append(long value)(Code)(Java Doc)
public ToStringBuilder append(long[] array)(Code)(Java Doc)
public ToStringBuilder append(Object obj)(Code)(Java Doc)
public ToStringBuilder append(Object[] array)(Code)(Java Doc)
public ToStringBuilder append(short value)(Code)(Java Doc)
public ToStringBuilder append(short[] array)(Code)(Java Doc)
public ToStringBuilder append(String fieldName, boolean value)(Code)(Java Doc)
public ToStringBuilder append(String fieldName, boolean[] array)(Code)(Java Doc)
public ToStringBuilder append(String fieldName, boolean[] array, boolean fullDetail)(Code)(Java Doc)
public ToStringBuilder append(String fieldName, byte value)(Code)(Java Doc)
public ToStringBuilder append(String fieldName, byte[] array)(Code)(Java Doc)
public ToStringBuilder append(String fieldName, byte[] array, boolean fullDetail)(Code)(Java Doc)
public ToStringBuilder append(String fieldName, char value)(Code)(Java Doc)
public ToStringBuilder append(String fieldName, char[] array)(Code)(Java Doc)
public ToStringBuilder append(String fieldName, char[] array, boolean fullDetail)(Code)(Java Doc)
public ToStringBuilder append(String fieldName, double value)(Code)(Java Doc)
public ToStringBuilder append(String fieldName, double[] array)(Code)(Java Doc)
public ToStringBuilder append(String fieldName, double[] array, boolean fullDetail)(Code)(Java Doc)
public ToStringBuilder append(String fieldName, float value)(Code)(Java Doc)
public ToStringBuilder append(String fieldName, float[] array)(Code)(Java Doc)
public ToStringBuilder append(String fieldName, float[] array, boolean fullDetail)(Code)(Java Doc)
public ToStringBuilder append(String fieldName, int value)(Code)(Java Doc)
public ToStringBuilder append(String fieldName, int[] array)(Code)(Java Doc)
public ToStringBuilder append(String fieldName, int[] array, boolean fullDetail)(Code)(Java Doc)
public ToStringBuilder append(String fieldName, long value)(Code)(Java Doc)
public ToStringBuilder append(String fieldName, long[] array)(Code)(Java Doc)
public ToStringBuilder append(String fieldName, long[] array, boolean fullDetail)(Code)(Java Doc)
public ToStringBuilder append(String fieldName, Object obj)(Code)(Java Doc)
public ToStringBuilder append(String fieldName, Object obj, boolean fullDetail)(Code)(Java Doc)
public ToStringBuilder append(String fieldName, Object[] array)(Code)(Java Doc)
public ToStringBuilder append(String fieldName, Object[] array, boolean fullDetail)(Code)(Java Doc)
public ToStringBuilder append(String fieldName, short value)(Code)(Java Doc)
public ToStringBuilder append(String fieldName, short[] array)(Code)(Java Doc)
public ToStringBuilder append(String fieldName, short[] array, boolean fullDetail)(Code)(Java Doc)
public ToStringBuilder appendAsObjectToString(Object object)(Code)(Java Doc)
public ToStringBuilder appendSuper(String superToString)(Code)(Java Doc)
public ToStringBuilder appendToString(String toString)(Code)(Java Doc)
public static ToStringStyle getDefaultStyle()(Code)(Java Doc)
public Object getObject()(Code)(Java Doc)
public StringBuffer getStringBuffer()(Code)(Java Doc)
public ToStringStyle getStyle()(Code)(Java Doc)
public static String reflectionToString(Object object)(Code)(Java Doc)
public static String reflectionToString(Object object, ToStringStyle style)(Code)(Java Doc)
public static String reflectionToString(Object object, ToStringStyle style, boolean outputTransients)(Code)(Java Doc)
public static String reflectionToString(Object object, ToStringStyle style, boolean outputTransients, Class reflectUpToClass)(Code)(Java Doc)
public static void setDefaultStyle(ToStringStyle style)(Code)(Java Doc)
public String toString()(Code)(Java Doc)

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.