private void parseTerrestrial(Element terrestrialElement, TerrestrialPlanet terrestrial) { terrestrial.setTemperature( Integer.parseInt(getInnerTagContent(terrestrialElement, "temperature"))); parsePlanet(terrestrialElement, terrestrial); systemsMap.put(system, terrestrial); }
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); }
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); }
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; }