+ return sone;
+ }
+
+ private void parseTime(SimpleXML soneXml, Sone sone) {
+ String soneTime = soneXml.getValue("time", null);
+ if (soneTime == null) {
+ /* TODO - mark Sone as bad. */
+ logger.log(Level.WARNING, String.format("Downloaded time for Sone %s was null!", sone));
+ throw new MalformedXml();
+ }
+ try {
+ sone.setTime(Long.parseLong(soneTime));
+ } catch (NumberFormatException nfe1) {
+ /* TODO - mark Sone as bad. */
+ logger.log(Level.WARNING, String.format("Downloaded Sone %s with invalid time: %s", sone, soneTime));
+ throw new MalformedTime();
+ }
+ }
+
+ private void verifyProtocolVersion(SimpleXML soneXml) {
+ Optional<Integer> protocolVersion = parseProtocolVersion(soneXml);
+ if (protocolVersion.isPresent()) {
+ if (protocolVersion.get() < 0) {
+ logger.log(Level.WARNING, String.format("Invalid protocol version: %d! Not parsing Sone.", protocolVersion.get()));
+ throw new InvalidProtocolVersion();
+ }
+ if (protocolVersion.get() > MAX_PROTOCOL_VERSION) {
+ logger.log(Level.WARNING, String.format("Unknown protocol version: %d! Not parsing Sone.", protocolVersion.get()));
+ throw new SoneTooNew();
+ }
+ }