1 15 16 package com.jdon.model; 17 18 import javax.servlet.http.HttpServletRequest ; 19 20 import org.apache.commons.beanutils.PropertyUtils; 21 22 import com.jdon.controller.events.EventModel; 23 import com.jdon.controller.model.Model; 24 import com.jdon.controller.model.ModelIF; 25 import com.jdon.model.config.ModelMapping; 26 import com.jdon.strutsutil.util.CreateViewPageUtil; 27 import com.jdon.util.Debug; 28 29 30 50 51 public abstract class ModelHandler implements ServiceHandler{ 52 53 private final static String module = ModelHandler.class.getName(); 54 55 protected ModelMapping modelMapping; 56 public void setModelMapping(ModelMapping modelMapping) { 57 this.modelMapping = modelMapping; 58 } 59 60 public ModelMapping getModelMapping() { 61 return modelMapping; 62 } 63 64 78 public ModelForm initForm(HttpServletRequest request) throws 79 Exception { 80 return null; 81 } 82 83 86 public Model initModel(HttpServletRequest request) throws Exception { 87 return null; 88 } 89 90 105 public ModelIF initModelIF(EventModel em, ModelForm form, HttpServletRequest request) throws Exception { 106 return initModel(request); 107 } 108 109 112 public Model findModelByKey(String keyValue, HttpServletRequest request) throws 113 Exception { 114 return null; 115 116 } 117 118 127 public ModelIF findModelIF(Object keyValue, HttpServletRequest request) throws Exception { 128 return findModelByKey((String )keyValue, request); } 130 131 132 139 public abstract void serviceAction(EventModel em, HttpServletRequest request) throws 140 Exception ; 141 142 143 146 public void modelCopyToForm(Model model, ModelForm form) throws Exception { 147 try { 148 PropertyUtils.copyProperties(form, model); 149 } catch (Exception e) { 150 String error = " Model:" + model.getClass().getName() +" copy To ModelForm:"+ form.getClass().getName() +" error:" + e; 151 Debug.logError(error, module); 152 throw new Exception (error); 153 } 154 } 155 156 168 public void modelIFCopyToForm(ModelIF model, ModelForm form) throws Exception { 169 if (model instanceof Model){ modelCopyToForm((Model)model, form); 171 return; 172 } 173 try { 174 PropertyUtils.copyProperties(form, model); 175 } catch (Exception e) { 176 String error = " Model:" + model.getClass().getName() +" copy To ModelForm:"+ form.getClass().getName() +" error:" + e; 177 Debug.logError(error, module); 178 throw new Exception (error); 179 } 180 } 181 182 185 public void formCopyToModel(ModelForm form, Model model) throws Exception { 186 try { 187 PropertyUtils.copyProperties(model, form); 188 } catch (Exception e) { 189 String error = " ModelForm:" + form.getClass().getName() 190 + " copy To Model:" + model.getClass().getName() 191 + " error:" + e; 192 Debug.logError(error, module); 193 throw new Exception (error); 194 } 195 } 196 197 212 public void formCopyToModelIF(ModelForm form, ModelIF model) throws Exception { 213 if (model instanceof Model){ formCopyToModel(form, (Model)model); 215 return; 216 } 217 try { 218 PropertyUtils.copyProperties(model, form); 219 } catch (Exception e) { 220 String error = " ModelForm:"+ form.getClass().getName() +" copy To Model:"+model.getClass().getName() +" error:" + e; 221 Debug.logError(error, module); 222 throw new Exception (error); 223 } 224 } 225 226 } 227 | Popular Tags |