1 15 16 package com.jdon.model.handler; 17 18 import javax.servlet.http.HttpServletRequest ; 19 20 import com.jdon.bussinessproxy.meta.MethodMetaArgs; 21 import com.jdon.controller.events.Event; 22 import com.jdon.controller.events.EventModel; 23 import com.jdon.controller.model.ModelIF; 24 import com.jdon.controller.service.Service; 25 import com.jdon.controller.service.ServiceFacade; 26 import com.jdon.model.ModelForm; 27 import com.jdon.model.ModelHandler; 28 import com.jdon.util.Debug; 29 30 31 42 public class XmlModelHandler extends ModelHandler { 43 private final static String module = XmlModelHandler.class.getName(); 44 45 private HandlerMethodMetaArgsFactory maFactory;; 46 47 private ServiceFacade serviceFacade; 48 49 50 53 public XmlModelHandler() { 54 this.maFactory = new HandlerMethodMetaArgsFactory(); 55 this.serviceFacade = new ServiceFacade(); 56 } 57 62 public ModelIF initModelIF(EventModel em, ModelForm form, HttpServletRequest request) throws Exception { 63 ModelIF result = null; 64 try { 65 HandlerMetaDef hm = this.modelMapping.getHandlerMetaDef(); 66 String serviceName = hm.getServiceRef(); 67 Debug.logVerbose("[JdonFramework] construct the CRUD method for the service:" + serviceName , module); 68 MethodMetaArgs methodMetaArgs = maFactory.createinitMethod(hm, em); 69 70 Service service = serviceFacade.getService(request); 71 if (methodMetaArgs != null) 72 result = (ModelIF)service.execute(serviceName, 73 methodMetaArgs, 74 request); 75 } catch (Exception e) { 76 Debug.logError("[JdonFramework] initModel error: " + e , module); 77 throw new Exception (e); 78 } 79 return result; 80 } 81 82 83 84 public ModelIF findModelIF(Object keyValue, HttpServletRequest request) throws 85 java.lang.Exception { 86 Object result = null; 87 try { 88 HandlerMetaDef hm = this.modelMapping.getHandlerMetaDef(); 89 String serviceName = hm.getServiceRef(); 90 Debug.logVerbose("[JdonFramework] construct the CRUD method for the service:" + serviceName , module); 91 MethodMetaArgs methodMetaArgs = maFactory.createGetMethod(hm, keyValue); 92 if (methodMetaArgs.getMethodName() == null) 93 throw new Exception ("no configure findMethod value, but now you call it: "); 94 Service service = serviceFacade.getService(request); 95 result = service.execute(serviceName, 96 methodMetaArgs, 97 request); 98 } catch (Exception e) { 99 Debug.logError("[JdonFramework] findModelByKey error: " + e + " maybe not configure getMethod", module); 100 throw new Exception (e); 101 } 102 Debug.logVerbose("[JdonFramework] result type:" + result.getClass().getName(), module); 103 return (ModelIF) result; 104 } 105 106 public void serviceAction(EventModel em, HttpServletRequest request) throws 107 java.lang.Exception { 108 Debug.logVerbose("[JdonFramework] enter the serviceAction " , module); 109 try { 110 HandlerMetaDef hm = this.modelMapping.getHandlerMetaDef(); 111 String serviceName = hm.getServiceRef(); 112 MethodMetaArgs methodMetaArgs = null; 113 switch (em.getActionType()) { 114 case Event.CREATE: 115 Debug.logVerbose("[JdonFramework] construct the CRUD method for the service:" + serviceName , module); 116 methodMetaArgs = maFactory.createCreateMethod(hm, em); 117 break; 118 case Event.EDIT: 119 Debug.logVerbose("[JdonFramework] construct the CRUD method for the service:" + serviceName , module); 120 methodMetaArgs = maFactory.createUpdateMethod(hm, em); 121 break; 122 case Event.DELETE: 123 Debug.logVerbose("[JdonFramework] construct the CRUD method for the service:" + serviceName , module); 124 methodMetaArgs = maFactory.createDeleteMethod(hm, em); 125 break; 126 default: 127 Debug.logVerbose("[JdonFramework] construct the command method for the service:" + serviceName , module); 128 methodMetaArgs = maFactory.createDirectMethod(em.getActionName(), new Object []{em}); 129 } 130 Debug.logVerbose( " execute the method: " + methodMetaArgs.getMethodName() + " for the service: " + serviceName , module); 131 Service service = serviceFacade.getService(request); 132 service.execute(serviceName, methodMetaArgs, request); 133 } catch (Exception ex) { 134 Debug.logError("[JdonFramework] serviceAction Error: " + ex , module); 135 throw new Exception (" serviceAction Error:" + ex); 136 } 137 138 } 139 140 141 } 142 | Popular Tags |