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

📄 bpel2pi.java

📁 这是我们参加06年全国开源软件的竞赛作品
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        }

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

        if (inputVariable != null && !inputVariableValue.equals("")) {
            strin = partnerLinkValue + "$" + portTypeValue + "$"
                    + operationValue + "$" + inputVariableValue + "("
                    + inputVariableValue + ")";
            strAction = partnerLinkValue + "$" + portTypeValue + "$"
                    + operationValue + "$" + inputVariableValue;
            listAction.add(strAction);
        }
        // strin =
        // partnerLinkValue+"$"+portTypeValue+"$"+operationValue+"$"+inputVariableValue+"("+inputVariableValue+")";
        else if (inputVariable == null && inputVariableValue.equals("")) {
            strin = partnerLinkValue + "$" + portTypeValue + "$"
                    + operationValue + "$";
            listAction.add(strin);
        }
        // strin = partnerLinkValue+"$"+portTypeValue+"$"+operationValue+"$";

        if (inputVariableValue != null)
            agent.setFreeName((String) inputVariableValue);

        if (outputVariable != null && !outputVariable.equals("")) {
            strout = "'" + partnerLinkValue + "$" + portTypeValue + "$"
                    + operationValue + "$" + outputVariableValue + "<"
                    + outputVariableValue + ">";
            strAction = "'" + partnerLinkValue + "$" + portTypeValue + "$"
                    + operationValue + "$" + outputVariableValue;
            listAction.add(strAction);
        }
        // strout =
        // "'"+partnerLinkValue+"$"+portTypeValue+"$"+operationValue+"$"+outputVariableValue+"<"+outputVariableValue+">";
        else if (outputVariable == null && outputVariableValue.equals("")) {
            strout = "'" + partnerLinkValue + "$" + portTypeValue + "$"
                    + operationValue + "$";
            listAction.add(strout);
        }
        // strout =
        // "'"+partnerLinkValue+"$"+portTypeValue+"$"+operationValue+"$" ;

        agent.setFreeName(partnerLinkValue + "$" + portTypeValue + "$"
                + operationValue + "$" + inputVariableValue);// 添加自由名和输入名!
        agent.setFreeName(partnerLinkValue + "$" + portTypeValue + "$"
                + operationValue + "$" + outputVariableValue);
        agent.setFreeName(outputVariableValue);
        agent.setBoundName(inputVariableValue);

        if (!strin.equals("") && !strout.equals(""))
            str = strin + "." + strout;
        else if (!strin.equals("") && strout.equals(""))
            str = strin;
        else if (strin.equals("") && !strout.equals(""))
            str = strout;
        if (!afterInfo.equals("")) {

        }

        String rearName = blackBox(afterInfo);
        str = redeem(targetStr) + reduce(str);
        if (!sourceStr.equals(""))
            str += "." + reduce(sourceStr);
        if (!rearName.equals(""))
            str += "." + reduce(rearName) + ".0";
        else
            str += ".0";

        str = "(" + str + ")";
        agent.setAction(str);

        return agent;
    }

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

        receiveTimes++;
        String str = "";
        String partnerLinkValue = "";
        String portTypeValueTemp = "";
        String portTypeValue = "";
        String operationValue = "";
        String variableValue = "";

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

        str = partnerLinkValue + "$" + portTypeValue + "$" + operationValue
                + "$" + variableValue;
        listAction.add(str);
        str += "(" + variableValue + ")";

        agent.setFreeName(partnerLinkValue + "$" + portTypeValue + "$"
                + operationValue + "$" + variableValue);
        agent.setFreeName(variableValue); // 设置自由名和约束名

        String rearName = "";
        rearName = blackBox(afterInfo);

        str = redeem(targetStr) + reduce(str);
        if (!sourceStr.equals(""))
            str += "." + reduce(sourceStr);
        if (!rearName.equals(""))
            str += "." + reduce(rearName) + ".0";
        else
            str += ".0";

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

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

        replyTimes++;
        String str = "";
        String partnerLinkValue = "";
        String portTypeValueTemp = "";
        String portTypeValue = "";
        String operationValue = "";
        String variableValue = "";

        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().toLowerCase();
        }
        if (portTypeValueTemp != null && !portTypeValueTemp.trim().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().toLowerCase();
        }
        String freeName = null;
        if (!partnerLinkValue.equals("") && !portTypeValue.equals("")
                && !operationValue.equals("") && !variableValue.equals("")) {
            freeName = partnerLinkValue + "$" + portTypeValue + "$"
                    + operationValue + "$" + variableValue;
            agent.setFreeName(freeName);

            str = "'" + partnerLinkValue + "$" + portTypeValue + "$"
                    + operationValue + "$" + variableValue;
            listAction.add(str);
            str += "<" + variableValue + ">";

            agent.setFreeName(partnerLinkValue + "$" + portTypeValue + "$"
                    + operationValue + "$" + variableValue);
            agent.setFreeName(variableValue);
        }

        String rearName = blackBox(afterInfo);

        str = redeem(targetStr) + reduce(str);

        if (!sourceStr.equals(""))
            str += "." + reduce(sourceStr);
        if (!rearName.equals(""))
            str += "." + reduce(rearName) + ".0";
        else
            str += ".0";

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

    public Agent ParseAssign(Node node, Agent agent, String afterInfo) {
        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 nodeName = "";
        nodeName = node.getNodeName();

        if (nodeName.equals("assign"))
            assignTimes++;

        if (nodeName.equals("throw"))
            throwTimes++;

        if (nodeName.equals("terminate"))
            terminateTimes++;

        if (nodeName.equals("wait"))
            waitTimes++;

        if (nodeName.equals("empty"))
            emptyTimes++;

        String rearName = blackBox(afterInfo);
        str = redeem(targetStr);
        if (!sourceStr.equals(""))
            str += "t." + reduce(sourceStr);
        else
            str += "t";
        if (!rearName.equals(""))
            str += "." + reduce(rearName) + ".0";
        else
            str += ".0";
        listAction.add("t");
        str = "(" + str + ")";
        agent.setAction(str);
        return agent;
    }

    public Agent ParseWait(Node node, Agent agent, String afterInfo) {
        String str = "";
        String strWait = ""; // 用来存储wait节点的分析内容!

        str += "(*start_wait*)";
        str += strWait;
        str += "(*";
        Agent tempAgent = new Agent();
        tempAgent = ParseForRemark(node, tempAgent, afterInfo);
        str += tempAgent.getAction();
        str += "*)";
        str += "(*end_wait*)";
        return agent;
    }

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

        String str = "";
        for (Node child = node.getFirstChild(); child != null; child = child
                .getNextSibling()) {
            if (child.getNodeType() == Node.ELEMENT_NODE) {
                str += "<" + child.getNodeName();
                NamedNodeMap childAttr = child.getAttributes();
                for (int i = 0; i < childAttr.getLength(); i++) {
                    Node attr = childAttr.item(i);
                    str += " " + attr.getNodeName() + "=";
                    str += "\"" + attr.getNodeValue() + "\"";
                }
                str += ">";
                Agent tempAgent = new Agent();
                tempAgent = ParseForRemark(child, tempAgent, afterInfo);
                str += tempAgent.getAction();
                str += "</" + child.getNodeName() + ">";
            }
        }

        agent.setAction(str);
        return agent;

    }

    public String ParseLinkSource(Node node, Agent agent) {
        // 这里对链接的处理还要再分析!
        linkSourceTimes++;
        String linkSourceStr = String.valueOf(linkSourceTimes);
        String str = "";
        NamedNodeMap attrs = node.getAttributes();
        Node linkNameNode = null;
        int attrsLength = attrs.getLength();
        for (int i = 0; i < attrsLength; i++)
            if (attrs.item(i).getNodeName().equalsIgnoreCase("linkname")) {
                linkNameNode = attrs.item(i);
                break;
            }
        String linkName = null;
        if (linkNameNode != null)
            linkName = ((Attr) linkNameNode).getValue().trim().toLowerCase();
        String linkValue = "links" + linkSourceStr;

        String tempLinkName = "als" + linkSourceStr;
        str = "'" + tempLinkName + "<" + linkName + "," + linkValue + ">.0 | ";
        str += tempLinkName + "(" + linkName + "," + linkValue + ")." + "'"
                + linkName + "<" + linkValue + ">" + ".";

        agent.setBoundName(linkValue);
        agent.setBoundName(linkName + "&" + tempLinkName);

        return str;
    }

    public String ParseLinkTarget(Node node, Agent agent) {
        // t.[z=true]还没有加上去!
        linkTargetTimes++;
        String str = "";
        NamedNodeMap attrs = node.getAttributes();
        Node linkNameNode = null;
        int attrsLength = attrs.getLength();
        for (int i = 0; i < attrsLength; i++)
            if (attrs.item(i).getNodeName().equalsIgnoreCase("linkname")) {
                linkNameNode = attrs.item(i);
                break;
            }
        String linkName = null;
        if (linkNameNode != null)
            linkName = ((Attr) linkNameNode).getValue().trim().toLowerCase();
        String linkValue = "linkt" + String.valueOf(linkTargetTimes);
        str = linkName + "(" + linkValue + ")" + ".";

        agent.setBoundName(linkValue + "&" + linkName);
        return str;
    }

}

⌨️ 快捷键说明

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