ix.util
Class FieldWalker

java.lang.Object
  |
  +--ix.util.FieldWalker
Direct Known Subclasses:
XMLTranslator.WalkerForXML

public class FieldWalker
extends java.lang.Object

Used to visit the fields of an object. A FieldWalker contains the information needed to process instances of a given class field-by-field. It also embodies decisions about which fields should be accessible in this way, how their values are obtained or set, and the order in which they should be visited.


Inner Class Summary
static class FieldWalker.FieldInfo
           
 
Field Summary
protected  java.util.List fields
           
protected  java.util.Map index
           
protected  java.lang.Class objClass
           
 
Constructor Summary
FieldWalker(java.lang.Class objClass)
          Constructs a FieldWalker for the given class.
 
Method Summary
protected  void collectFieldInfo()
           
protected  java.util.Collection collectFieldNames(java.lang.Class c, java.util.Collection names)
           
 void describeClass()
          Prints a description of this FieldWalker's view of its source class on the System.out.
 void describeClass(java.io.PrintStream out)
          Prints a description of this FieldWalker's view of its source class on the designated PrintStream.
 java.lang.String fieldNameFromGetName(java.lang.String name)
           
 java.lang.String fieldNameFromSetName(java.lang.String name)
           
 java.util.List getFieldInfo()
          Returns a list of field descriptions.
 FieldWalker.FieldInfo getFieldInfo(java.lang.String fieldName)
          Returns the information for the specified field, or else null if the field does not exist or cannot be accessed via this FieldWalker.
static boolean isGetName(java.lang.String name)
           
static boolean isSetName(java.lang.String name)
           
static void main(java.lang.String[] argv)
          Test loop that repeatedly asks the user for a class name, constructs a FieldWalker for the class, and asks the walker to print a class description.
 void setField(java.lang.Object object, java.lang.String fieldName, java.lang.Object newValue)
          Calls the "set" method for the field.
 void visitField(java.lang.Object object, FieldWalker.FieldInfo info, java.lang.Object result)
          Called once for each field by the walkFields method.
 void walkFields(java.lang.Object object, java.lang.Object result)
          Calls the visitField method for every field.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

objClass

protected java.lang.Class objClass

fields

protected java.util.List fields

index

protected java.util.Map index
Constructor Detail

FieldWalker

public FieldWalker(java.lang.Class objClass)
Constructs a FieldWalker for the given class.
Method Detail

getFieldInfo

public java.util.List getFieldInfo()
Returns a list of field descriptions.
See Also:
FieldWalker.FieldInfo

getFieldInfo

public FieldWalker.FieldInfo getFieldInfo(java.lang.String fieldName)
Returns the information for the specified field, or else null if the field does not exist or cannot be accessed via this FieldWalker.

walkFields

public void walkFields(java.lang.Object object,
                       java.lang.Object result)
Calls the visitField method for every field.

visitField

public void visitField(java.lang.Object object,
                       FieldWalker.FieldInfo info,
                       java.lang.Object result)
Called once for each field by the walkFields method. This visitField method does nothing and is usually overridden in subclasses.

setField

public void setField(java.lang.Object object,
                     java.lang.String fieldName,
                     java.lang.Object newValue)
              throws java.lang.NoSuchFieldException,
                     java.lang.IllegalAccessException,
                     java.lang.IllegalArgumentException,
                     java.lang.reflect.InvocationTargetException
Calls the "set" method for the field.

describeClass

public void describeClass()
Prints a description of this FieldWalker's view of its source class on the System.out.

describeClass

public void describeClass(java.io.PrintStream out)
Prints a description of this FieldWalker's view of its source class on the designated PrintStream.

collectFieldInfo

protected void collectFieldInfo()

isGetName

public static final boolean isGetName(java.lang.String name)

isSetName

public static final boolean isSetName(java.lang.String name)

fieldNameFromGetName

public java.lang.String fieldNameFromGetName(java.lang.String name)

fieldNameFromSetName

public java.lang.String fieldNameFromSetName(java.lang.String name)

collectFieldNames

protected java.util.Collection collectFieldNames(java.lang.Class c,
                                                 java.util.Collection names)

main

public static void main(java.lang.String[] argv)
Test loop that repeatedly asks the user for a class name, constructs a FieldWalker for the class, and asks the walker to print a class description.