?? bpel2pi.java
字號(hào):
/*
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
author: Yuan yongfu lijin liyong lib 511,the College of Mathematics and Computer Science,HuNan Normal University,China
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
*/
package edu.hunnu.webjetchecker.convert;
import java.io.File;
import java.util.ArrayList;
import java.util.StringTokenizer;
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import edu.hunnu.webjetchecker.*;
import edu.hunnu.webjetchecker.convert_interface.Bpel2Pi_inter;
/**
* @author Ly 2006.03.23
*
* TODO To change the template for this generated type comment go to Window -
* Preferences - Java - Code Style - Code Templates
*/
// 這是在原來的基礎(chǔ)上,針對宋燕提出的具體情況做了以下更改:
// 1. 把linkSource變成了二元組輸出和接受名字
// 2. 將所有的匹配結(jié)構(gòu)去除,影響的結(jié)構(gòu)主要是while , switch ;
// 3.
public class Bpel2Pi extends Bpel2PiTop implements Bpel2Pi_inter {
// idea: 將bpel文件結(jié)構(gòu)看作一棵樹,深度遍歷所有節(jié)點(diǎn),遞歸調(diào)用所有分支!
// 在一字符串傳遞祖先節(jié)點(diǎn)的信息,父與子之間的信息用 ;隔開,某個(gè)節(jié)點(diǎn)的前置喝后置條件用 & 隔開 。
public int sequenceTimes = 0; // 專門用于parseSequence中記錄它已經(jīng)被調(diào)用的次數(shù)
public int switchTimes = 0;
public int flowTimes = 0;
public int pickTimes = 0;
public int whileTimes = 0;
public int linkSourceTimes = 0;
public int linkTargetTimes = 0;
public int invokeTimes = 0;
public int receiveTimes = 0;
public int replyTimes = 0;
public int assignTimes = 0;
public int waitTimes = 0;
public int terminateTimes = 0;
public int emptyTimes = 0;
public int throwTimes = 0;
public int onAlarmTimes = 0;
public int onMessageTimes = 0;
public int caseTimes = 0;
public int otherwiseTimes = 0;
ArrayList array1 = new ArrayList();
ArrayList array2 = new ArrayList();
int listIndex = 0;
private String result = "";
private String agentHead = "";
private ArrayList listAction = new ArrayList();
int flag = 0;
String strAction = "";
ActivityMap activityMap = new ActivityMap(); // 全局對象
/**
*
*/
public Bpel2Pi() {
super();
this.result = "";
this.agentHead = "";
this.listAction = null;
// TODO Auto-generated constructor stub
}
public Bpel2Pi(File file) {
Bpel bpel = new Bpel(file);
this.convert(bpel);
if (flag == 1) {
listAction.add("t");
}
}
public ArrayList getListAction() {
return this.listAction;
}
public String getResult() {
return this.result;
}
public String getAgentHead() {
return this.agentHead;
}
/*
* (non-Javadoc)
*
* @see edu.hunnu.webjetchecker.bpel2pi.Bpel2Pi#convert(edu.hunnu.webjetchecker.Bpel)
*/
public Agent convert(Bpel bpel) {
// TODO Auto-generated method stub
Element root = bpel.getRoot();
if (root != null) {
Agent agent = new Agent();
agent = this.ParseBPEL(root);
String newString = "P(" + agent.getFreeName() + ")";
agentHead = newString;
result = modifyString(agent.toString(), newString);
} else {
System.out.println("This file is not a BPEL");
}
return null;
}
public Agent ParseBPEL(Node root) {
String engineName = "Engine"; // 設(shè)置一個(gè)初始的進(jìn)程agent
Agent agent = new Agent();
agent.setSelfAgentName(engineName);
for (Node child = root.getFirstChild(); child != null; child = child
.getNextSibling()) {
int activityType = activityMap.getType(child.getNodeName()
.toLowerCase());
if (activityType != 99) {
String afterInfo = "";
agent = ParseNode(child, agent, afterInfo);
}
}
return agent;
}
public Agent ParseActivity(Node node, Agent agent, String afterInfo) {
for (Node child = node.getFirstChild(); child != null; child = child
.getNextSibling()) {
int activityType = activityMap.getType(child.getNodeName()
.toLowerCase());
if (activityType != 99) {
agent = ParseNode(child, agent, afterInfo);
}
}
return agent;
}
public Agent GenerateNewAgent() {
Agent agent = new Agent();
int agentNum = 1;
String agentName = "Engine" + String.valueOf(agentNum);
String nextAgentName = "Engine" + String.valueOf(agentNum + 1);
agent.setSelfAgentName(agentName);
agent.setToAgentName(nextAgentName);
agentNum++;
return agent;
}
public Agent ParseNode(Node node, Agent agent, String afterInfo) {
int activityType = activityMap.getType(node.getNodeName());
switch (activityType) {
case 0:
agent = ParseSequence(node, agent, afterInfo);
// str += strSequence;
break;
case 1:
agent = ParseSwitch(node, agent, afterInfo);
// str += strSwitch;
break;
case 2:
agent = ParsePick(node, agent, afterInfo);
// str += strPick;
break;
case 3:
agent = ParseWhile(node, agent, afterInfo);
// str += strWhile;
break;
case 4:
agent = ParseInvoke(node, agent, afterInfo);
// str += strInvoke;
break;
case 5:
agent = ParseFlow(node, agent, afterInfo);
// str += strFlow;
break;
case 6:
agent = ParseReceive(node, agent, afterInfo);
// str += strReceive;
break;
case 7:
agent = ParseReply(node, agent, afterInfo);
// str += strReply;
break;
case 8:
agent = ParseAssign(node, agent, afterInfo);
// str += strAssign;
break;
case 12:
// agent = ParsePartnerLinks(node,agent,afterInfo);
break;
case 13:
// agent = ParseVariables(node,agent,afterInfo) ;
break;
case 14:
// agent = ParseFaultHandlers(node,agent,afterInfo);
break;
default:
break;
}
return agent;
}
public Agent ParseSequence(Node node, Agent agent, String afterInfo) {
// 用并發(fā)表示順序
// 順序在并發(fā)中通過通道的傳值來表示通道和傳的值用a和b加序號(hào)來表示
sequenceTimes += 1;
String str = "";
String sourceStr = "";
String targetStr = "";
for (Node child = node.getFirstChild(); child != null; child = child
.getNextSibling()) {
if (child.getNodeName().equalsIgnoreCase("source")) {
sourceStr += ParseLinkSource(child, agent);
}
if (child.getNodeName().equalsIgnoreCase("target")) {
targetStr += ParseLinkTarget(child, agent);
}
}
int childsCount = getValidChildsNum(node);
String inputActionName = "";
String outputActionName = "";
String inputValue = "";
String outputValue = "";
String seTimeStr = String.valueOf(sequenceTimes);
String input[] = new String[childsCount + 1];// 從2---------childsCount存儲(chǔ),索取的時(shí)候從2開始!
input[0] = "";
input[1] = "";
String output[] = new String[childsCount + 1]; // 從1---------childsCount-1存儲(chǔ)
output[0] = "";
output[childsCount] = "";
for (int i = 1; i < childsCount; i++) {// 對n個(gè)孩子構(gòu)造n-1個(gè)前置和后置條件對!
inputActionName = "se" + seTimeStr + String.valueOf(i);
inputValue = "ise" + seTimeStr + String.valueOf(i);
outputActionName = "'se" + seTimeStr + String.valueOf(i);
outputValue = "ose" + seTimeStr + String.valueOf(i);
agent.setBoundName(outputValue);
agent.setBoundName(inputValue);
agent.setBoundName(inputActionName);
array1.add(listIndex, new String(inputActionName));
array2.add(listIndex, new String(""));
listIndex++;
input[i + 1] = inputActionName + "(" + inputValue + ")";
output[i] = outputActionName + "<" + outputValue + ">";
}
int childsNum = 0;
for (Node child = node.getFirstChild(); child != null; child = child
.getNextSibling()) {
int childType = activityMap.getType(child.getNodeName()
.toLowerCase());
if (childType != 99 && childType != 11) {
childsNum++; // 記錄該節(jié)點(diǎn)中所擁有的孩子的數(shù)目
String rearName = output[childsNum];
Agent tempAgent = new Agent(); // 對子節(jié)點(diǎn)生成一個(gè)新進(jìn)程對象,保存該節(jié)點(diǎn)及其子孫的所有信息!
tempAgent = ParseNode(child, tempAgent, rearName); // 對每個(gè)子節(jié)點(diǎn)生成一個(gè)進(jìn)程對象,進(jìn)行分析
// 把子進(jìn)程的自由名和邦定名傳入父進(jìn)程
agent.setFreeName((ArrayList) tempAgent.freeName);
agent.setBoundName((ArrayList) tempAgent.boundName); // 這里會(huì)不會(huì)重復(fù)設(shè)置名字
String tempStr = tempAgent.getAction(); // 對子節(jié)點(diǎn)的分析結(jié)果
// 前置條件的處理!
// 下面一段對那些曾經(jīng)分裂引起前置條件變化的替換進(jìn)行處理!將array1中已經(jīng)替換的前置名用分裂后的名字替換!
String previousName = input[childsNum];
StringTokenizer tempStringTokenizer = new StringTokenizer(
previousName, "&");
int tokenCount = tempStringTokenizer.countTokens();
String transform = "";
for (int j = 1; j <= tokenCount; j++) {
String strObject = tempStringTokenizer.nextToken();// 得到前置條件的一個(gè)名字
StringTokenizer tempStringTokenizer1 = new StringTokenizer(
strObject, "(");// 獲得前置條件某個(gè)名字的通道名
String chunnelName = tempStringTokenizer1.nextToken();
int location = array1.indexOf(chunnelName);
String tempObject = "";
if (location > -1)
tempObject = (String) array2.get(location);
if (!tempObject.equals("")) // 原來的名字已經(jīng)由于子節(jié)點(diǎn)的分裂發(fā)生了變化
strObject = tempObject;
if (j < tokenCount)
transform += strObject + ".";
else
transform += strObject;
}
tempStr = redeem(transform) + tempStr;// 這里其實(shí)就是加上了前置條件
if (!isLastValidNode(child))
str += tempStr + "|";
else
str += tempStr;
} // end if
} // end for
if (!afterInfo.equals("") || !sourceStr.equals("")) { // 在sequence
// 中的出站鏈接和從父節(jié)點(diǎn)中傳遞的afterInfo可以看作一樣的內(nèi)容處理!
afterInfo = blackBox(afterInfo); // 將用"&"相連的名字變成用"."相連!
String tempStr = redeem(afterInfo) + reduce(sourceStr) + ".0";
str = modifyString(str, tempStr);
}
str = "(" + redeem(targetStr) + "(" + str + ")" + ")";
agent.setAction(str);
return agent;
}
public Agent ParseWhile(Node node, Agent agent, String afterInfo) {
// this method is according to the idea of SongYan
whileTimes++;
String str = "";
String sourceStr = "";
String targetStr = "";
for (Node child = node.getFirstChild(); child != null; child = child
.getNextSibling()) {
if (child.getNodeName().equalsIgnoreCase("source")) {
sourceStr += ParseLinkSource(child, agent);
}
if (child.getNodeName().equalsIgnoreCase("target")) {
targetStr += ParseLinkTarget(child, agent);
}
}
Agent tempAgent = new Agent();
tempAgent = ParseActivity(node, tempAgent, afterInfo);
agent.setFreeName(tempAgent.freeName);
agent.setBoundName(tempAgent.boundName);
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -