org.zkoss.lang.reflect
Class Fields

java.lang.Object
  extended by org.zkoss.lang.reflect.Fields

public class Fields
extends java.lang.Object

Utilities to access fields.

Author:
tomyeh

Constructor Summary
Fields()
           
 
Method Summary
static java.lang.Object get(java.lang.Object obj, java.lang.String name)
           
static java.lang.Object getField(java.lang.Object obj, java.lang.String name)
          Returnst the value of the specfied field of the object.
static void set(java.lang.Object obj, java.lang.String name, java.lang.Object val, boolean autoCoerce)
           
static void setField(java.lang.Object obj, java.lang.String name, java.lang.Object val)
          Sets the value of the specfied field in the object, without converting the specified val.
static void setField(java.lang.Object obj, java.lang.String name, java.lang.Object val, boolean autoCoerce)
          Sets the value of the specified field in the object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Fields

public Fields()
Method Detail

getField

public static final java.lang.Object getField(java.lang.Object obj,
                                              java.lang.String name)
                                       throws java.lang.NoSuchMethodException
Returnst the value of the specfied field of the object.

If getField(obj, "a.b.c") is called and obj.getA() or obj.getA().getB() returns null, the result is null. However, NullPointerException is thrown if obj is null.

Parameters:
name - the field name. It can be in form of "a.b.c", but cannot be an expression.
Throws:
java.lang.NoSuchMethodException - if no corresponding field.

setField

public static final void setField(java.lang.Object obj,
                                  java.lang.String name,
                                  java.lang.Object val,
                                  boolean autoCoerce)
                           throws java.lang.NoSuchMethodException,
                                  ModificationException
Sets the value of the specified field in the object.

Parameters:
autoCoerce - whether to automatically convert val to the proper class that matches the argument of method or field.
Throws:
java.lang.NoSuchMethodException
ModificationException

setField

public static final void setField(java.lang.Object obj,
                                  java.lang.String name,
                                  java.lang.Object val)
                           throws java.lang.NoSuchMethodException,
                                  ModificationException
Sets the value of the specfied field in the object, without converting the specified val.

It is a shortcut of setField(obj, name, val, false).

Parameters:
name - the field name. It can be in form of "a.b.c", but cannot be an expression.
Throws:
java.lang.NoSuchMethodException
ModificationException

get

public static final java.lang.Object get(java.lang.Object obj,
                                         java.lang.String name)
                                  throws java.lang.NoSuchMethodException
Throws:
java.lang.NoSuchMethodException

set

public static final void set(java.lang.Object obj,
                             java.lang.String name,
                             java.lang.Object val,
                             boolean autoCoerce)
                      throws java.lang.NoSuchMethodException,
                             ModificationException
Throws:
java.lang.NoSuchMethodException
ModificationException


Copyright © 2005-2007 Potix Corporation. All Rights Reserved.