⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmlmodelhandler.java

📁 用jbuilder写的源程序
💻 JAVA
字号:
/**
 * Copyright 2003-2006 the original author or authors.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */

package com.jdon.model.handler;

import javax.servlet.http.HttpServletRequest;

import com.jdon.bussinessproxy.meta.MethodMetaArgs;
import com.jdon.controller.events.Event;
import com.jdon.controller.events.EventModel;
import com.jdon.controller.model.ModelIF;
import com.jdon.controller.service.Service;
import com.jdon.controller.service.ServiceFacade;
import com.jdon.model.ModelForm;
import com.jdon.model.ModelHandler;
import com.jdon.util.Debug;


/**
 *  it is a meta ModelHandler, all methods are finished by
 *  the definition in jdonframework.xml
 * 
 *  XmlModelHandler is loaded by XmlHandlerClassFactory from container.xml
 * 
 *  XmlModelHandler is the client of container, XmlModelHandler will be made
 *  many instance by HandlerObjectFactory.
 * 
 * @author banq
 */
public class XmlModelHandler extends ModelHandler {
  private final static String module = XmlModelHandler.class.getName();
  
  private HandlerMethodMetaArgsFactory maFactory;;
  
  private ServiceFacade serviceFacade;

   
    /**
     * @param service
     */
   public XmlModelHandler() {
        this.maFactory = new HandlerMethodMetaArgsFactory();
        this.serviceFacade = new ServiceFacade();
   }
  /**
   * if your application need initialize the ModelForm,
   * this method is a option.
   * extends thie method. 
   */
  public ModelIF initModelIF(EventModel em, ModelForm form, HttpServletRequest request) throws Exception {    
    ModelIF result = null;
    try {
        HandlerMetaDef hm = this.modelMapping.getHandlerMetaDef();
        String serviceName = hm.getServiceRef();
        Debug.logVerbose("[JdonFramework] construct the CRUD method for the service:" + serviceName , module);        
        MethodMetaArgs methodMetaArgs = maFactory.createinitMethod(hm, em);
        
        Service service = serviceFacade.getService(request);
        if (methodMetaArgs != null)
        result = (ModelIF)service.execute(serviceName,
                                        methodMetaArgs,
                                        request);
    } catch (Exception e) {
       Debug.logError("[JdonFramework] initModel error: " + e , module);
       throw new Exception(e);
    }
    return result;
  }
  
  

  public ModelIF findModelIF(Object keyValue, HttpServletRequest request) throws
      java.lang.Exception {
    Object result = null;
    try {
        HandlerMetaDef hm = this.modelMapping.getHandlerMetaDef();
        String serviceName = hm.getServiceRef();
        Debug.logVerbose("[JdonFramework] construct the CRUD method for the service:" + serviceName , module);
        MethodMetaArgs methodMetaArgs = maFactory.createGetMethod(hm, keyValue);        
        if (methodMetaArgs.getMethodName() == null)
            throw new Exception("no configure findMethod value, but now you call it: ");
        Service service = serviceFacade.getService(request);
        result = service.execute(serviceName,
                                 methodMetaArgs,
                                 request);
    } catch (Exception e) {
        Debug.logError("[JdonFramework] findModelByKey error: " + e + " maybe not configure getMethod", module);
        throw new Exception(e);
    }
    Debug.logVerbose("[JdonFramework] result type:" + result.getClass().getName(), module);
    return (ModelIF) result;
  }

  public void serviceAction(EventModel em, HttpServletRequest request) throws
      java.lang.Exception {
      Debug.logVerbose("[JdonFramework] enter the serviceAction " , module);
    try {
      HandlerMetaDef hm = this.modelMapping.getHandlerMetaDef();
      String serviceName = hm.getServiceRef();
      MethodMetaArgs methodMetaArgs = null;
      switch (em.getActionType()) {
        case Event.CREATE:
          Debug.logVerbose("[JdonFramework] construct the CRUD method for the service:" + serviceName , module);
          methodMetaArgs = maFactory.createCreateMethod(hm, em);
          break;
        case Event.EDIT:
          Debug.logVerbose("[JdonFramework] construct the CRUD method for the service:" + serviceName , module);
          methodMetaArgs = maFactory.createUpdateMethod(hm, em);
          break;
        case Event.DELETE:
          Debug.logVerbose("[JdonFramework] construct the CRUD method for the service:" + serviceName , module);
          methodMetaArgs = maFactory.createDeleteMethod(hm, em);
          break;
        default:
          Debug.logVerbose("[JdonFramework] construct the command method for the service:" + serviceName , module);            
          methodMetaArgs = maFactory.createDirectMethod(em.getActionName(), new Object[]{em});
      }      
      Debug.logVerbose( " execute the method: " + methodMetaArgs.getMethodName() + " for the service: " + serviceName , module);
      Service service = serviceFacade.getService(request);
      service.execute(serviceName, methodMetaArgs, request);
    } catch (Exception ex) {
      Debug.logError("[JdonFramework] serviceAction Error: " + ex , module);
      throw new Exception(" serviceAction Error:" + ex);
    }

  }
  
 
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -