📄 commoncasehandler.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.
*/
package eti.bi.alphaminer.core.dao;
import java.io.IOException;
import java.io.StringWriter;
import java.util.Vector;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.XMLSerializer;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import eti.bi.alphaminer.vo.BICase;
import eti.bi.alphaminer.vo.Node;
import eti.bi.alphaminer.vo.NodeConnection;
import eti.bi.alphaminer.vo.NodeFactory;
import eti.bi.alphaminer.vo.OperatorNode;
import eti.bi.alphaminer.vo.TaskNode;
import eti.bi.exception.BaseException;
import eti.bi.exception.SysException;
/**
* @@author kjor
*
* To change this generated comment edit the template variable "typecomment":
* Window>Preferences>Java>Templates.
* To enable and disable the creation of type comments go to
* Window>Preferences>Java>Code Generation.
*/
public class CommonCaseHandler {
/**
* Constructor for CaseHandler.
*/
public CommonCaseHandler() {
super();
}
public static String getCML(BICase aCase)throws BaseException
{
String aCMLString = null;
Document m_Document = null;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try
{
DocumentBuilder builder = factory.newDocumentBuilder();
TaskNode aTaskNode = (TaskNode) aCase.getNode(NodeFactory.TASK, null);
if (aTaskNode ==null) throw new SysException();
m_Document = builder.newDocument();
Element root = (Element)m_Document.createElement("CML");
m_Document.appendChild(root);
// Insert Header Node
Element aHeader = m_Document.createElement("Header");
Element aCreateDate = m_Document.createElement("CreateDate");
aCreateDate.setAttribute("value",aCase.getCreateDate());
aHeader.appendChild(aCreateDate);
Element aCaseDescription = m_Document.createElement("CaseDescription");
aCaseDescription.setAttribute("value",aCase.getCaseDescription());
aHeader.appendChild(aCaseDescription);
Element aStatus = m_Document.createElement("Status");
aStatus.setAttribute("value",aCase.getStatus());
aHeader.appendChild(aStatus);
root.appendChild(aHeader);
//<<21/02/2005 Mark Li: Add Case Name
//Insert Case Name
Element aCaseName = m_Document.createElement("CaseName");
aCaseName.setAttribute("value",aTaskNode.getCaseName());
root.appendChild(aCaseName);
//21/02/2005 Mark Li: Add Case Name>>
// Insert Industry Node
Element aIndustry = m_Document.createElement("Industry");
aIndustry.setAttribute("value",aTaskNode.getIndustry());
root.appendChild(aIndustry);
// Insert ProblemType Node
Element aProblemType = m_Document.createElement("ProblemType");
aProblemType.setAttribute("value",aTaskNode.getProblemType());
root.appendChild(aProblemType);
// Insert BusinessObjective Node
Element aBusinessObjective = m_Document.createElement("BusinessObjective");
aBusinessObjective.setAttribute("value",aTaskNode.getBusinessObjective());
root.appendChild(aBusinessObjective);
// Insert DataMiningGoal Node
Element aDataMiningGoal = m_Document.createElement("DataMiningGoal");
aDataMiningGoal.setAttribute("value",aTaskNode.getDataMiningGoal());
root.appendChild(aDataMiningGoal);
// Insert CompanyName Node
Element aCompanyName = m_Document.createElement("CompanyName");
aCompanyName.setAttribute("value",aTaskNode.getCompanyName());
root.appendChild(aCompanyName);
// Insert DepartmentName Node
Element aDepartmentName = m_Document.createElement("DepartmentName");
aDepartmentName.setAttribute("value",aTaskNode.getDepartmentName());
root.appendChild(aDepartmentName);
// Insert ToolUsed Node
Element aToolUsed = m_Document.createElement("ToolUsed");
aToolUsed.setAttribute("value",aTaskNode.getToolUsed());
root.appendChild(aToolUsed);
StringWriter aWriter = new StringWriter();
OutputFormat format = new OutputFormat("xml","UTF-8",true);
XMLSerializer serializer = new XMLSerializer(aWriter,format);
serializer.serialize(m_Document);
aCMLString = aWriter.toString();
}catch (ParserConfigurationException pce)
{
throw new SysException(pce);
}catch (IOException ie)
{
throw new SysException(ie);
}
return aCMLString;
}
public static String getPML(BICase aCase)throws BaseException
{
String aPMLString = null;
Document m_Document = null;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try
{
DocumentBuilder builder = factory.newDocumentBuilder();
TaskNode aTaskNode = (TaskNode) aCase.getNode(NodeFactory.TASK, null);
if (aTaskNode ==null) throw new SysException();
m_Document = builder.newDocument();
Element root = (Element)m_Document.createElement("PML");
m_Document.appendChild(root);
//Insert Operator Nodes
Node aNodeList[] = aCase.getOperatorNodeListArray();
for (int i=0;i<aCase.getOperatorNodeListSize();i++)
{
if (!(aNodeList[i] instanceof OperatorNode))
throw new SysException();
OperatorNode aNode = (OperatorNode)aNodeList[i];
// Insert Header Node
Element aOperator = m_Document.createElement("Operator");
aOperator.setAttribute("operatorID", aNode.getNodeID());
// Insert Operator DefinitionID Node
Element aOperatorDefinitionID = m_Document.createElement("OperatorDefinitionID");
aOperatorDefinitionID.setAttribute("value",aNode.getOperatorDefinitionID());
aOperator.appendChild(aOperatorDefinitionID);
// Insert OperatorDisplayName Node
Element aOperatorDisplayName = m_Document.createElement("OperatorDisplayName");
aOperatorDisplayName.setAttribute("value",aNode.getNodeDescription());
aOperator.appendChild(aOperatorDisplayName);
// Insert OperatorPosition Node
Element aOperatorPosition = m_Document.createElement("OperatorPosition");
aOperatorPosition.setAttribute("xPosition",new Integer((int) aNode.getPositionX()).toString());
aOperatorPosition.setAttribute("yPosition",new Integer((int) aNode.getPositionY()).toString());
aOperator.appendChild(aOperatorPosition);
// Insert OperatorPath Node
Element aOperatorPath = m_Document.createElement("OperatorPath");
aOperatorPath.setAttribute("value",aNode.getPath());
aOperator.appendChild(aOperatorPath);
// Insert OperatorName Node
Element aOperatorName = m_Document.createElement("OperatorName");
aOperatorName.setAttribute("value",aNode.getName());
aOperator.appendChild(aOperatorName);
// Insert OperatorCategory Node
Element aOperatorCategory = m_Document.createElement("OperatorCategory");
aOperatorCategory.setAttribute("value",aNode.getCategory());
aOperator.appendChild(aOperatorCategory);
// Insert OperatorFunction Node
Element aOperatorFunction = m_Document.createElement("OperatorFunction");
aOperatorFunction.setAttribute("value",aNode.getFunction());
aOperator.appendChild(aOperatorFunction);
// Insert OperatorAlgorithm Node
Element aOperatorAlgorithm = m_Document.createElement("OperatorAlgorithm");
aOperatorAlgorithm.setAttribute("value",aNode.getAlgorithm());
aOperator.appendChild(aOperatorAlgorithm);
// Insert OperatorInput Nodes
Vector aInputTables = aNode.getInputTables();
for (int j=0;j<aInputTables.size();j++)
{
Element aOperatorInput = m_Document.createElement("OperatorInput");
aOperatorInput.setAttribute("value",aInputTables.elementAt(j).toString());
aOperator.appendChild(aOperatorInput);
}
// Insert OperatorParameter Nodes
String[][] aParameters = aNode.getParametersArray();
for (int k=0;k<aNode.getParametersSize();k++)
{
Element aOperatorParameter = m_Document.createElement("OperatorParameter");
Element aParameterName = m_Document.createElement("ParameterName");
aParameterName.setAttribute("value",aParameters[k][0].toString());
aOperatorParameter.appendChild(aParameterName);
Element aParameterValue = m_Document.createElement("ParameterValue");
aParameterValue.setAttribute("value",aParameters[k][1].toString());
aOperatorParameter.appendChild(aParameterValue);
aOperator.appendChild(aOperatorParameter);
}
// Insert OperatorOutput Nodes
Vector aOutputTables = aNode.getOutputTables();
for (int j=0;j<aOutputTables.size();j++)
{
Element aOperatorOutput = m_Document.createElement("OperatorOutput");
aOperatorOutput.setAttribute("value",aOutputTables.elementAt(j).toString());
aOperator.appendChild(aOperatorOutput);
}
root.appendChild(aOperator);
}
// Insert Process Node
Element aProcessElement = m_Document.createElement("Process");
// Insert Connection Nodes
eti.bi.alphaminer.vo.Process aProcess = aCase.getProcess();
Vector aConnections = aProcess.getConnectionList();
for (int m=0;m<aConnections.size();m++)
{
if (!(aConnections.elementAt(m) instanceof NodeConnection))
throw new SysException();
NodeConnection aConnection = (NodeConnection)aConnections.elementAt(m);
Element aConnectionElement = m_Document.createElement("Connection");
Element aHeadNode = m_Document.createElement("HeadNode");
aHeadNode.setAttribute("nodeID",aConnection.getHeadNodeID());
aConnectionElement.appendChild(aHeadNode);
Element aTailNode = m_Document.createElement("TailNode");
aTailNode.setAttribute("nodeID",aConnection.getTailNodeID());
aConnectionElement.appendChild(aTailNode);
aProcessElement.appendChild(aConnectionElement);
}
root.appendChild(aProcessElement);
StringWriter aWriter = new StringWriter();
OutputFormat format = new OutputFormat("xml","UTF-8",true);
XMLSerializer serializer = new XMLSerializer(aWriter,format);
serializer.serialize(m_Document);
aPMLString = aWriter.toString();
}catch (ParserConfigurationException pce)
{
throw new SysException(pce);
}catch (IOException ie)
{
throw new SysException(ie);
}
return aPMLString;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -