📄 casefactory.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.vo;
import java.text.DecimalFormat;
import java.util.Calendar;
import java.util.Vector;
import eti.bi.alphaminer.core.dao.BIMLDAO;
import eti.bi.alphaminer.core.dao.DAOFactory;
import eti.bi.alphaminer.vo.BICase;
import eti.bi.alphaminer.vo.Node;
import eti.bi.alphaminer.vo.NodeConnection;
import eti.bi.common.Constants;
import eti.bi.exception.AppException;
/**
* CaseFactory is responsible for creating Cases.
*/
public class CaseFactory {
/**
* Creates a Case.
* @return the Case created.
*/
public static BICase createCase() {
BICase newCase = new BICase();
newCase.setCaseID(generateCaseID());
newCase.setStatus("new");
return newCase;
}
/**
* Creates a Case based on case content and with a specified case ID.
* @param a_CaseID ID of the case to be created.
* @param a_CML the case content used.
* @return the Case created.
*/
public static BICase createCase(String a_CaseID, String a_CML) {
BICase createCase = new BICase();
createCase.setCaseID(a_CaseID);
createCase = NodeFactory.insertHeaderAndTaskNode(createCase, a_CML);
return createCase;
}
/**
* Creates a Case with a specified case ID.
* @param a_CaseID ID of the case to be created.
* @return the Case created.
*/
public static BICase createCase(String a_CaseID) {
BICase createCase = new BICase();
createCase.setCaseID(a_CaseID);
return createCase;
}
/**
* Creates a Case and copies information of a given source Case into the newly
* created Case.
* @param a_SourceCase the source Case to be copied.
* @return the Case created.
*/
public static BICase createCase(BICase a_SourceCase) {
BICase newCase = createCase();
if (a_SourceCase == null) {
System.err.println("source case is null");
} else {
newCase.setNode(
NodeFactory.createNode(
newCase.getCaseID(),
a_SourceCase.getNode(NodeFactory.TASK, null)));
Node[] nodes = a_SourceCase.getModelNodeListArray();
for (int i = 0; nodes != null && i < nodes.length; i++)
newCase.setNode(
NodeFactory.createNode(newCase.getCaseID(), nodes[i]));
nodes = a_SourceCase.getOperatorNodeListArray();
for (int i = 0; nodes != null && i < nodes.length; i++)
newCase.setNode(
NodeFactory.createNode(newCase.getCaseID(), nodes[i]));
nodes = a_SourceCase.getDataNodeListArray();
for (int i = 0; nodes != null && i < nodes.length; i++)
newCase.setNode(
NodeFactory.createNode(newCase.getCaseID(), nodes[i]));
Vector connections = a_SourceCase.getProcess().getConnectionList();
NodeConnection con = null;
for (int i = 0; i < connections.size(); i++) {
con = (NodeConnection) connections.elementAt(i);
newCase.insertConnection(
con.getHeadNodeID(),
con.getTailNodeID());
}
newCase.setAccessRight(a_SourceCase.getAccessRight());
newCase.setVersion(a_SourceCase.getVersion());
newCase.setCaseID(generateCaseID());
newCase.setStatus("new");
}
return newCase;
}
/**
* Generates a unique ID for a Case.
* @return the ID.
* @throws AppException
*/
public static String generateCaseID(){
BIMLDAO aBIMLDAO;
try {
aBIMLDAO = (BIMLDAO) DAOFactory.getDAO("BIML", Constants.BIML_DAO_TYPE);
return aBIMLDAO.getNextId();
} catch (AppException e) {
// TODO Auto-generated catch block
e.printStackTrace();
DecimalFormat aDF = new DecimalFormat(Constants.BIML_ID_PATTERN);
return aDF.format(Calendar.getInstance().getTimeInMillis());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -