中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > 编程语言 > Java > 综合文章
ofbiz3-ComponentContainer load 流程
作者:未知 时间:2005-07-27 22:26 出处:CSDN 责编:chinaitpower
              摘要:ofbiz3-ComponentContainer load 流程

ComponentContainer load 流程
/*
    1 : 前言
    ContainerLoader.java文件首先把ofbiz -
    container.xml定义的container读入到了.ContainerConfig
    2 : 加载
 */
    private Container loadContainer(String classname, String configFileLocation) throws
    StartupException {
  // load the component container class
  ClassLoader loader = Thread.currentThread().getContextClassLoader();
  if (loader == null) {
    Debug.logWarning("Unable to get context classloader; using system", module);
    loader = ClassLoader.getSystemClassLoader();
  }
  Class componentClass = null;
  try {
    componentClass = loader.loadClass(classname);
  }
  catch (ClassNotFoundException e) {
    throw new StartupException("Cannot locate container class", e);
  }
  if (componentClass == null) {
    throw new StartupException("Component container class not loaded");
  }

  Container componentObj = null;
  try {
    componentObj = (Container) componentClass.newInstance();
////通过classname生成实例
  }
  catch (InstantiationException e) {
    throw new StartupException(e);
  }
  catch (IllegalAccessException e) {
    throw new StartupException(e);
  }
  catch (ClassCastException e) {
    throw new StartupException(e);
  }

  if (componentObj == null) {
    throw new StartupException(
        "Unable to create instance of component container");
  }

  try {
    componentObj.start(configFileLocation); //容器初始化
  }
  catch (ContainerException e) {
    throw new StartupException(e);
  }

  return componentObj;
}
3 : ComponentContainer加载
    ComponentContainer.java类
    /*
       loadConfig参数是Components配置文件名,如果没有,将自动取系统自定义的
       Component-Load.xml,如果需要定义,可以
       <container
     name="component-container" class="org.ofbiz.base.container.ComponentContainer">
          <propterty name="load-config"  value="xxx.xml"/>
       </container>
       updateClasspath:加载完后是否重新设置classpath

     */
    public synchronized void loadComponents(String loaderConfig,
                                            boolean updateClasspath) throws
    AlreadyLoadedException, ComponentException {
  // 设置load list,如果失败,抛出Already Loaded Exception
  if (loadedComponents == null) {
    loadedComponents = new LinkedList(); //用Linklist保存将要加载的Components
  }
  else {
    throw new AlreadyLoadedException("Components already loaded, cannot start");
  }

  /*
     ComponentLoader将读取Component-Load.xml, 存储所有的组件,
             components存储的实例名是ComponentDef,它对应于:
      <load-component component-location="${ofbiz.home}/components/minerva"/>
   */
  List components = ComponentLoaderConfig.getComponentsToLoad(loaderConfig);

  /*
     加载每一个Components
   */
  if (components != null) {
    Iterator ci = components.iterator();
    while (ci.hasNext()) {
      ComponentLoaderConfig.ComponentDef def = (ComponentLoaderConfig.
                                                ComponentDef) ci.next();
      if (def.type == ComponentLoaderConfig.SINGLE_COMPONENT) {
        ComponentConfig config = null;
        try {
          /*在这里将要读取每个组件下的 ofbiz-component.xml文件
                比如:
                /components/minerva/ofbiz-component.xml
            /components/entity/ofbiz-component.xml
            ComponentConfig用一个静态的HashMap存储系统中所在的Component.
                每个ComponentConfig对应于一个ofbiz-component.xml文件.
           */
          config = ComponentConfig.getComponentConfig(def.name, def.location);
          if (UtilValidate.isEmpty(def.name)) {
            def.name = config.getGlobalName();
          }
        }
        catch (ComponentException e) {
          Debug.logError("Cannot load component : " + def.name + " @ " +
                         def.location + " : " + e.getMessage(), module);
        }
        if (config == null) {
          Debug.logError("Cannot load component : " + def.name + " @ " +
                         def.location, module);
        }
        else {

          /*
                   主要作要就是把当前Components用到的jar放入classpath中
           */
          loadComponent(config);
        }
      }
      else if (def.type == ComponentLoaderConfig.COMPONENT_DIRECTORY) {

        loadComponentDirectory(def.location);
      }
    }
  }

  // set the new classloader/classpath on the current thread
  if (updateClasspath) {
    System.setProperty("java.class.path", classPath.toString());
    ClassLoader cl = classPath.getClassLoader();
    Thread.currentThread().setContextClassLoader(cl);
  }

  Debug.logInfo("All components loaded", module);
}


mail: mzhanker@126.com


关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有