1 7 package com.inversoft.verge.mvc.model; 8 9 import java.util.Map ; 10 11 import com.inversoft.beans.BeanException; 12 import com.inversoft.util.typeconverter.TypeConversionException; 13 import com.inversoft.verge.mvc.MVCException; 14 import com.inversoft.verge.mvc.MVCRequest; 15 import com.inversoft.verge.mvc.config.BaseConfigStruct; 16 import com.inversoft.verge.mvc.config.BaseFormConfig; 17 import com.inversoft.verge.util.WebBean; 18 import com.inversoft.verge.util.WebBeanProperty; 19 20 21 28 public class DefaultModelHandler implements ModelHandler { 29 30 47 public Object getValue(MVCRequest mvcRequest, String definition, 48 ModelResolution resolution, Map extraParams) 49 throws MVCException { 50 51 assert (definition != null) : "definition == null"; 52 assert (resolution != null) : "resolution == null"; 53 assert (resolution.getModel() != null) : "resolution.getModel() == null"; 54 55 BaseConfigStruct struct = (BaseConfigStruct) mvcRequest.getConfiguration(); 56 BaseFormConfig config = struct.baseFormConfig; 57 MetaData md = resolution.getMetaData(); 58 WebBean webBean = config.getFormBean(md.getID()); 59 Object model = resolution.getModel(); 60 try { 61 return webBean.getPropertyValue(md.getProperty(), model); 62 } catch (BeanException be) { 63 throw new MVCException(be); 64 } 65 } 66 67 84 public void setValue(MVCRequest mvcRequest, String definition, 85 ModelResolution resolution, Object value, Map extraParams) 86 throws MVCException { 87 88 assert (definition != null) : "definition == null"; 89 assert (resolution != null) : "resolution == null"; 90 91 Object model = resolution.getModel(); 92 BaseConfigStruct struct = (BaseConfigStruct) mvcRequest.getConfiguration(); 93 BaseFormConfig config = struct.baseFormConfig; 94 MetaData md = resolution.getMetaData(); 95 WebBean webBean = config.getFormBean(resolution.getMetaData().getID()); 96 try { 97 webBean.setPropertyValue(md.getProperty(), model, value, true); 98 } catch (BeanException be) { 99 throw new MVCException(be); 100 } catch (TypeConversionException tce) { 101 102 WebBeanProperty wbp = null; 103 try { 104 wbp = webBean.getWebBeanProperty(md.getProperty()); 105 } catch (BeanException be) { 106 throw new MVCException("FATAL: ", be); 107 } 108 109 mvcRequest.getValidatorParser().executeHandle(mvcRequest, tce, model, wbp); 111 } 112 } 113 } | Popular Tags |