1 16 package com.jdon.strutsutil; 17 18 import javax.servlet.http.HttpServletRequest ; 19 import javax.servlet.http.HttpServletResponse ; 20 21 import org.apache.struts.action.ActionForm; 22 import org.apache.struts.action.ActionForward; 23 import org.apache.struts.action.ActionMapping; 24 import org.apache.struts.action.ActionMessage; 25 import org.apache.struts.action.ActionMessages; 26 27 import com.jdon.controller.WebAppUtil; 28 import com.jdon.controller.events.EventModel; 29 import com.jdon.controller.model.ModelIF; 30 import com.jdon.model.ModelForm; 31 import com.jdon.model.ModelHandler; 32 import com.jdon.model.handler.HandlerMetaDef; 33 import com.jdon.util.Debug; 34 35 65 public class ServiceMethodAction extends ModelBaseAction { 66 private final static String module = ServiceMethodAction.class.getName(); 67 68 public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) 69 throws Exception { 70 intContext(this.getServlet().getServletContext()); 71 72 ModelForm modelForm = (ModelForm) actionForm; 73 if ((modelForm == null) || (modelForm.getMethod() == null)) { 74 Debug.logError("[JdonFramework] no form or no action/method ", module); 75 return actionMapping.findForward("forward"); 76 } 77 String formName = FormBeanUtil.getFormName(actionMapping); 78 Debug.logVerbose("[JdonFramework]--> enter ServiceMethodAction, formName = " + formName, module); 79 ModelHandler modelHandler = modelManager.borrowtHandlerObject(formName); 80 EventModel em = new EventModel(); 81 try { 82 ModelIF modelDTO = modelManager.getModelObject(formName); 83 modelHandler.formCopyToModelIF(modelForm, modelDTO); 84 85 HandlerMetaDef hm = modelHandler.getModelMapping().getHandlerMetaDef(); 86 87 String serviceName = hm.getServiceRef(); 88 89 em.setActionName(modelForm.getMethod()); 90 em.setModelIF(modelDTO); 91 Object result = WebAppUtil.callService(serviceName, modelForm.getMethod(), new Object []{em}, request); 92 if (result instanceof ModelIF){ 93 modelDTO = (ModelIF)result; 94 modelHandler.modelIFCopyToForm(modelDTO, modelForm); 95 } 96 } catch (Exception ex) { 97 Debug.logError("[JdonFramework]please check your service � model or form :" + ex, module); 98 throw new Exception ("System error! please call system Admin." + ex); 99 } finally { 100 modelManager.returnHandlerObject(modelHandler); 101 } 102 if (em.getErrors() != null) { 103 Debug.logError("[JdonFramework] error happend " + em.getErrors(), module); 104 ActionMessages errors = new ActionMessages(); 105 ActionMessage error = new ActionMessage(em.getErrors()); 106 errors.add(ActionMessages.GLOBAL_MESSAGE, error); 107 saveErrors(request, errors); 108 } 109 return actionMapping.findForward(modelForm.getAction()); 110 } 111 } 112 | Popular Tags |