KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > wcf > convert > SelectSingleConverter


1 /*
2  * ====================================================================
3  * This software is subject to the terms of the Common Public License
4  * Agreement, available at the following URL:
5  * http://www.opensource.org/licenses/cpl.html .
6  * Copyright (C) 2003-2004 TONBELLER AG.
7  * All Rights Reserved.
8  * You must accept the terms of that agreement to use this software.
9  * ====================================================================
10  *
11  *
12  */

13 package com.tonbeller.wcf.convert;
14
15 import java.lang.reflect.InvocationTargetException JavaDoc;
16
17 import org.apache.commons.beanutils.PropertyUtils;
18 import org.w3c.dom.Element JavaDoc;
19
20 import com.tonbeller.wcf.format.FormatException;
21 import com.tonbeller.wcf.format.FormatHandler;
22 import com.tonbeller.wcf.format.Formatter;
23 import com.tonbeller.wcf.ui.Item;
24 import com.tonbeller.wcf.ui.SelectSingle;
25
26 /**
27  * sets a scalar bean property to the value of the selected item. If no item
28  * is selected, nothing will be done.
29  *
30  * <p>
31  * An items value is the value attribute of the elected item.
32  * For type conversion the type, modelReference and formatString attributes
33  * will be taken from the items parent (e.g. the listBox).
34  *
35  * @author av
36  */

37 public class SelectSingleConverter extends SelectConverterBase {
38
39   protected void updateModelReference(Formatter fmt, Element JavaDoc elem, Object JavaDoc bean) throws FormatException, IllegalAccessException JavaDoc, NoSuchMethodException JavaDoc, InvocationTargetException JavaDoc {
40     String JavaDoc model = SelectSingle.getModelReference(elem);
41     if (model.length() == 0)
42       return;
43     
44     String JavaDoc type = SelectSingle.getType(elem);
45     String JavaDoc formatString = SelectSingle.getFormatString(elem);
46     FormatHandler parser = fmt.getHandler(type);
47     if (parser == null)
48       throw new FormatException("no handler found for type: " + type);
49     
50     Element JavaDoc item = SelectSingle.getSelectedItem(elem);
51     if (item == null)
52       return;
53
54     String JavaDoc valueString = Item.getValue(item);
55     Object JavaDoc value = parser.parse(valueString, formatString);
56     PropertyUtils.setProperty(bean, model, value);
57   }
58
59
60 }
61
Popular Tags