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

📄 workflow_dom.java

📁 用java实现的工作流
💻 JAVA
字号:
package treedoc;


/* 功能
   使用DOM方法读取GXL文件,解码并调用INTOSQL类中的方法把数据写入数据库的
   边表和节点主表中
*/


/**
 * 名称       : WORKFLOW_DOM
 * 描述       : WWW.FANGFA.NET 工作流管理系统--流程拓扑图XML解析读取类
 * 版权信息   : Copyright (c) 2004 COMSCI
 * @作者      : COMSCI Sichuan Fangfa Digital
 * @版本      : 0.9 builder 2004091910
 * @日期      : 2004/09/19
 */



import java.io.*;
import java.util.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;

public class workflow_dom {
  public workflow_dom(String fe,String gid) throws Exception {

    File f = new File(fe);  //将外部保存的GXL文件读入
    workflow_IntoSql wis = new workflow_IntoSql(fe);
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document doc = db.parse(f);

    // Get the first child (the graph-element)
    // List for the new Cells

    Element gxl = (Element) doc.getDocumentElement(); // First gxl element
    //   List newCells = new ArrayList();
    // ConnectionSet for the Insert method
    //   ConnectionSet cs = new ConnectionSet();
    // Hashtable for the ID lookup (ID to Vertex)
    //   Map ids = new Hashtable();
    // Hashtable for Attributes (Vertex to Map)
    //  Hashtable attributes = new Hashtable();

    NodeList graph_list = gxl.getChildNodes();
//////////////开始截析GXL内容/////////////////////////////////////////////

    if (graph_list.getLength() == 0) {

      return;
    }

    for (int graph_index = 0; graph_index < graph_list.getLength(); graph_index++) {
      Node graph_node = graph_list.item(graph_index);
      if (graph_node.getNodeName().equals("graph")) {
        Element graph_elem = (Element) graph_node;
        NodeList list = graph_elem.getChildNodes();
        for (int i = 0; i < list.getLength(); i++) {
          Node node = list.item(i);

          // Fetch Label
          //    String label = getLabel(node);
          // If Valid Node

          if (node.getAttributes() != null && node.getNodeName() != null) {
            // Fetch Type
            String type = node.getNodeName().toString().toLowerCase();
            //读出节点数据,并写入
            if (type.equals("node")) {

              Node edgeid = node.getAttributes().getNamedItem("id");
              String id = edgeid.getNodeValue();

              //   System.out.println(id);
              //   System.out.println(getLabel(node));
              //   取节点位置数据,以后还原图使用
              //   for (Enumeration e = getBound(node).elements(); e.hasMoreElements(); ) {
              //   System.out.println(e.nextElement());

              //    }
              wis.into_node(getLabel(node), id,gid);
            }

            //读出EDGE数据,并写入DB
            if (type.equals("edge")) {

              String from = null;
              String to = null;
              String edge = null;
              Node edgeid = node.getAttributes().getNamedItem("id");
              Node tmp = node.getAttributes().getNamedItem("from");
              Node tmp1 = node.getAttributes().getNamedItem("to");
              // Fetch ID Value

              edge = edgeid.getNodeValue();
              from = tmp.getNodeValue();
              to = tmp1.getNodeValue();
              wis.into_edge(edge, from, to,gid);
            }
          }

        }
      }

    }

  }

// 将节点BOUNDS数据保存在VECTOR中
  protected Vector getBound(Node node) {

    Vector vec = new Vector();
    NodeList children = node.getChildNodes();
    for (int j = 0; j < children.getLength(); j++) {
      Node attr = children.item(j);
      if (attr.getNodeName().equals("attr")
          && attr
          .getAttributes()
          .getNamedItem("name")
          .getNodeValue()
          .equals(
          "Bounds")) {
        NodeList values = attr.getChildNodes();
        for (int k = 0; k < values.getLength(); k++) {
          if (values.item(k).getNodeName().equals("tup")) {
            NodeList tup = values.item(k).getChildNodes();
            for (int i = 0; i < tup.getLength(); i++) {
              if (tup.item(i).getNodeName().equals("int")) {
                Node Bounds = tup.item(i).getFirstChild();
                vec.add(Bounds.getNodeValue());

              }

            }

          }
        }

      }
    }
    return vec;
  }

//取节点LABEL数据
  protected static String getLabel(Node node) {
    String lab = null;
    NodeList children = node.getChildNodes();
    for (int j = 0; j < children.getLength(); j++) {
      Node attr = children.item(j);
      if (attr.getNodeName().equals("attr")
          && attr
          .getAttributes()
          .getNamedItem("name")
          .getNodeValue()
          .equals(
          "Label")) {
        NodeList values = attr.getChildNodes();
        for (int k = 0; k < values.getLength(); k++) {
          if (values.item(k).getNodeName().equals("string")) {
            Node labelNode = values.item(k).getFirstChild();

            if (labelNode != null) {
              lab = labelNode.getNodeValue();
            }
          }
        }
      }
    }
    return (lab != null) ? lab : new String("");
  }

//////////////////////保留测试用MAIN方法////////////////////////////
 // public static void main(String argv[]) {
//    try {

   //   workflow_dom wd = new workflow_dom();

 //   }
 //   catch (Exception e) {}
 // }
////////////////////////////////////////////////////////////////////
}

⌨️ 快捷键说明

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