private void FetchFromFile(Element eElement) { PrintConsole.print("App fetchs gatways from a different file."); fileAddress = eElement.getAttribute(ATTFILE); try { BufferedReader reader = null; int Id = 0; InputStream in = getClass().getResourceAsStream(fileAddress); reader = new BufferedReader(new InputStreamReader(in)); String var = ""; String[] Pos; gatways = new TreeMap<>(); Vertex newGateway; while ((var = reader.readLine()) != null) { Pos = var.split("[ ]"); newGateway = new Vertex(Id, new Point(Integer.valueOf(Pos[0]), Integer.valueOf(Pos[1]))); gatways.put(newGateway.getId(), newGateway); Id++; } reader.close(); } catch (Exception ex) { PrintConsole.printErr("GatewayConfig/FetchFromFile message:" + ex.getMessage()); } }
@Override protected boolean ValidateXMLDocument(Element eElement) throws Exception { if (!eElement.hasAttribute(ATTMODE)) { PrintConsole.printErr( TAG + " must have child node. the following template may help you " + "\n <Channels Mode=\"Partially|All\"> \n \t <Add Value=\"1\" />\n\t<Add Value=\"2\" /> \n </Channels>"); System.exit(0); } return true; }
protected boolean ValidateXMLDocument(Element eElement, ChannelMode mode) throws Exception { if (mode == ChannelMode.Partially) { if (eElement.hasChildNodes()) { PrintConsole.printErr( TAG + " must have child node. the following template may help you " + "\n <Channels Mode=\"Partially\"> \n \t <Add Value=\"1\" />\n\t<Add Value=\"2\" /> \n </Channels>"); System.exit(0); } } return true; }
protected boolean ValidateXMLDocument(Element eElement, TypeOfGenerationEnum type) throws Exception { if (type == TypeOfGenerationEnum.RANDOM) { if (eElement.hasAttribute(ATTSEED)) if (!Pattern.matches("-?[0-9]+", eElement.getAttribute(ATTSEED))) { PrintConsole.printErr( "The value of " + ATTSEED + " attribute in " + TAG + " must be an interger value. \n\n"); System.exit(0); } } if (type == TypeOfGenerationEnum.FILE) if (!eElement.hasAttribute(ATTFILE)) { PrintConsole.printErr( ATTFILE + " attribute in " + TAG + " tag is missing. the following template may help you \n" + "<Gateways Number=\"2\" TypeOfGeneration=\"file\" Address=\"src/setting/gatway.txt\" />"); System.exit(0); } if (type == TypeOfGenerationEnum.STATIC) if (!eElement.hasChildNodes()) { PrintConsole.printErr( TAG + " must have child node. the following template may help you " + "\n <Gateways Number=\"2\" TypeOfGeneration=\"Static\">" + " \n <Add x=\"150\" y=\"975\" /> \n <Add x=\"274\" y=\"785\" />\n</Gateways> "); System.exit(0); } return true; }
@Override protected boolean ValidateXMLDocument(Element eElement) throws Exception { if (!eElement.hasAttribute(ATTNUM)) { PrintConsole.printErr( ATTNUM + " attribute in " + TAG + " tag is missing. the following template may help you." + "\n <Gateways Number=\"2\" TypeOfGeneration=\"Static\"> \n " + "<Add x=\"114\" y=\"457\" />\n<Add x=\"12\" y=\"333\" /></Gateways>"); System.exit(0); } else if (!Pattern.matches("-?[0-9]+", eElement.getAttribute(ATTNUM))) { PrintConsole.printErr( "The value of " + ATTNUM + " attribute in " + TAG + " must be an interger value. \n\n"); System.exit(0); } if (!eElement.hasAttribute(ATTTOG)) { PrintConsole.printErr( ATTTOG + " attribute in " + TAG + " tag is missing. this template may help you." + "\n <Gateways Number=\"2\" TypeOfGeneration=\"Static\"> \n " + "<Add x=\"114\" y=\"457\" />\n<Add x=\"12\" y=\"333\" /></Gateways>"); System.exit(0); } else if (!Pattern.matches( "random|static|file", eElement.getAttribute(ATTTOG).toLowerCase())) { PrintConsole.printErr( "the value of " + ATTTOG + " in " + TAG + " node must be on of the following item:" + " \n 1- File \n 2- Static \n 3- Random.\n\n"); System.exit(0); } if (!eElement.hasAttribute(ATTRADIO)) { PrintConsole.printErr( ATTRADIO + " attribute in " + TAG + " tag is missing. the following template may help you." + "\n <Routers Number=\"20\" TypeOfGeneration=\"RANDOM\" MinDistance=\"50\" Seed=\" 12252554 \" " + "SaftyTest=\"50\" />\n\n"); System.exit(0); } // check the value of tag else if (!Pattern.matches("-?[0-9]+", eElement.getAttribute(ATTRADIO))) { PrintConsole.printErr( "The value of " + ATTRADIO + " attribute must be an interger value. \n\n"); System.exit(0); } return true; }