ArrayList<Character> list = new ArrayList<Character>();
for (Element character : node.getChildren("character")) {
Character npg = null;
if (!Character.isInList(character.getAttributeValue("firstName"),
character.getAttributeValue("lastName"))) {
if (character.getAttributeValue("race").equalsIgnoreCase(
"Human")) {
npg = new Human(character.getAttributeValue("firstName"),
character.getAttributeValue("lastName"));
} else if (character.getAttributeValue("race")
.equalsIgnoreCase("Asari")) {
npg = new Asari(character.getAttributeValue("firstName"),
character.getAttributeValue("lastName"));
} else if (character.getAttributeValue("race")
.equalsIgnoreCase("Krogan")) {
npg = new Krogan(character.getAttributeValue("firstName"),
character.getAttributeValue("lastName"));
} else {
throw new ErrNotFountOrMistake("The race of the character "
+ character.getAttributeValue("firstName") + " "
+ character.getAttributeValue("lastName")
+ " is undefined or misdefined in the xml file.");
}
if (npg != null) {
try {
Planet.getPlanet(character.getAttributeValue("planet"))
.addCharacter(npg);
} catch (DataFormatException e) {
e.printStackTrace();
}
}
} else {
if (Character
.getCharacter(character.getAttributeValue("firstName"),
character.getAttributeValue("lastName"))
.getRace()
.equalsIgnoreCase(character.getAttributeValue("race"))) {
npg = Character.getCharacter(
character.getAttributeValue("firstName"),
character.getAttributeValue("lastName"));
} else {
throw new ErrNotFountOrMistake("The race " + character.getAttributeValue("race") + " of the character "
+ character.getAttributeValue("firstName") + " "
+ character.getAttributeValue("lastName")
+ " is undefined or misdefined in the xml file.");
}
}
for(Element text : character.getChildren("text")){
npg.setText(text.getText());
}
list.add(npg);
}
return list;