测试ofbiz3 的entity
2008-02-23 10:09:00来源:互联网 阅读 ()
测试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",
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash