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

📄 remark_pi2bpel.java

📁 这是我们参加06年全国开源软件的竞赛作品
💻 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 javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.*;
import edu.hunnu.webjetchecker.ActivityMatch;
import edu.hunnu.webjetchecker.TransBpel;

public class Remark_Pi2Bpel {
    private Document doc = null;

    private File file = null;

    public Remark_Pi2Bpel(File file) {
        this.file = file;
    }

    public void pi2Bpel(String re, int flag) {
        String strPi = "";
        strPi = re;
        int index, nextIndex, order, endIndex, endOrder = 0;
        String tempStr, wholeName = null, endWholeName = null, endTempStr;
        Node headNode = null;
        Node endNode = null;
        int type;
        index = strPi.indexOf("(*start_");
        tempStr = strPi.substring(index + 8, index + 12);

        type = ActivityMatch.getType(tempStr);
        wholeName = ActivityMatch.compensate(type);

        index = strPi.indexOf("#");
        nextIndex = strPi.indexOf("#", index + 1);
        tempStr = strPi.substring(index + 1, nextIndex);

        order = Integer.parseInt(tempStr);
        if (wholeName != null && order != 0) {
            endIndex = strPi.lastIndexOf("(*start_");
            if (strPi.substring(endIndex + 8, endIndex + 14).equalsIgnoreCase(
                    "action")) {
                String aa = strPi;
                while (aa.substring(endIndex + 8, endIndex + 14)
                        .equalsIgnoreCase("action")
                        && endIndex > 0) {
                    // search the first activity which is the formulate the
                    // (*start_ ,except the (*start_action
                    aa = strPi.substring(0, endIndex);
                    endIndex = aa.lastIndexOf("(*start_");
                }
            }
            if (endIndex >= 0) {
                endTempStr = strPi.substring(endIndex + 8, endIndex + 12);// get
                                                                            // the
                                                                            // four
                                                                            // words
                                                                            // of
                                                                            // the
                                                                            // first
                                                                            // name
                type = ActivityMatch.getType(endTempStr);// get the type of
                                                            // name
                endWholeName = ActivityMatch.compensate(type);// compensate
                                                                // the name

                index = strPi.indexOf("#", endIndex);// get the location of
                                                        // the first occurence
                                                        // of #
                nextIndex = strPi.indexOf("#", index + 1);// get the location
                                                            // of the next
                                                            // occurence of #
                endTempStr = strPi.substring(index + 1, nextIndex);// obtain
                                                                    // the num
                                                                    // of
                                                                    // ""#num#
                endOrder = Integer.parseInt(endTempStr);

                if (wholeName.equals(endWholeName) && order == endOrder) {
                    System.out
                            .println("The head and tail of acitivity are the same!");
                }

                // obtain the document accroding to the file
                try {
                    DocumentBuilderFactory dbf = DocumentBuilderFactory
                            .newInstance();
                    DocumentBuilder db = dbf.newDocumentBuilder();
                    doc = db.parse(file);
                } catch (javax.xml.parsers.ParserConfigurationException pce) {
                    System.out
                            .println("The parser was not configured correctly.");
                    System.exit(1);
                } catch (java.io.IOException ie) {
                    System.out.println("Cannot read input file.");
                    System.exit(1);
                } catch (org.xml.sax.SAXException se) {
                    System.out.println("Problem parsing the file.");
                    System.exit(1);
                } catch (java.lang.IllegalArgumentException ae) {
                    System.out.println("Please specify an XML source.");
                    System.exit(1);
                } catch (Exception e) {
                    System.out.println("Problem parsing the file: "
                            + e.getMessage());
                }
                if (endWholeName != null && endOrder != 0) {

                    TransBpel tb = new TransBpel(doc);
                    headNode = tb.searchNode(wholeName, order);

                    endNode = tb.searchNode(endWholeName, endOrder);

                    if (headNode != null && endNode != null) {
                        tb.addElementBefore(headNode, flag);
                        tb.addElementBehind(endNode, flag);
                        // Output the modified document into file

                        String parentFile = this.file.getAbsolutePath(); // this.file.getParent();
                        int ind = parentFile.lastIndexOf("\\");
                        parentFile = parentFile.substring(0, ind);
                        // 写入BPEL源文件
                        String path = "";
                        if (flag == 0)
                            path = parentFile + "\\Bisi_" + file.getName();
                        else if (flag == 1) {
                            path = parentFile + "\\Property_" + file.getName();
                        }
                        tb.outputDom(new File(path));

                    } else {
                        System.out.println("Error");
                    }

                } else {
                    System.out
                            .println("The endWholeName is null or the endOrder is 0!");
                }
            } else {
                System.out.println("The endIndex < 0!");
            }
        } else {
            System.out.println("The wholeName is 0 or the order is 0!");
        }
    }

}

⌨️ 快捷键说明

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