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

📄 xmlhandlerclassfactory.java

📁 Java/J2EE框架Jdon-Framework系统的Sample
💻 JAVA
字号:
/**
 * Copyright 2005 Jdon.com
 * 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 extends 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();
    Class newClass = null;
    try {
      if (handlerClassName == null) {
        HandlerMetaDef handlerMetaDef = modelMapping.getHandlerMetaDef();
        if (handlerMetaDef == null) {
          throw new Exception("you must supply a handler config");
        }
        //使用框架中配置的modelHandler,如XmlModelHandler
        handlerClassName = modelHandler.getClass().getName();
        modelMapping.setHandler(handlerClassName);
      }
      Debug.logVerbose("create Handler class, key=" + formName + " value=" +
                    handlerClassName, module);
      newClass = Thread.currentThread().getContextClassLoader().
          loadClass(handlerClassName);
      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 + -