Пример #1
0
  private void parseTerrestrial(Element terrestrialElement, TerrestrialPlanet terrestrial) {
    terrestrial.setTemperature(
        Integer.parseInt(getInnerTagContent(terrestrialElement, "temperature")));

    parsePlanet(terrestrialElement, terrestrial);
    systemsMap.put(system, terrestrial);
  }
Пример #2
0
  private void parseStar(Element starElement) {
    system = starElement.getAttribute("system");
    Star star = new Star();
    star.setType(getInnerTagContent(starElement, "type"));

    parseBody(starElement, star);
    systemsMap.put(system, star);
  }
Пример #3
0
  private void parseGiant(Element giantElement) {
    system = giantElement.getAttribute("system");
    GasGiant giant = new GasGiant();

    giant.setRings(Integer.parseInt(getInnerTagContent(giantElement, "rings")));

    parsePlanet(giantElement, giant);
    systemsMap.put(system, giant);
  }
Пример #4
0
  public SystemsMap getSystems(String path) throws Exception {
    systemsMap.clear();
    File file = new File(path);
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();

    Document doc = db.parse(file);

    Node root = doc.getDocumentElement();
    root.normalize();

    NodeList children = root.getChildNodes();

    for (int i = 0; i < children.getLength(); i++) {
      Node child = children.item(i);
      if (child.getNodeType() == Node.ELEMENT_NODE) {
        switch (child.getNodeName()) {
          case "star":
            {
              parseStar((Element) child);
              break;
            }
          case "terrestrial":
            {
              parseTerrestrial((Element) child);
              break;
            }
          case "giant":
            {
              parseGiant((Element) child);
              break;
            }
          case "habitable":
            {
              parseHabitable((Element) child);
              break;
            }
        }
      }
    }
    return systemsMap;
  }