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

📄 robot.java

📁 一个数据挖掘软件ALPHAMINERR的整个过程的JAVA版源代码
💻 JAVA
字号:
/*
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software
 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/*
 * Created on 2005/3/17
 *
 * $Author$
 * $Date$
 * $Revision$
 *
 */
package eti.bi.test;
 
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Hashtable;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.Vector;

import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import eti.bi.alphaminer.core.config.ConfigLoader;
import eti.bi.alphaminer.core.dao.BIMLDAO;
import eti.bi.alphaminer.core.dao.DAOFactory;
import eti.bi.alphaminer.core.handler.CaseHandler;
import eti.bi.alphaminer.ui.ApplicationWindow;
import eti.bi.alphaminer.ui.KBBIApplication;
import eti.bi.alphaminer.vo.BICase;
import eti.bi.alphaminer.vo.Node;
import eti.bi.alphaminer.vo.TaskNode;
import eti.bi.common.Constants;
import eti.bi.exception.AppException;
import eti.bi.exception.BaseException;
import eti.bi.exception.SysException;


/**
 * @author kelvinj
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class Robot {

	private static Vector<String> m_CaseIDs = new Vector<String>();
	private static Vector<BICase> m_Cases = new Vector<BICase>();
	
	private static Hashtable<String, Vector<Node>> m_ExecuteNodes = new Hashtable<String, Vector<Node>>();
	
	private CaseHandler m_CaseHandler = null;
	private ApplicationWindow m_ApplicationWindow = null;
	
	private static String CASE_FILE_NAME = "caselist.txt";
	
	private static FileWriter LOG = null;    

	private String m_ConfigFile = "eti.bi.alphaminer.resource.property.ApplicationConfig";
	ResourceBundle m_Config;
	private String m_Version;
	private String m_ProductName;

	/**
	 * 
	 */
	public Robot() {
		super();
		m_CaseHandler = CaseHandler.getInstance();
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
			String language = "en"; //zh zh zh en
			String country = "CN";  //HK CN TW US
			  
			Locale currentLocale = new Locale(language, country);    
			m_Config = ResourceBundle.getBundle(m_ConfigFile, currentLocale);
			m_Version = "Release "+m_Config.getString("release") + " (Build "+m_Config.getString("build")+")";
			m_ProductName = m_Config.getString("productname");
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (UnsupportedLookAndFeelException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	    System.setProperty("file.encoding", "UTF8");
	}

	public void execute() throws SysException, IOException
	{
		try {
			LOG.write("Initiate KBBIApplication ... ");
			ApplicationWindow.POPUP_WINDOW = false;
			KBBIApplication.BACKGOUND_EXECUTION = true;
			m_ApplicationWindow = KBBIApplication.getApplicationWindow();
			LOG.write(m_ProductName + " : " + m_Version + "\n\n");
			for (int i=0;i<m_Cases.size();i++)
			{
				try
				{
					BICase runningCase = m_Cases.get(i);
					m_CaseHandler.setCase(runningCase);
	
					TaskNode taskNode = runningCase.getTaskNode();
					LOG.write("\n****************************************************\n");
					LOG.write("Execute "+ runningCase.getCaseID() + "("+ taskNode.getCaseName()+")\n");
	
					Vector tailNodes = m_ExecuteNodes.get(runningCase.getCaseID());
					for (int j=0;j<tailNodes.size();j++)
					{
						LOG.write("execute ["+((Node)tailNodes.get(j)).getNodeDescription() + " <" + ((Node)tailNodes.get(j)).getNodeID() + "> ] ... ");
						try
						{
							m_CaseHandler.executeNode(runningCase.getCaseID(), ((Node)tailNodes.get(j)).getNodeID());
							LOG.write("Passed\n");
						}catch (Exception e)
						{
							LOG.write("Failed (Cause: "+e.getMessage() + ")\n");
						}
					}
				}catch (Exception e)
				{
					LOG.write("Failed (Cause: "+e.getMessage() + ")\n");
				}
				
				LOG.write("****************************************************\n");
			}
			LOG.write("\nTerminate Application ...");
			m_ApplicationWindow.dispose();
			LOG.write("Done\n");
		} catch (Exception e) {
			e.printStackTrace();
			// Report the error using the appropriate name and ID.
		}
	}
	
	public void loadCases() throws SysException, IOException
	{
		LOG.write("============================================================\n");
		LOG.write("                      KBBI Robot (SIT)             \n");
		LOG.write("============================================================\n");
		BIMLDAO aBIMLDAO;
		try {
			aBIMLDAO = (BIMLDAO) DAOFactory.getDAO("BIML", Constants.BIML_DAO_TYPE);
		} catch (AppException e) {
			throw new SysException("Cannot create BIMLDAO Object");
		}
		
		BufferedReader in = null;
		File aFile = null;
		try {
			aFile = new File(CASE_FILE_NAME);
			LOG.write("Case Definition File: " + aFile.getAbsolutePath() + "\n");
			in = new BufferedReader(new FileReader(aFile));
			
			String line = in.readLine();
			while(line !=null)
			{
				String caseID = line.trim();
				if (caseID.length()>0)
				{
					try {
						LOG.write("Loading case "+caseID);
						BICase aCase = aBIMLDAO.getCaseById(caseID);
						if (aCase == null)
						{
							throw new SysException(caseID + " Not Found.");
						}
						TaskNode runningTask = aCase.getTaskNode();
						LOG.write("(" + runningTask.getCaseName() + ").....");
						Vector<Node> tailNodes = getTailNodes(aCase);
						m_ExecuteNodes.put(caseID,tailNodes);
						m_Cases.add(aCase);
						m_CaseIDs.add(caseID);
						LOG.write("...Done\n");
					} catch (BaseException e3) {
						// Do nothing, try to get another case
						LOG.write(".....Fail (Cause: " + e3.getMessage() + ")\n");
					}
				}
				line = in.readLine();
			}
			in.close();
		} catch (FileNotFoundException e1) {
			throw new SysException("File : " + aFile.getAbsolutePath());
		}catch (IOException e2) {
			throw new SysException("IO Exception, file : " +aFile.getAbsolutePath());
		}
		
	}
	
	private Vector<Node> getTailNodes(BICase a_Case) throws IOException
	{
		LOG.write("analysing...");
		Node[] nodes = a_Case.getOperatorNodeListArray();
		Vector<Node> tailNodes = new Vector<Node>();
		
		eti.bi.alphaminer.vo.Process process = a_Case.getProcess();
		for (int i=0;i<nodes.length;i++)
		{
			Vector child = process.getChildrenOfNode(nodes[i].getNodeID());
			boolean isTail = false;
			
			/*if (((OperatorNode)nodes[i]).getOperatorNodeType()==OperatorNode.ETI_INSIGHT)
			{
				// Skip Insight operator
				isTail = false;
			}else */if (child.size()==0)
			{
				// No Child, It's a tail node
				isTail = true;
			}else
			{
				// assume it's tail, if any one of the child nodes is not insight, it not a tail 
				isTail = true;
				for (int j=0;j<child.size();j++)
				{
				}
			}
			if (isTail)
			{
				tailNodes.add(nodes[i]);
			}

		}
		return tailNodes;
	}
	
	public static void main(String[] args) throws Exception 
	{
		ConfigLoader.loadConfig();
		File logFile = null;
		if (args.length>1)
		{
			CASE_FILE_NAME = args[0];
			logFile = new File(args[1]);
			if (!logFile.exists())
			{
				System.err.println(logFile.getAbsoluteFile() + " does not exist.");
				return;
			}
		}else
		{
			System.err.println("Usage: Robot <casefile> <logfile>");
			return;
		}
		
		System.out.println("Log file : " + logFile.getAbsolutePath());
		try {
			LOG = new FileWriter(logFile);
			Robot robot = new Robot();
			try {
				robot.loadCases();
				LOG.write("\n\n\n");
				robot.execute();
			} catch (SysException e1) {
				LOG.write("Error: e1.getMessage()\n");
			}
			LOG.close();
		} catch (IOException e) {
			System.err.println("IOException: " + e.getMessage());
		}
	}
}

⌨️ 快捷键说明

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