1 7 package com.inversoft.verge.mvc.model.web; 8 9 10 import java.util.HashMap ; 11 import java.util.Map ; 12 13 import javax.servlet.http.HttpServletRequest ; 14 15 import com.inversoft.beans.BeanException; 16 import com.inversoft.util.typeconverter.TypeConversionException; 17 import com.inversoft.verge.mvc.MVCException; 18 import com.inversoft.verge.mvc.MVCRequest; 19 import com.inversoft.verge.mvc.model.ModelHandler; 20 import com.inversoft.verge.mvc.model.ModelResolution; 21 import com.inversoft.verge.util.ScopeConstants; 22 import com.inversoft.verge.util.WebBeanProperty; 23 24 25 37 public class WebModelHandler implements ModelHandler { 38 39 42 public WebModelHandler() { 43 super(); 44 } 45 46 55 public Object getValue(MVCRequest mvcRequest, String definition, 56 ModelResolution resolution, Map extraParams) 57 throws MVCException { 58 59 WebMetaData md = (WebMetaData) resolution.getMetaData(); 60 if (md == null) { 61 md = buildMetaData(definition, resolution, extraParams); 62 } 63 64 HttpServletRequest request = mvcRequest.getRequest(); 65 WebBeanProperty wbp = null; 66 try { 67 wbp = md.createWebBeanProperty(); 68 return wbp.getPropertyValue(request); 69 } catch (BeanException be) { 70 throw new MVCException(be); 71 } 72 } 73 74 84 public void setValue(MVCRequest mvcRequest, String definition, 85 ModelResolution resolution, Object value, Map extraParams) 86 throws MVCException { 87 88 WebMetaData md = (WebMetaData) resolution.getMetaData(); 89 if (md == null) { 90 md = buildMetaData(definition, resolution, extraParams); 91 } 92 93 HttpServletRequest request = mvcRequest.getRequest(); 94 WebBeanProperty wbp = null; 95 try { 96 wbp = md.createWebBeanProperty(); 97 wbp.setPropertyValue(request, value); } catch (BeanException be) { 99 throw new MVCException(be); 100 } catch (TypeConversionException tce) { 101 102 assert (wbp != null) : "wbp == null"; 103 104 mvcRequest.getValidatorParser().executeHandle(mvcRequest, tce, 106 resolution.getModel(), wbp); 107 } 108 } 109 110 WebMetaData buildMetaData(String definition, ModelResolution resolution, 111 Map extraParams) 112 throws MVCException { 113 if (extraParams == null) { 114 extraParams = new HashMap (); 115 extraParams.put(WebMetaData.CLASS_PARAMETER, 116 resolution.getModel().getClass().getName()); 117 extraParams.put(WebMetaData.SCOPE_PARAMETER, 118 Integer.toString(ScopeConstants.REQUEST_INT)); 119 } 120 121 return new WebMetaData(definition, extraParams); 122 } 123 } | Popular Tags |