Definition at line 21 of file ansim/NetReader.java.
Static Public Member Functions | |
| static void | read (String net, List< Edge > edges) |
| static void ansim::NetReader::read | ( | String | net, | |
| List< Edge > | edges | |||
| ) | [inline, static] |
method for reading net file
| net | name of netfile | |
| edges | holds net after execution |
Definition at line 28 of file ansim/NetReader.java.
00028 { 00029 try { 00030 InputStream in = new FileInputStream(net); 00031 XMLInputFactory factory = XMLInputFactory.newInstance(); 00032 XMLStreamReader parser = factory.createXMLStreamReader(in); 00033 for (int event = parser.next(); event != XMLStreamConstants.END_DOCUMENT; event = parser.next()) { 00034 if (event == XMLStreamConstants.START_ELEMENT) { 00035 if (parser.getLocalName().equals("edge")) { 00036 String id = ""; 00037 float length = 0; 00038 float speed = 0; 00039 String name = ""; 00040 float xfrom = 0; 00041 float yfrom = 0; 00042 float xto = 0; 00043 float yto = 0; 00044 for (int attr = 0; attr < parser.getAttributeCount(); attr++) { 00045 String attrName = parser.getAttributeLocalName(attr); 00046 String value = parser.getAttributeValue(attr); 00047 if ("id".equals(attrName)) 00048 id = value; 00049 if ("Length".equals(attrName)) 00050 length = Float.parseFloat(value); 00051 if ("Speed".equals(attrName)) 00052 speed = Float.parseFloat(value); 00053 if ("Name".equals(attrName)) 00054 name = value; 00055 if ("XFrom".equals(attrName)) 00056 xfrom = Float.parseFloat(value); 00057 if ("YFrom".equals(attrName)) 00058 yfrom = Float.parseFloat(value); 00059 if ("XTo".equals(attrName)) 00060 xto = Float.parseFloat(value); 00061 if ("YTo".equals(attrName)) 00062 yto = Float.parseFloat(value); 00063 00064 } 00065 Edge edge = new Edge(id, length, speed, name, xfrom,yfrom, xto, yto); 00066 edges.add(edge); 00067 } 00068 } 00069 } 00070 parser.close(); 00071 } catch (XMLStreamException ex) { 00072 System.out.println(ex); 00073 } catch (IOException ex) { 00074 System.out.println("IOException while parsing " + net); 00075 } 00076 }
1.5.6