1 7 package com.inversoft.verge.mvc.model.repository; 8 9 10 import java.util.Map ; 11 12 import javax.servlet.http.HttpServletRequest ; 13 14 import com.inversoft.beans.BeanException; 15 import com.inversoft.util.typeconverter.TypeConversionException; 16 import com.inversoft.verge.mvc.MVCException; 17 import com.inversoft.verge.mvc.MVCRequest; 18 import com.inversoft.verge.mvc.model.ModelHandler; 19 import com.inversoft.verge.mvc.model.ModelResolution; 20 import com.inversoft.verge.repository.RepositoryBeanProperty; 21 22 23 32 public class RepositoryModelHandler implements ModelHandler { 33 34 37 public RepositoryModelHandler() { 38 } 39 40 54 public Object getValue(MVCRequest mvcRequest, String definition, 55 ModelResolution resolution, Map extraParams) 56 throws MVCException { 57 58 RepositoryMetaData md = (RepositoryMetaData) resolution.getMetaData(); 59 if (md == null) { 60 md = new RepositoryMetaData(definition); 61 } 62 63 try { 64 HttpServletRequest request = mvcRequest.getRequest(); 65 RepositoryBeanProperty rbp = md.createRepositoryBeanProperty(request); 66 return rbp.getPropertyValue(request); 67 } catch (BeanException be) { 68 throw new MVCException(be); 69 } 70 } 71 72 86 public void setValue(MVCRequest mvcRequest, String definition, 87 ModelResolution resolution, Object value, Map extraParams) 88 throws MVCException { 89 90 RepositoryMetaData md = (RepositoryMetaData) resolution.getMetaData(); 91 if (md == null) { 92 md = new RepositoryMetaData(definition); 93 } 94 95 HttpServletRequest request = mvcRequest.getRequest(); 96 RepositoryBeanProperty rbp = null; 97 try { 98 rbp = md.createRepositoryBeanProperty(request); 99 rbp.setPropertyValue(request, value); } catch (BeanException be) { 101 throw new MVCException(be); 102 } catch (TypeConversionException tce) { 103 104 assert (rbp != null) : "rbp == null"; 105 106 mvcRequest.getValidatorParser().executeHandle(mvcRequest, tce, 108 resolution.getModel(), rbp); 109 } 110 } 111 } 112 | Popular Tags |