/** * Sets this <code>XmlReaderContentHandler</code> object's <code>tag</code> field if the given * name is the key for a tag and this object's state is not <code>INITIAL</code>. The field is set * to the constant that corresponds to the given element name. If the state is <code>INITIAL * </code>, the state is set to the given name, which will be one of the sections <code>PROPERTIES * </code>, <code>METADATA</code>, or <code>DATA</code>. In either case, this method puts this * document handler in the proper state for calling the method <code>endElement</code>. * * <p>If the state is <code>DATA</code> and the tag is <code>RowTag</code>, <code>DelTag</code>, * or <code>InsTag</code>, this method moves the rowset's cursor to the insert row and sets this * <code>XmlReaderContentHandler</code> object's <code>idx</code> field to <code>0</code> so that * it will be in the proper state when the parser calls the method <code>endElement</code>. * * @param lName the name of the element; either (1) one of the array elements in the fields <code> * properties</code>, <code>colDef</code>, or <code>data</code> or (2) one of the <code>RowSet * </code> elements <code>"properties"</code>, <code>"metadata"</code>, or <code>"data"</code> * @param attributes <code>org.xml.sax.AttributeList</code> objects that are attributes of the * named section element; may be <code>null</code> if there are no attributes, which is the * case for <code>WebRowSet</code> objects * @exception SAXException if a general SAX error occurs */ public void startElement(String uri, String lName, String qName, Attributes attributes) throws SAXException { int tag; String name = ""; name = lName; switch (getState()) { case PROPERTIES: tempCommand = ""; tag = propMap.get(name); if (tag == PropNullTag) setNullValue(true); else setTag(tag); break; case METADATA: tag = colDefMap.get(name); if (tag == MetaNullTag) setNullValue(true); else setTag(tag); break; case DATA: /** * This has been added to clear out the values of the previous read so that we should not * add up values of data between different tags */ tempStr = ""; tempUpdate = ""; if (dataMap.get(name) == null) { tag = NullTag; } else if (dataMap.get(name) == EmptyStringTag) { tag = EmptyStringTag; } else { tag = dataMap.get(name); } if (tag == NullTag) { setNullValue(true); } else if (tag == EmptyStringTag) { setEmptyStringValue(true); } else { setTag(tag); if (tag == RowTag || tag == DelTag || tag == InsTag) { idx = 0; try { rs.moveToInsertRow(); } catch (SQLException ex) {; } } } break; default: setState(name); } }
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()); } }
public static PetriNet convert(ConfigurableEPC baseEPC) { HashMap<EPCFunction, Transition> functionActivityMapping; HashMap<EPCConnector, Place> xorconnectorChoiceMapping; // HV: Initialize the mappings. functionActivityMapping = new HashMap<EPCFunction, Transition>(); xorconnectorChoiceMapping = new HashMap<EPCConnector, Place>(); // Check to use the weights if necessary // HV: Add both mappings. On completion, these will be filledd. PetriNet petrinet = EPCToPetriNetConverter.convert( baseEPC, new HashMap(), functionActivityMapping, xorconnectorChoiceMapping); HashSet visible = new HashSet(); // HV: The next block is taken care of by the functionActivityMapping // below. /* * Iterator it = petrinet.getTransitions().iterator(); while * (it.hasNext()) { Transition t = (Transition) it.next(); if (t.object * instanceof EPCFunction) { // if (t.getLogEvent() != null) { // Add * transitions with LogEvent (i.e. referring to functions) * visible.add(t); } } */ // HV: Prevent the places mapped onto from being reduced. visible.addAll(functionActivityMapping.values()); visible.addAll(xorconnectorChoiceMapping.values()); Message.add(visible.toString(), Message.DEBUG); Iterator it = petrinet.getPlaces().iterator(); while (it.hasNext()) { Place p = (Place) it.next(); if (p.inDegree() * p.outDegree() == 0) { // Add Initial and final places to visible, i.e. places that // refer to in and output events visible.add(p); } } // Reduce the PetriNet with Murata rules, while keeping the visible ones PetriNetReduction pnred = new PetriNetReduction(); pnred.setNonReducableNodes(visible); HashMap pnMap = new HashMap(); // Used to map pre-reduction nodes to // post-reduction nodes. PetriNet reduced = pnred.reduce(petrinet, pnMap); if (reduced != petrinet) { // Update both mappings from pre-reduction nodes to post-reduction // nodes. HashMap<EPCFunction, Transition> newFunctionActivityMapping = new HashMap<EPCFunction, Transition>(); for (EPCFunction function : functionActivityMapping.keySet()) { Transition transition = (Transition) functionActivityMapping.get(function); if (pnMap.keySet().contains(transition)) { newFunctionActivityMapping.put(function, (Transition) pnMap.get(transition)); } } functionActivityMapping = newFunctionActivityMapping; HashMap<EPCConnector, Place> newXorconnectorChoiceMapping = new HashMap<EPCConnector, Place>(); for (EPCConnector connector : xorconnectorChoiceMapping.keySet()) { Place place = (Place) xorconnectorChoiceMapping.get(connector); if (pnMap.keySet().contains(place)) { newXorconnectorChoiceMapping.put(connector, (Place) pnMap.get(place)); } } xorconnectorChoiceMapping = newXorconnectorChoiceMapping; } reduced.makeClusters(); // filter the \nunknown:normal ArrayList<Transition> alTrans = reduced.getVisibleTasks(); for (int i = 0; i < alTrans.size(); i++) { Transition t = alTrans.get(i); String id = t.getIdentifier(); int idx = id.indexOf("\\nunknown:normal"); if (idx > 0) { id = id.substring(0, idx); } // �˴������ֵ��ѯ�滻���е�label String mappedId = htDict.get(id); if (mappedId != null) { t.setIdentifier(mappedId); } else { t.setIdentifier(id); } } return reduced; }
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>")); } } } } } }
/** * Provides the value of a particular default field, null if undefined. * * @param field default field to retrieve * @return value corresponding to default field */ public static String getDefault(Default field) { return DEFAULTS.get(field); }
/** * Sets the value for the given element if <code>name</code> is one of the array elements in the * fields <code>properties</code>, <code>colDef</code>, or <code>data</code> and this <code> * XmlReaderContentHandler</code> object's state is not <code>INITIAL</code>. If the state is * <code>INITIAL</code>, this method does nothing. * * <p>If the state is <code>METADATA</code> and the argument supplied is <code>"metadata"</code>, * the rowset's metadata is set. If the state is <code>PROPERTIES</code>, the appropriate property * is set using the given name to determine the appropriate value. If the state is <code>DATA * </code> and the argument supplied is <code>"data"</code>, this method sets the state to <code> * INITIAL</code> and returns. If the argument supplied is one of the elements in the field <code> * data</code>, this method makes the appropriate changes to the rowset's data. * * @param lName the name of the element; either (1) one of the array elements in the fields <code> * properties</code>, <code>colDef</code>, or <code>data</code> or (2) one of the <code>RowSet * </code> elements <code>"properties"</code>, <code>"metadata"</code>, or <code>"data"</code> * @exception SAXException if a general SAX error occurs */ @SuppressWarnings("fallthrough") public void endElement(String uri, String lName, String qName) throws SAXException { int tag; String name = ""; name = lName; switch (getState()) { case PROPERTIES: if (name.equals("properties")) { state = INITIAL; break; } try { tag = propMap.get(name); switch (tag) { case KeycolsTag: if (keyCols != null) { int i[] = new int[keyCols.size()]; for (int j = 0; j < i.length; j++) i[j] = Integer.parseInt(keyCols.elementAt(j)); rs.setKeyColumns(i); } break; case PropClassTag: // Added the handling for Class tags to take care of maps // Makes an entry into the map upon end of class tag try { typeMap.put(Key_map, j86.sun.reflect.misc.ReflectUtil.forName(Value_map)); } catch (ClassNotFoundException ex) { throw new SAXException( MessageFormat.format( resBundle.handleGetObject("xmlrch.errmap").toString(), ex.getMessage())); } break; case MapTag: // Added the handling for Map to take set the typeMap rs.setTypeMap(typeMap); break; default: break; } if (getNullValue()) { setPropertyValue(null); setNullValue(false); } else { setPropertyValue(propertyValue); } } catch (SQLException ex) { throw new SAXException(ex.getMessage()); } // propertyValue need to be reset to an empty string propertyValue = ""; setTag(-1); break; case METADATA: if (name.equals("metadata")) { try { rs.setMetaData(md); state = INITIAL; } catch (SQLException ex) { throw new SAXException( MessageFormat.format( resBundle.handleGetObject("xmlrch.errmetadata").toString(), ex.getMessage())); } } else { try { if (getNullValue()) { setMetaDataValue(null); setNullValue(false); } else { setMetaDataValue(metaDataValue); } } catch (SQLException ex) { throw new SAXException( MessageFormat.format( resBundle.handleGetObject("xmlrch.errmetadata").toString(), ex.getMessage())); } // metaDataValue needs to be reset to an empty string metaDataValue = ""; } setTag(-1); break; case DATA: if (name.equals("data")) { state = INITIAL; return; } if (dataMap.get(name) == null) { tag = NullTag; } else { tag = dataMap.get(name); } switch (tag) { case ColTag: try { idx++; if (getNullValue()) { insertValue(null); setNullValue(false); } else { insertValue(tempStr); } // columnValue now need to be reset to the empty string columnValue = ""; } catch (SQLException ex) { throw new SAXException( MessageFormat.format( resBundle.handleGetObject("xmlrch.errinsertval").toString(), ex.getMessage())); } break; case RowTag: try { rs.insertRow(); rs.moveToCurrentRow(); rs.next(); // Making this as the original to turn off the // rowInserted flagging rs.setOriginalRow(); applyUpdates(); } catch (SQLException ex) { throw new SAXException( MessageFormat.format( resBundle.handleGetObject("xmlrch.errconstr").toString(), ex.getMessage())); } break; case DelTag: try { rs.insertRow(); rs.moveToCurrentRow(); rs.next(); rs.setOriginalRow(); applyUpdates(); rs.deleteRow(); } catch (SQLException ex) { throw new SAXException( MessageFormat.format( resBundle.handleGetObject("xmlrch.errdel").toString(), ex.getMessage())); } break; case InsTag: try { rs.insertRow(); rs.moveToCurrentRow(); rs.next(); applyUpdates(); } catch (SQLException ex) { throw new SAXException( MessageFormat.format( resBundle.handleGetObject("xmlrch.errinsert").toString(), ex.getMessage())); } break; case InsDelTag: try { rs.insertRow(); rs.moveToCurrentRow(); rs.next(); rs.setOriginalRow(); applyUpdates(); } catch (SQLException ex) { throw new SAXException( MessageFormat.format( resBundle.handleGetObject("xmlrch.errinsdel").toString(), ex.getMessage())); } break; case UpdTag: try { if (getNullValue()) { insertValue(null); setNullValue(false); } else if (getEmptyStringValue()) { insertValue(""); setEmptyStringValue(false); } else { updates.add(upd); } } catch (SQLException ex) { throw new SAXException( MessageFormat.format( resBundle.handleGetObject("xmlrch.errupdate").toString(), ex.getMessage())); } break; default: break; } default: break; } }