View Javadoc

1   /*
2    * @(#) BeanUtils.java Apr 15, 2004 Copyright (c) 2002-2005 Delft University of
3    * Technology Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved.
4    * This software is proprietary information of Delft University of Technology
5    * The code is published under the Lesser General Public License
6    */
7   package nl.tudelft.simulation.introspection.beans;
8   
9   import java.beans.PropertyDescriptor;
10  
11  /***
12   * Utility class for bean tests.
13   * <p>
14   * (c) copyright 2002-2005-2004 <a href="http://www.simulation.tudelft.nl">Delft
15   * University of Technology </a>, the Netherlands. <br>
16   * See for project information <a
17   * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
18   * License of use: <a href="http://www.gnu.org/copyleft/lesser.html">Lesser
19   * General Public License (LGPL) </a>, no warranty.
20   * 
21   * @author <a
22   *         href="http://web.eur.nl/fbk/dep/dep1/Introduction/Staff/People/Lang">Niels
23   *         Lang </a><a href="http://www.peter-jacobs.com/index.htm">Peter
24   *         Jacobs </a>
25   * @version 1.1 Apr 15, 2004
26   * @since 1.5
27   */
28  
29  public class BeanUtils extends Object
30  {
31      /***
32       * resolves whether the bean is null
33       * 
34       * @param bean A bean instance.
35       * @param pd A PropertyDescriptor for the property to be examined.
36       * @return True, if the value of the property described by 'pd' for the
37       *         instance 'bean' is null indeed. Returns false otherwise.
38       */
39      public static boolean isNull(final Object bean, final PropertyDescriptor pd)
40      {
41          Object result = null;
42          try
43          {
44              result = pd.getReadMethod().invoke(bean, new Object[0]);
45          } catch (Exception e)
46          {
47              return true;
48          }
49          return (result == null);
50      }
51  }