/* * public HashMap getLeafElements() { HashMap map = new HashMap(); Object[] * elts = dataElements.values().toArray(); for (int j=0; j<elts.length; j++) * { PDMDataElement data = (PDMDataElement) elts[j]; * map.put(data.getID(),data); } Object[] ops = * operations.values().toArray(); for (int i=0; i<ops.length; i++){ * PDMOperation op = (PDMOperation) ops[i]; if * (!(op.getInputElements().isEmpty())){ HashMap outs = * op.getOutputElements(); Object[] outArray = outs.values().toArray(); for * (int j=0; j<outArray.length; j++) { PDMDataElement d = (PDMDataElement) * outArray[j]; map.remove(d.getID()); } } } return map; } */ public HashMap getLeafElements() { HashMap result = new HashMap(); HashSet leafOps = getLeafOperations(); if (!(leafOps.isEmpty())) { Iterator it = leafOps.iterator(); while (it.hasNext()) { PDMOperation op = (PDMOperation) it.next(); PDMDataElement data = op.getOutputElement(); result.put(data.getID(), data); } } else { Object[] elts = dataElements.values().toArray(); for (int j = 0; j < elts.length; j++) { PDMDataElement data = (PDMDataElement) elts[j]; result.put(data.getID(), data); } Object[] ops = operations.values().toArray(); for (int i = 0; i < ops.length; i++) { PDMOperation op = (PDMOperation) ops[i]; HashMap outs = op.getOutputElements(); Object[] outArray = outs.values().toArray(); for (int j = 0; j < outArray.length; j++) { PDMDataElement d = (PDMDataElement) outArray[j]; result.remove(d.getID()); } } } return result; }
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()); } }
/** * Removes an Operation to the set of Operations of the Product Data Model added by Johfra * * @param operation PDMOperation */ public void remOperation(PDMOperation operation) { operations.remove(operation.getID()); }
/** * Export PDM model to Declare process model. * * @param bw Writer * @throws IOException If writing fails */ public void writePDMToDeclare(Writer bw) throws IOException { // write the preamble of the XML file bw.write("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"); bw.write("<model>\n"); bw.write("<assignment language=\"ConDec\" name=\"" + name + "\">\n"); // write the activity definitions, i.e. each operation in the PDM is an // activity definition in Declare bw.write("<activitydefinitions>\n"); // start with an initial activity that puts the values for the leaf // elements of the PDM bw.write("<activity id=\"Initial\" name=\"Initial\">\n"); bw.write("<authorization/>\n"); bw.write("<datamodel>\n"); // all leaf elements HashMap leafs = getLeafElements(); Object[] leafElts = leafs.values().toArray(); for (int i = 0; i < leafElts.length; i++) { PDMDataElement data = (PDMDataElement) leafElts[i]; data.writePDMToDeclare(bw, "output"); } bw.write("</datamodel>\n"); bw.write("<attributes/>\n"); bw.write("</activity>\n"); // first remove input operations from the set of operations and then // write all real operations HashMap realOps = (HashMap) operations.clone(); HashSet inputOps = getLeafOperations(); Iterator it7 = inputOps.iterator(); while (it7.hasNext()) { PDMOperation op = (PDMOperation) it7.next(); realOps.remove(op.getID()); } Iterator it4 = realOps.values().iterator(); while (it4.hasNext()) { PDMOperation operation = (PDMOperation) it4.next(); operation.writePDMToDeclare(bw); } bw.write("\n"); // write all input operations (i.e. producing input data elements) Iterator it8 = inputOps.iterator(); while (it8.hasNext()) { PDMOperation op = (PDMOperation) it8.next(); op.writePDMToDeclare(bw); } bw.write("</activitydefinitions>\n"); // write the constraint definition, for now we do not have any // constraints in the PDM that are translated to Declare bw.write("<constraintdefinitions>\n"); bw.write("</constraintdefinitions>\n"); // write all dataelements bw.write("<data>\n"); Iterator it5 = dataElements.values().iterator(); while (it5.hasNext()) { PDMDataElement dataElement = (PDMDataElement) it5.next(); dataElement.writePDMToDeclare(bw); } bw.write("</data>\n"); // write the organizational information bw.write("<team/>\n"); // TODO: improve graphical positioning of activities. Now they are // presented in one long line. // write the graphical positioning information of the Declare model, // first the initial operation, then the real operations and then the // input operations. bw.write("<graphical>\n"); bw.write("<cells>\n"); Iterator it6 = realOps.values().iterator(); Double pos = 10.0; while (it6.hasNext()) { PDMOperation operation = (PDMOperation) it6.next(); bw.write( "<cell activitydefinition=\"" + operation.getOperationNR() + "\" height=\"40.0\" width=\"80.0\" x=\"" + pos + "\" y=\"90.0\" />\n"); pos = pos + 85.0; } Iterator it9 = inputOps.iterator(); pos = 10.0; while (it9.hasNext()) { PDMOperation operation = (PDMOperation) it9.next(); bw.write( "<cell activitydefinition=\"" + operation.getOperationNR() + "\" height=\"40.0\" width=\"80.0\" x=\"" + pos + "\" y=\"180.0\" />\n"); pos = pos + 85.0; } bw.write("</cells>\n"); // write the connectors bw.write("<connectors/>\n"); // close the XML file in the right way bw.write("</graphical>\n"); bw.write("</assignment>\n"); bw.write("</model>\n"); }