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

📄 xmlhandlerclassfactory.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.config;

import com.jdon.model.handler.HandlerClassFactory;
import com.jdon.util.Debug;
import com.jdon.model.mapping.ModelMapping;

import com.jdon.model.handler.HandlerMetaDef;
import com.jdon.model.ModelHandler;

public class XmlHandlerClassFactory implements HandlerClassFactory {

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

  private ModelHandler modelHandler;
  public XmlHandlerClassFactory(ModelHandler modelHandler) {
    this.modelHandler = modelHandler;
  }

  public Class createModel(ModelMapping modelMapping) {
    Debug.logVerbose(" XmlHandlerClassFactory create Model :",    module);
    String formName = modelMapping.getFormName();
    String className = modelMapping.getClassName();
    Class newClass = null;
    try {
      Debug.logVerbose("create model class, key=" + formName + " value=" +
                       className, module);
      newClass = Thread.currentThread().getContextClassLoader().
          loadClass(className);
      if (newClass == null) {
        throw new Exception(" classLoader problem: " +
                            " please check your config xml or check your pakcage");
      }
    } catch (Exception ex) {
      className = className.replaceAll(" ", "[ ]");
      Debug.logError(" className=" + className + " error:" + ex, module);
    }
    return newClass;
  }

  public Class createHandler(ModelMapping modelMapping) {
    Debug.logVerbose(" XmlHandlerClassFactory create Handler :",      module);
    String formName = modelMapping.getFormName();
    String handlerClassName = modelMapping.getHandler();
    HandlerMetaDef handlerMetaDef = modelMapping.getHandlerMetaDef();    
    Class newClass = null;
    try {
      if (handlerMetaDef != null) { // there is handler/service configure
        if (handlerClassName == null){// there is no  handler ClassName configure    
            //使用框架中配置的modelHandler,如XmlModelHandler
            handlerClassName = modelHandler.getClass().getName();
            modelMapping.setHandler(handlerClassName);
            newClass = modelHandler.getClass();
        }        
      }
      if (handlerClassName != null){
        newClass = Thread.currentThread().getContextClassLoader().loadClass(handlerClassName);
      }
      Debug.logVerbose("create Handler class, key=" + formName + " value=" +
              handlerClassName, module);      
      if (newClass == null) {
        throw new Exception(" classLoader problem: " +
                            " please check your config xml or check your pakcage");
      }
    } catch (Exception ex) {
      Debug.logError("  error:" + ex, module);
    }
    return newClass;
  }

}

⌨️ 快捷键说明

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