KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > uitags > util > BeanUtils


1 /**
2  * Nov 23, 2004
3  *
4  * Copyright 2004 uitags
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package net.sf.uitags.util;
19
20 import javax.servlet.jsp.JspException JavaDoc;
21
22 /**
23  * Helper class that provides wrappers for Commons <code>BeanUtils</code>'s
24  * methods. The wrapping methods free the calling code from having to handle
25  * introspection-related checked-exceptions by wrapping them inside
26  * <code>JspException</code>.
27  *
28  * @author jonni
29  * @author hgani
30  * @version $Id$
31  */

32 public final class BeanUtils {
33   /**
34    * Non-instantiable by client.
35    */

36   private BeanUtils() {
37     super();
38   }
39
40   /**
41    * Wraps <code>BeanUtils</code>' method with the same name
42    * and signature.
43    *
44    * @param bean the bean whose property value is to be returned
45    * @param propertyName the name of the property whose value is to be retrieved
46    * @return the value of the bean property
47    * @throws JspException wraps exceptions thrown by <code>BeanUtils</code>
48    */

49   public static String JavaDoc getSimpleProperty(Object JavaDoc bean, String JavaDoc propertyName)
50       throws JspException JavaDoc {
51     try {
52       return org.apache.commons.beanutils.BeanUtils.getSimpleProperty(
53           bean, propertyName);
54     }
55     catch (Exception JavaDoc e) {
56       throw new JspException JavaDoc(e);
57     }
58   }
59
60   /**
61    * Wraps <code>BeanUtils</code>' method with the same name
62    * and signature.
63    *
64    * @param bean the bean whose property value is to be returned
65    * @param propertyName the name of the property whose value is to be retrieved
66    * @return the value of the bean property
67    * @throws JspException wraps exceptions thrown by <code>BeanUtils</code>
68    */

69   public static String JavaDoc getProperty(Object JavaDoc bean, String JavaDoc propertyName)
70       throws JspException JavaDoc {
71     try {
72       return org.apache.commons.beanutils.BeanUtils.getProperty(
73           bean, propertyName);
74     }
75     catch (Exception JavaDoc e) {
76       throw new JspException JavaDoc(e);
77     }
78   }
79 }
80
Popular Tags