KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > bean > loaders > MapLoader


1 package jodd.bean.loaders;
2
3 import java.util.Iterator;
4 import java.util.Map;
5
6 import jodd.bean.BeanUtil;
7
8 /**
9  * Populate java bean using objects that are implementation of Map interface.
10  * <p>
11  * Properties in Map object are defined as follows:
12  * each key of Map object is a string the represents a bean property name and
13  * keys value is an object that represents bean property value.
14  */

15 public class MapLoader implements jodd.bean.Loader {
16
17     public void load(Object bean, Object map) {
18         if (map instanceof Map) {
19             Iterator i = ((Map)map).keySet().iterator();
20             while (i.hasNext()) {
21                 String propertyName = (String) i.next();
22                 Object propertyValue = ((Map)map).get(propertyName);
23                 if (propertyValue == null) {
24                     return;
25                 }
26                 BeanUtil.setProperty(bean, propertyName, propertyValue);
27             }
28         }
29     }
30 }
31
Popular Tags