示例#1
0
  public static MiningResult importFile(InputStream input) throws IOException {
    try {
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      Document doc;
      // NodeList netNodes;
      dbf.setValidating(false);
      dbf.setIgnoringComments(true);
      dbf.setIgnoringElementContentWhitespace(true);
      // dbf.setExpandEntityReferences(false);
      // dbf.setNamespaceAware(false);

      DocumentBuilder db = dbf.newDocumentBuilder();

      db.setEntityResolver(
          new EntityResolver() {
            public InputSource resolveEntity(String publicId, String systemId) {
              if (systemId.indexOf("ARIS-Export") != -1) {
                return new InputSource("file:" + About.EXTLIBLOCATION() + "ARIS-Export101.dtd");
              } else {
                return null;
              }
            }
          });

      InputSource inpStream = new InputSource(input);
      inpStream.setSystemId("file:" + System.getProperty("user.dir", ""));
      doc = db.parse(inpStream);

      // check if root element is a aml tag
      Message.add("parsing done" + doc, Message.DEBUG);
      if (!(doc.getDocumentElement().getNodeName().equals("AML"))) {
        Message.add("aml tag not found", Message.ERROR);
        throw new Exception("aml tag not found");
      } else {
        Message.add("aml root element found");
      }

      EPCResult result = new EPCResult(null, (EPC) null);
      HashMap ObjDef_LinkId = new HashMap();
      HashMap modelid_net = new HashMap();
      HashMap ObjDef_Name = new HashMap();
      HashMap function_LinkId = new HashMap();
      HashMap ModelId_ModelType = new HashMap();
      traverseAMLforObjectNames(
          ObjDef_Name, doc.getDocumentElement(), ObjDef_LinkId, ModelId_ModelType);
      Iterator findLinkToEpc = ObjDef_LinkId.keySet().iterator();
      while (findLinkToEpc.hasNext()) {
        String currentObjDef = (String) findLinkToEpc.next();
        String Links = (String) ObjDef_LinkId.get(currentObjDef);
        StringTokenizer linkSet = new StringTokenizer(Links);
        String realEpcLink = "";
        while (linkSet.hasMoreTokens()) {
          String currentLink = linkSet.nextToken();
          if (ModelId_ModelType.get(currentLink).equals("MT_EEPC")) {
            realEpcLink = currentLink;
            break;
          }
        }
        if (realEpcLink.equals(" ")) {
          ObjDef_LinkId.remove(currentObjDef);
        } else {
          ObjDef_LinkId.put(currentObjDef, realEpcLink);
        }
      }
      result =
          traverseAML(
              result,
              doc.getDocumentElement(),
              null,
              ObjDef_Name,
              ObjDef_LinkId,
              modelid_net,
              function_LinkId);
      Iterator hierarchicalFunctions = function_LinkId.keySet().iterator();
      while (hierarchicalFunctions.hasNext()) {
        EPCSubstFunction f = (EPCSubstFunction) hierarchicalFunctions.next();
        f.setSubstitutedEPC((EPC) modelid_net.get(function_LinkId.get(f)));
        // Message.add(f.getSubstitutedEPC().getName());
      }

      return result;

    } catch (Throwable x) {
      Message.add(x.toString());
      throw new IOException(x.getMessage());
    }
  }
示例#2
0
  private static void parseNet(
      Node node,
      EPC net,
      HashMap ObjDef_Name,
      HashMap ObjDef_LinkId,
      HashMap function_LinkId,
      String ModelName)
      throws Exception {
    HashMap mapping = new HashMap();

    // read all nodes
    NodeList nodes = node.getChildNodes();
    net.setIdentifier(ModelName);
    // Message.add("here I am still happy");
    for (int i = 0; i < nodes.getLength(); i++) {
      Node n = nodes.item(i);
      if (!n.getNodeName().equals("ObjOcc")) {
        continue;
      }
      if (n.getAttributes().getNamedItem("SymbolNum") == null) {
        continue;
      }
      String symbolnum = n.getAttributes().getNamedItem("SymbolNum").getNodeValue();
      if (!(symbolnum.equals("ST_FUNC")
          || symbolnum.equals("ST_EV")
          || symbolnum.equals("ST_OPR_AND_1")
          || symbolnum.equals("ST_OPR_OR_1")
          || symbolnum.equals("ST_OPR_XOR_1"))) {
        continue;
      }

      String ObjDef = n.getAttributes().getNamedItem("ObjDef.IdRef").getNodeValue();
      String ownName = (String) ObjDef_Name.get(ObjDef);
      // Message.add("YES " +
      // n.getAttributes().getNamedItem("ObjOcc.ID").getNodeValue());
      String id = n.getAttributes().getNamedItem("ObjOcc.ID").getNodeValue();
      // Message.add(id + " " + ownName);
      if (ownName == null || ownName == "") {
        ownName = id.substring(7, 11);
      }
      if (symbolnum.equals("ST_FUNC")) {
        if (ObjDef_LinkId.containsKey(ObjDef)) {
          EPCSubstFunction sf =
              (EPCSubstFunction)
                  net.addFunction(
                      new EPCSubstFunction(new LogEvent(ownName, "unknown:normal"), net, null));
          sf.setIdentifier(ownName);
          mapping.put(id, sf);
          function_LinkId.put(sf, ObjDef_LinkId.get(ObjDef));
        } else {
          EPCFunction f =
              net.addFunction(new EPCFunction(new LogEvent(ownName, "unknown:normal"), net));
          f.setIdentifier(ownName);
          mapping.put(id, f);
        }
      } else if (symbolnum.equals("ST_EV")) {
        EPCEvent e = net.addEvent(new EPCEvent(ownName, net));
        e.setIdentifier(ownName);
        mapping.put(id, e);
      } else if (symbolnum.equals("ST_OPR_AND_1")) {
        EPCConnector c = net.addConnector(new EPCConnector(EPCConnector.AND, net));
        mapping.put(id, c);
      } else if (symbolnum.equals("ST_OPR_OR_1")) {
        // EPCConnector c = net.addConnector(new
        // EPCConnector(EPCConnector.OR, net));
        EPCConnector c = net.addConnector(new EPCConnector(EPCConnector.AND, net));
        mapping.put(id, c);
      } else if (symbolnum.equals("ST_OPR_XOR_1")) {
        EPCConnector c = net.addConnector(new EPCConnector(EPCConnector.XOR, net));
        mapping.put(id, c);
      }
    }

    for (int i = 0; i < nodes.getLength(); i++) {
      Node n = nodes.item(i);
      if (!n.getNodeName().equals("ObjOcc")) {
        continue;
      }
      if (n.getAttributes().getNamedItem("SymbolNum") == null) {
        continue;
      }
      String symbolnum = n.getAttributes().getNamedItem("SymbolNum").getNodeValue();
      if (!(symbolnum.equals("ST_FUNC")
          || symbolnum.equals("ST_EV")
          || symbolnum.equals("ST_OPR_AND_1")
          || symbolnum.equals("ST_OPR_OR_1")
          || symbolnum.equals("ST_OPR_XOR_1"))) {
        continue;
      }
      String source = n.getAttributes().getNamedItem("ObjOcc.ID").getNodeValue();
      if (n.hasChildNodes()) {
        for (int j = 0; j < n.getChildNodes().getLength(); j++) {
          if (n.getChildNodes().item(j).getNodeName().equals("CxnOcc")) {
            Node CxnOcc = n.getChildNodes().item(j);
            String dest = CxnOcc.getAttributes().getNamedItem("ToObjOcc.IdRef").getNodeValue();
            if (mapping.get(dest) == null) {
              continue;
            }
            if (net.addEdge((EPCObject) mapping.get(source), (EPCObject) mapping.get(dest))
                == null) {
              throw (new Exception(
                  "<html>Structural properties of EPCs are violated in input file.<br>"
                      + "The following edge could not be added:<br><br>"
                      + mapping.get(source).toString()
                      + " ==> "
                      + mapping.get(dest).toString()
                      + "<br><br>Import aborted.</html>"));
            }
          }
        }
      }
    }
  }