⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bpel2pi.java

📁 这是我们参加06年全国开源软件的竞赛作品
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        String tempStr = tempAgent.getAction();
        tempStr = "t." + tempStr;
        listAction.add("t");
        str += tempStr + "+ 0";

        str = "(" + reduce(targetStr) + "(" + str + ")" + ")";
        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 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();
                }

                if (i == 0) {
                    str += partnerLinkValue + "$" + portTypeValue + "$"
                            + operationValue + "$" + variableValue + "("
                            + variableValue + ")" + ".";
                } else {
                    str += "+" + partnerLinkValue + "$" + portTypeValue + "$"
                            + operationValue + "$" + variableValue + "("
                            + variableValue + ")" + ".";
                }

                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.";
                listAction.add("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);

                str += tempStr;

            }
        }

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

        str = "(" + redeem(targetStr) + "(" + str + ")" + ")";
        agent.setAction(str);
        return agent;
    }

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

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

                    if (i < childsNum)
                        str += activity + "+";
                    else
                        str += activity;
                } else {
                    otherwiseTimes++;
                    if (i < childsNum)
                        str += activity + "+";
                    else
                        str += activity;
                }

            }

        }

        str = "t." + "(" + redeem(targetStr) + "(" + str + ")" + ")";
        listAction.add("t");
        agent.setAction(str);
        return agent;
    }

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

        flowTimes++;
        int childsNum = getValidChildsNum(node);
        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);

            }
        }
        String sourceRear[] = new String[childsNum]; // ,从0----childsNum-1开始存储!
        String tempSourceTotal = "";
        if (!sourceStr.equals("")) { // 如果这不为空,则临时构造多个后置名,分别添加到该节点的每个子节点,然后再并发并发一个添加的进程!
            String linkSouStr = String.valueOf(linkSourceTimes);
            for (int i = 0; i < childsNum; i++) {
                String inputAct = "fl_s" + linkSouStr + String.valueOf(i);
                String inputValue = "ifl_s" + linkSouStr + String.valueOf(i);
                String outputValue = "ofl_s" + linkSouStr + String.valueOf(i);
                String outputAct = "'" + inputAct;
                String outputName = outputAct + "<" + outputValue + ">";
                sourceRear[i] = outputName;
                tempSourceTotal += inputAct + "(" + inputValue + ")" + ".";
                agent.setBoundName(outputValue);
                agent.setBoundName(inputAct + "&" + inputValue);
            }
            tempSourceTotal = reduce(tempSourceTotal);
        }

        int tokenCount = 0;
        StringTokenizer stringTokenizer = new StringTokenizer(afterInfo, "&");
        tokenCount = stringTokenizer.countTokens();

        String array[][] = new String[tokenCount][childsNum]; // 每行储存一个后置名字分裂的名字!
        for (int i = 0; i < tokenCount; i++) { // 做两层嵌套循环,对每个afterName的分量做分裂!
            String token = stringTokenizer.nextToken();
            StringTokenizer stringTokenizer1 = new StringTokenizer(token, "<");
            String outAct = stringTokenizer1.nextToken();
            String inAct = "";
            if (outAct.charAt(0) != '\'')
                System.out.println("in__flow: Name has error!");
            else
                inAct = outAct.substring(1);
            String tempNames = "";
            for (int j = 0; j < childsNum; j++) {
                String tempOutputAction = outAct + "$" + String.valueOf(i)
                        + String.valueOf(j);
                String tempOutputValue = "ofl" + "$" + String.valueOf(i)
                        + String.valueOf(j);
                String tempInputAction = inAct + "$" + String.valueOf(i)
                        + String.valueOf(j);
                String tempInputValue = "ifl" + "$" + String.valueOf(i)
                        + String.valueOf(j);
                agent.setBoundName(tempOutputValue);
                agent.setBoundName(tempInputAction + "&" + tempInputValue);
                array[i][j] = tempOutputAction + "<" + tempOutputValue + ">";
                array1.add(listIndex, new String(tempInputAction));
                array2.add(listIndex, new String(""));
                listIndex++;
                tempNames += tempInputAction + "(" + tempInputValue + ")" + ".";
            }
            int location = array1.indexOf((String) inAct); // 对分裂的名字进行记录,方便查找和替换!对应sequence
            // 活动中的前置条件的处理!
            if (location > -1)
                array2.add(location, (String) (reduce(tempNames)));
        }
        int j = 0; // 记录当前分析的是第几个孩子!从0开始!
        for (Node child = node.getFirstChild(); child != null; child = child
                .getNextSibling()) {
            int childType = activityMap.getType(child.getNodeName()
                    .toLowerCase());
            if (childType != 99 && childType != 11) { // 注意下面结构的逻辑关系!

                String tempAfterInfo = "";
                if (tokenCount > 0) {
                    for (int i = 0; i < tokenCount; i++)
                        tempAfterInfo += array[i][j] + ".";
                    tempAfterInfo = reduce(tempAfterInfo);
                }
                if (!sourceStr.equals("")) { // 将由于linkSource构造的临时后置名字加入到afterInfo中!
                    String addAfterInfo = sourceRear[j];
                    tempAfterInfo += "&" + addAfterInfo;
                }
                Agent tempAgent = new Agent();
                tempAgent = ParseNode(child, tempAgent, tempAfterInfo);

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

                String tempStr = tempAgent.getAction();
                if (!isLastValidNode(child))
                    str += tempStr + "|";
                else
                    str += tempStr;
                j++;
            }
        }

        if (!sourceStr.equals("") && !tempSourceTotal.equals("")) {
            str += "|" + redeem(tempSourceTotal) + reduce(sourceStr) + ".0";
        }

        str = "(" + redeem(targetStr) + "(" + str + ")" + ")";
        // 这里不用加sourcelink,因为它已经发散到各个子节点中去了!
        agent.setAction(str);
        return agent;
    }

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

        invokeTimes++;

        String strin = "";
        String strout = "";
        String str = "";
        String partnerLinkValue = "";
        String portTypeValueTemp = "";
        String portTypeValue = "";
        String operationValue = "";
        String inputVariableValue = "";
        String outputVariableValue = "";
        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);

            }
        }

        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 inputVariable = getNamedItemIgnoreCase(attrs, "inputVariable");
        if (inputVariable != null) {
            inputVariableValue = ((Attr) inputVariable).getValue().trim()
                    .toLowerCase();

⌨️ 快捷键说明

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