Java

本类阅读TOP10

·使用MyEclipse开发Struts框架的Hello World!(录像1)
·hibernate配置笔记
·AOP编程入门--Java篇
·linux下Tomcat 5.0.20 与 Apache 2 安装/集成/配置
·在win2003下整合了整合Tomcat5.5+ apache_2.0.53+ mod_jk_2.0.47.dll
·构建Linux下IDE环境--Eclipse篇
·Jsp 连接 mySQL、Oracle 数据库备忘(Windows平台)
·ASP、JSP、PHP 三种技术比较
·Tomcat5.5.9的安装配置
·AWT GUI 设计笔记(二)

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
测试ofbiz3 的entity

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

 测试ofbiz3 的entity.
 
  前期工作:

     1:请先用jbx建立ofbiz3的应用
     2:在D:\work\ofbiz\base\config中建一个ofbiz-test.xml文件,内容为:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ofbiz-containers PUBLIC "-//OFBiz//DTD Containers Config//EN" "http://www.ofbiz.org/dtds/ofbiz-containers.dtd">
<ofbiz-containers>
    <!-- load the ofbiz components (always first) -->
    <container name="component-container" class="org.ofbiz.base.container.ComponentContainer"/>

    <!-- load the cached classloader container (always second) -->
    <container name="classloader-container" class="org.ofbiz.base.container.ClassLoaderContainer"/>

    <!-- load JNDI/JOTM -->
    <container name="jotm-container" class="org.ofbiz.entity.transaction.JotmContainer"/>

    <!-- RMI Service Dispatcher -->
    <container name="rmi-dispatcher" class="org.ofbiz.service.rmi.RmiServiceContainer">
        <property name="lookup-name" value="RMIDispatcher"/>
        <property name="delegator-name" value="default"/>
        <property name="client-factory" value="org.ofbiz.service.rmi.socket.CompressionClientSocketFactory"/>
        <property name="server-factory" value="org.ofbiz.service.rmi.socket.CompressionServerSocketFactory"/>
    </container>

  
</ofbiz-containers>

     3:copy D:\work\ofbiz\base\src\start\org\ofbiz\base\start\Start.properties 到src目录

     4:修改Start.properties文件:
       ofbiz.container.config=base/config/ofbiz-test.xml


 编写java文件:

    package test;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.ConnectException;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import org.ofbiz.base.start.*;
import org.ofbiz.entity.*;
import org.ofbiz.base.util.*;


public class TestEntity {

  public static final String CONFIG_FILE = "start.properties";
  public static final String SHUTDOWN_COMMAND = "SHUTDOWN";
  public static final String STATUS_COMMAND = "STATUS";

  private Classpath classPath = new Classpath(System.getProperty(
      "java.class.path"));

  private List loaders = null;
  private Start.Config config = null;

  public TestEntity(String configFile) throws IOException {
    if (configFile == null) {
      configFile = CONFIG_FILE;
    }

    this.config = new Start.Config(configFile);
    this.loaders = new ArrayList();
  }

  private void loadLibs(String path) throws Exception {
    File libDir = new File(path);
    if (libDir.exists()) {
      File files[] = libDir.listFiles();
      for (int i = 0; i < files.length; i++) {
        String fileName = files[i].getName();
        if (files[i].isDirectory() && !"CVS".equals(fileName)) {
          loadLibs(files[i].getCanonicalPath());
        }
        else if (fileName.endsWith(".jar") || fileName.endsWith(".zip")) {
          classPath.addComponent(files[i]);
        }
      }
    }
  }

  private void startServer() throws Exception {
    // load the lib directory
    loadLibs(config.baseLib);

    // load the ofbiz-base.jar
    classPath.addComponent(config.baseJar);

    // load the config directory
    classPath.addComponent(config.baseConfig);

    // set the classpath/classloader
    System.setProperty("java.class.path", classPath.toString());
    ClassLoader classloader = classPath.getClassLoader();
    Thread.currentThread().setContextClassLoader(classloader);

    // stat the log directory
    boolean createdDir = false;
    File logDir = new File(config.logDir);
    if (!logDir.exists()) {
      logDir.mkdir();
      createdDir = true;
    }

    // start the loaders
    Iterator li = config.loaders.iterator();
    while (li.hasNext()) {
      String loaderClassName = (String) li.next();
      try {
        Class loaderClass = classloader.loadClass(loaderClassName);
        StartupLoader loader = (StartupLoader) loaderClass.newInstance();
        loader.load(config);
        loaders.add(loader);
      }
      catch (Exception e) {
        e.printStackTrace();
        System.exit(99);
      }
    }
  }

  public void testEntity() throws Exception {
    System.out.println("Entered testFindByPrimaryKey");
//Instantiate the delegator.
    GenericDelegator delegator = GenericDelegator.getGenericDelegator("default");

// Find book by primary key
    try {
      GenericValue party = delegator.findByPrimaryKey("PartyType",
          UtilMisc.toMap("partyTypeId", "PERSON"));
      System.out.println(party.getString("description") );
      System.out.println(party.getString("hasTable") );      
    }
    catch (GenericEntityException ex1) {
    }
    return;


}

public void start() throws Exception {
  startServer();
}

public static void main(String[] args) throws Exception {
  TestEntity start = new TestEntity(args.length == 2 ? args[1] : null);

  start.start();
  start.testEntity();

}

}
    
         
编译,运行:

结果为:


Entered testFindByPrimaryKey

Person

Y


mail:mzhanker@126.com

  




相关文章

相关软件