?? bpel2remarkpi.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
*
* 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 Bpel2RemarkPi 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;
private File file;
// 建立兩個字符串數組!一個存儲全部的后置名字的通道名(不含"'"),第二個字符串數組全部置為空!如果后面的子節點(flow)對某個后置名進行了分裂,則
// 在對應的第二個數組中將分裂對應的輸入動作置入。
// 在活動之前加前置條件時(sequence),先將前置條件的每個名字的通道名在第一數組中查找,得到index,
// 再對第二個數組的對應位置查找,如果不為空,則表示該名字曾經分裂,則用該內容替換前置條件!
ArrayList array1 = new ArrayList();
ArrayList array2 = new ArrayList();
int listIndex = 0;
private String result = "";
private String agentHead = "";
// 本程序的link的處理也是盡量在某個結點處理,不能把它傳遞到其子節點。對于flow結構,如<flow>P1,P2,P3</flow>則對每個進程
// 添加一個后置條件'ai<xi>,然后再增加一個新的并發進程P4!P4 = a1(y1).a2(y2).a3(y3).'link<value>;
// public int controlRearCondition = 0 ; //這個條件用于對生成的字符串進行替換操作
/*
* 如<sequence> <flow1> <flow2> P1 <flow> </flow> P2 </sequence> 顯然
* sequence對flow1有個后置輸出,同時對P2有個前置輸入。經過flow2時,后置輸出要再進行分裂
* 為使分裂后的與P2的前置輸入保持,則應對前置輸入進行必要的替換! 而且這個替換要等到所有的節點的分析都結束后!
*/
/*
* 本程序的兩個關鍵點: 1.順序算子的設置, 2,linkSource 和 linkTarget的表示! 注意這兩個點的相同與區別!
*/
ActivityMap activityMap = new ActivityMap(); // 全局對象
/**
*
*/
public Bpel2RemarkPi() {
super();
// TODO Auto-generated constructor stub
}
public Bpel2RemarkPi(File file) {
this.file = file;
Bpel bpel = new Bpel(this.file);
this.convert(bpel);
}
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 = "";
String sequenceStr = String.valueOf(sequenceTimes);
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個前置和后置條件對!
// 用來構造sequence中的所有兒子節點中要用到的并發算子
// 并發算子的actionName構造采用這種形式:節點的首字母 + 已分析的次數 + 該孩子節點隸屬的位置
// -----保證該名字的唯一性
// 輸出名 :" o " + "se" + + 已分析的次數 + 該孩子節點隸屬的位置
// 輸入名 :" i " + "se" + + 已分析的次數 + 該孩子節點隸屬的位置
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.setFreeName(inputActionName+"&"+outputValue);
// agent.setBoundName(inputValue);
// 將用于順序的算子的通道名改為限制名! update by ly ------13.03.06
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;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -