1 13 package com.tonbeller.wcf.convert; 14 15 import java.lang.reflect.InvocationTargetException ; 16 import java.util.Map ; 17 18 import org.apache.commons.beanutils.PropertyUtils; 19 import org.w3c.dom.Element ; 20 21 import com.tonbeller.wcf.format.FormatException; 22 import com.tonbeller.wcf.format.Formatter; 23 import com.tonbeller.wcf.ui.Item; 24 import com.tonbeller.wcf.utils.DomUtils; 25 26 30 31 public abstract class BooleanConverter extends NodeConverterBase { 32 public static final int UNKNOWN = 1; 33 public static final int TRUE = 2; 34 public static final int FALSE = 3; 35 36 45 public void convert(Formatter fmt, Map params, Map fileParams, Element elem, Object bean) 46 throws FormatException, IllegalAccessException , NoSuchMethodException , InvocationTargetException { 47 48 int state = isSelected(elem, params); 49 if (state == UNKNOWN) 50 return; 51 52 Boolean value = new Boolean (state == TRUE); 54 55 DomUtils.removeAttribute(elem, "error"); 57 Item.setSelected(elem, value.booleanValue()); 58 59 String modelReference = Item.getModelReference(elem); 61 if (bean != null && modelReference.length() > 0) 62 PropertyUtils.setProperty(bean, Item.getModelReference(elem), value); 63 } 64 65 69 public abstract int isSelected(Element elem, Map params); 70 71 74 public void convert(Formatter fmt, Object bean, Element elem) 75 throws IllegalAccessException , NoSuchMethodException , InvocationTargetException { 76 77 String modelReference = Item.getModelReference(elem); 78 if (bean == null || modelReference.length() == 0) 79 return; 80 81 Boolean value = (Boolean ) PropertyUtils.getProperty(bean, Item.getModelReference(elem)); 82 boolean b = (value == null) ? false : value.booleanValue(); 83 Item.setSelected(elem, b); 84 } 85 86 } 87 | Popular Tags |