bpel2remarkpi.java

来自「这是我们参加06年全国开源软件的竞赛作品」· Java 代码 · 共 1,272 行 · 第 1/4 页

JAVA
1,272
字号
        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" ;
            String tempStr = redeem(afterInfo);
            if (!sourceStr.equals(""))
                tempStr += reduce(sourceStr) + ".0";
            else
                tempStr += "0";
            str = modifyString(str, tempStr);
        }
        str = "(*start_sequence#" + sequenceStr + "#*)" + "("
                + redeem(targetStr) + "(" + str + ")" + ")" + "(*end_sequence#"
                + sequenceStr + "#*)";
        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 whileStr = String.valueOf(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);

        String tempStr = tempAgent.getAction();
        tempStr = "t." + tempStr;
        str += tempStr + "+ 0";

        str = "(" + reduce(targetStr) + "(" + "(*start_while#" + whileStr
                + "#*)" + str + "(*end_while#" + whileStr + "#*)" + ")" + ")";
        agent.setAction(str);
        return agent;
    }

    public Agent ParsePick(Node node, Agent agent, String afterInfo) {
        pickTimes++;
        String str = "";
        String partnerLinkValue = "";
        String portTypeValueTemp = "";
        String portTypeValue = "";
        String operationValue = "";
        String variableValue = "";
        int i = 0;

        String pickStr = String.valueOf(pickTimes);
        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);

            }
        }

        for (Node child = node.getFirstChild(); child != null; child = child
                .getNextSibling()) {
            if (child.getNodeName().equalsIgnoreCase("onmessage")) {
                onMessageTimes++;
                NamedNodeMap attrs = node.getAttributes();
                Node partnerLink = getNamedItemIgnoreCase(attrs, "partnerLink");
                if (partnerLink != null) {
                    partnerLinkValue = ((Attr) partnerLink).getValue().trim()
                            .toLowerCase();
                }

                Node portType = getNamedItemIgnoreCase(attrs, "portType");
                if (portType != null) {
                    portTypeValueTemp = ((Attr) portType).getValue().trim()
                            .toLowerCase();
                }
                if (portTypeValueTemp != null && !portTypeValueTemp.equals("")) {
                    int index = portTypeValueTemp.indexOf(":");
                    portTypeValue = portTypeValueTemp.substring(index + 1);
                }

                Node operation = getNamedItemIgnoreCase(attrs, "operation");
                if (operation != null) {
                    operationValue = ((Attr) operation).getValue().trim()
                            .toLowerCase();
                }

                Node variable = getNamedItemIgnoreCase(attrs, "variable");
                if (variable != null) {
                    variableValue = ((Attr) variable).getValue().trim()
                            .toLowerCase();
                }
                String onMessageStr = String.valueOf(onMessageTimes);
                if (i == 0) {
                    str += "(*start_onMessage#" + onMessageStr + "#*)"
                            + partnerLinkValue + "$" + portTypeValue + "$"
                            + operationValue + "$" + variableValue + "("
                            + variableValue + ")" + "(*end_onMessage#"
                            + onMessageStr + "#*)" + ".";
                } else {
                    str += "+" + "(*start_onMessage#" + onMessageStr + "#*)"
                            + partnerLinkValue + "$" + portTypeValue + "$"
                            + operationValue + "$" + variableValue + "("
                            + variableValue + ")" + "(*end_onMessage#"
                            + onMessageStr + "#*)" + ".";
                }

                agent.setFreeName(partnerLinkValue + "$" + portTypeValue + "$"
                        + operationValue + "$" + variableValue);
                agent.setBoundName(variableValue); // 添加自由名和限制名

                Agent tempAgent = new Agent();
                String tempAfterInfo = afterInfo;
                if (!sourceStr.equals("")) {
                    StringTokenizer stringTokenizer = new StringTokenizer(
                            sourceStr, ".");
                    int tokenCount = stringTokenizer.countTokens();
                    for (int k = 0; k < tokenCount; k++) {
                        String temp = stringTokenizer.nextToken();
                        tempAfterInfo += "&" + temp;
                    }
                }
                tempAgent = ParseActivity(child, tempAgent, tempAfterInfo);

                agent.setFreeName(tempAgent.freeName);
                agent.setBoundName(tempAgent.boundName);

                String tempStr = tempAgent.getAction();
                str = redeem(str);
                str += tempStr;
                i++;
            }

            if (child.getNodeName().equalsIgnoreCase("onAlarm")) {
                str += "+t.";
                onAlarmTimes++;
                Agent tempAgent = new Agent();
                if (!sourceStr.equals("")) {
                    StringTokenizer stringTokenizer = new StringTokenizer(
                            sourceStr, ".");
                    int tokenCount = stringTokenizer.countTokens();
                    for (int k = 0; k < tokenCount; k++) {
                        String temp = stringTokenizer.nextToken();
                        afterInfo += "&" + temp;
                    }
                }
                tempAgent = ParseActivity(child, tempAgent, afterInfo);
                agent.setFreeName(tempAgent.freeName);
                agent.setBoundName(tempAgent.boundName);

                String tempStr = tempAgent.getAction();
                str = redeem(str);
                String onAlarmStr = String.valueOf(onAlarmTimes);
                str += "(*start_onAlarm#" + onAlarmStr + "#*)" + tempStr
                        + "(*end_onAlarm#" + onAlarmStr + "#*)";

            }
        }

        if (!targetStr.equals(""))
            str += redeem(targetStr) + str;

        str = "(*start_pick#" + pickStr + "#*)" + "(" + redeem(targetStr) + "("
                + str + ")" + ")" + "(*end_pick#" + pickStr + "#*)";
        agent.setAction(str);
        return agent;
    }

    public Agent ParseSwitch(Node node, Agent agent, String afterInfo) {

        switchTimes++;
        String switchStr = String.valueOf(switchTimes);

        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);

            }
        }

        String str = "";
        int childsNum = getContrutorChildsNum(node);
        int i = 0;
        int caseTimes = 0;

        for (Node child = node.getFirstChild(); child != null; child = child
                .getNextSibling()) {
            String activity = "";
            if (child.getNodeName().equalsIgnoreCase("case")
                    || child.getNodeName().equalsIgnoreCase("otherwise")) {

                i++;
                String tempAfterInfo = afterInfo;
                Agent tempAgent = new Agent();
                if (!sourceStr.equals("")) {
                    StringTokenizer stringTokenizer = new StringTokenizer(
                            sourceStr, ".");
                    int tokenCount = stringTokenizer.countTokens();
                    for (int k = 0; k < tokenCount; k++) {
                        String temp = stringTokenizer.nextToken();
                        tempAfterInfo += "&" + temp;
                    }
                }

                tempAgent = ParseActivity(child, tempAgent, tempAfterInfo);
                agent.setFreeName(tempAgent.freeName);
                agent.setBoundName(tempAgent.boundName);
                activity = tempAgent.getAction();

                String conditionRemark = "";

                if (child.getNodeName().equalsIgnoreCase("case")) {
                    caseTimes++;
                    String caseStr = String.valueOf(caseTimes);
                    NamedNodeMap attrs = child.getAttributes();
                    Node linkNameNode = getNamedItemIgnoreCase(attrs,
                            "condition");
                    String linkName = ((Attr) linkNameNode).getValue().trim()
                            .toLowerCase();
                    conditionRemark = "(*condition = " + "\"" + linkName + "\""
                            + "*)";
                    if (i < childsNum)
                        str += "(*start_case#" + caseStr + "#*)"
                                + conditionRemark + activity + "(*end_case#"
                                + caseStr + "#*)" + " + ";
                    else
                        str += "(*start_case#" + caseStr + "#*)"
                                + conditionRemark + activity + "(*end_case#"
                                + caseStr + "#*)";
                } else {
                    otherwiseTimes++;
                    String otherwiseStr = String.valueOf(otherwiseTimes);
                    if (i < childsNum)
                        str += "(*start_otherwise#" + otherwiseStr + "#*)"
                                + conditionRemark + activity
                                + "(*end_otherwise#" + otherwiseStr + "#*)"
                                + " + ";
                    else
                        str += "(*start_otherwise#" + otherwiseStr + "#*)"
                                + conditionRemark + activity
                                + "(*end_otherwise#" + otherwiseStr + "#*)";
                }

            }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?