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

📄 modelhandler.java

📁 一个非常好的FRAMWRK!是一个外国组织做的!不!
💻 JAVA
字号:
/**
 * Copyright 2003-2005 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;

import javax.servlet.http.HttpServletRequest;
import com.jdon.controller.model.Model;
import com.jdon.controller.events.EventModel;

import com.jdon.util.Debug;


import org.apache.commons.beanutils.PropertyUtils;
import com.jdon.model.mapping.ModelMapping;


/**
 * Presentation layer delegateion class
 * Presentation layer need  three common works collaboration with service layer:
 * 
 * 1.  Presentation layer need a ModelForm instance that include
 * some initially data, these data must obtain from service.
 * 
 * 2. Presentation layer must obtain a existed ModelForm instance from service
 * 
 * 3. Presentation layer submit the data ModelForm instance that user created or
 * update, service layer must persistence them
 *
 * Framework's user can extends this ModelHandler, and 
 * configure your jdonframework.xml, so ask framework active it:
 *  <model ...>
      <handler class="your ModelHandler concrete class" />
    </model>
 *
 * @author banq
 */

public abstract class ModelHandler implements ServiceHandler{

  private final static String module = ModelHandler.class.getName();

  protected ModelMapping modelMapping;
  public void setModelMapping(ModelMapping modelMapping) {
    this.modelMapping = modelMapping;
  }

  public ModelMapping getModelMapping() {
    return modelMapping;
  }

  /**
   *
   *Presentation layer need a ModelForm instance that include
   *  some initially data, these data must obtain from service.
   * this method implements these functions in presentation layer's
   * ModelHanlder concrete class;
   * 
   * this method is available in pushing create or edit view page  
   * 
   * @param request
   * @return ModelForm instance
   * @throws java.lang.Exception
   * 
   */
  public ModelForm initForm(HttpServletRequest request) throws
      Exception{
      return null;
  }

  /**
   *Presentation layer need a ModelForm instance that include
   *  some initially data, these data must obtain from service.
   * this method implements these functions by deleagating 
   * service. 
   *  
   * this mehtod is only availabe in pushing create view page 
   * in pushing editable view page, the model is obtained
   * by it's key, not from this method;
   * 
   * @param request
   * @return Model instance
   * @throws Exception
   * @see CreateViewPageUtil
   */
  public Model initModel(HttpServletRequest request) throws Exception{
      return null;
  }


  /**
   * obtain a existed Model instance by his primtive key.
   * 
   * 
   * @param keyValue primtive key
   * @param request 
   * @return Model
   * @throws java.lang.Exception
   */
  public abstract Model findModelByKey(String keyValue,
                                       HttpServletRequest request) throws
      Exception;

  /**
   * package the Model instance that has user's input data to EventModel object,
   * and submit them to servier layer;
   * @param em package Model instance
   * @param request
   * @throws java.lang.Exception
   */
  public abstract void serviceAction(EventModel em, HttpServletRequest request) throws
      Exception;


  /**
   * Model object's data transfer to ModelForm object
   *
   * default implemention is copy mapping between with them;
   * another implemention is :   
   * PropertyUtils.setProperty
   * extends this class , and override this method
   * 
   * @param model
   * @param form
   * @throws java.lang.Exception
   */
  public void modelCopyToForm(Model model, ModelForm form) throws Exception {
     try {
      PropertyUtils.copyProperties(form, model);
    } catch (Exception e) {
      e.printStackTrace();
      Debug.logError(" formCopyToModel error:" + e, module);
      throw new Exception(" formCopyToModel error:");
    }
  }

  /**
   * ModelForm object's data transfer to Model object
   *
   * default implemention is copy mapping between with them;

   * another implemention:
   * String propertyName = StringUtil.getLastString(model.getClass().getName()); 
   * Model hasDataModel = PropertyUtils.getProperty(form, propertyName);
   * model = hasDataModel;
   * 
   * extends this class , and override this method 
   * 
   * @param model
   * @param form
   * @throws java.lang.Exception
   */
  public void formCopyToModel(ModelForm form, Model model) throws Exception {
    try {
      PropertyUtils.copyProperties(model, form);
    } catch (Exception e) {
      e.printStackTrace();
      Debug.logError(" formCopyToModel error:" + e , module);
      throw new Exception(" formCopyToModel error:");
    }
  }



}

⌨️ 快捷键说明

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