use of com.nolanlawson.keepscore.db.Game in project KeepScore by nolanlawson.
the class GamesBackupSerializer method deserialize.
@SuppressWarnings("incomplete-switch")
public static GamesBackup deserialize(String xmlData) {
int parserEvent = -1;
XmlPullParser parser = null;
Tag tag = null;
GamesBackup gamesBackup = new GamesBackup();
gamesBackup.setGames(new ArrayList<Game>());
Game game = null;
PlayerScore playerScore = null;
Map<String, String> attributes = null;
try {
// calls service (referenced in url) to request XML serialized data
parser = XmlHelper.loadData(xmlData);
parserEvent = parser.getEventType();
while (parserEvent != XmlPullParser.END_DOCUMENT) {
switch(parserEvent) {
case XmlPullParser.START_TAG:
tag = Tag.valueOf(parser.getName());
switch(tag) {
case Game:
game = new Game();
game.setPlayerScores(new ArrayList<PlayerScore>());
break;
case PlayerScore:
playerScore = new PlayerScore();
break;
}
// null or empty marker
if (parser.getAttributeCount() != -1) {
attributes = getAttributes(parser);
}
break;
case XmlPullParser.END_TAG:
tag = Tag.valueOf(parser.getName());
switch(tag) {
case Game:
gamesBackup.getGames().add(game);
break;
case PlayerScore:
game.getPlayerScores().add(playerScore);
break;
}
break;
case XmlPullParser.TEXT:
String text = parser.getText();
if (!StringUtil.isEmptyOrWhitespace(text)) {
handleText(text, tag, attributes, gamesBackup, game, playerScore);
}
break;
}
parserEvent = parser.next();
}
} catch (XmlPullParserException e) {
log.e(e, "unexpected");
} catch (IOException e) {
log.e(e, "unexpected");
}
applyVersionFixes(gamesBackup);
// return de-serialized game backup
return gamesBackup;
}
Aggregations