コード例 #1
0
  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());
    }
  }
コード例 #2
0
 @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;
 }
コード例 #3
0
 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;
 }
コード例 #4
0
  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;
  }
コード例 #5
0
 @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;
 }
コード例 #6
0
  private void FetchStatic(Element eElement) {
    PrintConsole.print("App fetchs gatways from cofiguration file <config.xml>.");
    gatways = new TreeMap<Integer, Vertex>();
    int Id = 0;
    NodeList childNodes = eElement.getElementsByTagName(CHILD);
    Vertex newGateway;
    for (int counter = 0; counter < childNodes.getLength() && counter < num; counter++) {
      Node childNode = childNodes.item(counter);
      if (childNode.getNodeType() == Node.ELEMENT_NODE) {
        Element childElem = (Element) childNode;
        newGateway =
            new Vertex(
                Id,
                new Point(
                    Integer.valueOf(childElem.getAttribute("x")),
                    Integer.valueOf(childElem.getAttribute("y"))));

        gatways.put(newGateway.getId(), newGateway);
        Id++;
      }
    }
  }