📄 bpel2pi.java
字号:
/*
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
*/
// 这是在原来的基础上,针对宋燕提出的具体情况做了以下更改:
// 1. 把linkSource变成了二元组输出和接受名字
// 2. 将所有的匹配结构去除,影响的结构主要是while , switch ;
// 3.
public class Bpel2Pi extends Bpel2PiTop implements Bpel2Pi_inter {
// idea: 将bpel文件结构看作一棵树,深度遍历所有节点,递归调用所有分支!
// 在一字符串传递祖先节点的信息,父与子之间的信息用 ;隔开,某个节点的前置喝后置条件用 & 隔开 。
public int sequenceTimes = 0; // 专门用于parseSequence中记录它已经被调用的次数
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"; // 设置一个初始的进程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) {
// 用并发表示顺序
// 顺序在并发中通过通道的传值来表示通道和传的值用a和b加序号来表示
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存储,索取的时候从2开始!
input[0] = "";
input[1] = "";
String output[] = new String[childsCount + 1]; // 从1---------childsCount-1存储
output[0] = "";
output[childsCount] = "";
for (int i = 1; i < childsCount; i++) {// 对n个孩子构造n-1个前置和后置条件对!
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++; // 记录该节点中所拥有的孩子的数目
String rearName = output[childsNum];
Agent tempAgent = new Agent(); // 对子节点生成一个新进程对象,保存该节点及其子孙的所有信息!
tempAgent = ParseNode(child, tempAgent, rearName); // 对每个子节点生成一个进程对象,进行分析
// 把子进程的自由名和邦定名传入父进程
agent.setFreeName((ArrayList) tempAgent.freeName);
agent.setBoundName((ArrayList) tempAgent.boundName); // 这里会不会重复设置名字
String tempStr = tempAgent.getAction(); // 对子节点的分析结果
// 前置条件的处理!
// 下面一段对那些曾经分裂引起前置条件变化的替换进行处理!将array1中已经替换的前置名用分裂后的名字替换!
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();// 得到前置条件的一个名字
StringTokenizer tempStringTokenizer1 = new StringTokenizer(
strObject, "(");// 获得前置条件某个名字的通道名
String chunnelName = tempStringTokenizer1.nextToken();
int location = array1.indexOf(chunnelName);
String tempObject = "";
if (location > -1)
tempObject = (String) array2.get(location);
if (!tempObject.equals("")) // 原来的名字已经由于子节点的分裂发生了变化
strObject = tempObject;
if (j < tokenCount)
transform += strObject + ".";
else
transform += strObject;
}
tempStr = redeem(transform) + tempStr;// 这里其实就是加上了前置条件
if (!isLastValidNode(child))
str += tempStr + "|";
else
str += tempStr;
} // end if
} // end for
if (!afterInfo.equals("") || !sourceStr.equals("")) { // 在sequence
// 中的出站链接和从父节点中传递的afterInfo可以看作一样的内容处理!
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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -