Made all the model classes extend off the schema xml classes for race, and made xml builder, validator and reader utility class.
#story[1092]
This commit is contained in:
@@ -3,7 +3,6 @@ package mock.app;
|
||||
import mock.dataInput.PolarParser;
|
||||
import mock.model.MockRace;
|
||||
import mock.model.Polars;
|
||||
import mock.xml.Race;
|
||||
import mock.xml.RaceXMLCreator;
|
||||
import network.Messages.LatestMessages;
|
||||
import org.xml.sax.SAXException;
|
||||
@@ -14,6 +13,7 @@ import shared.exceptions.InvalidRaceDataException;
|
||||
import shared.exceptions.InvalidRegattaDataException;
|
||||
import shared.exceptions.XMLReaderException;
|
||||
import shared.model.Constants;
|
||||
import shared.xml.Race.XMLRace;
|
||||
import shared.xml.XMLUtilities;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
@@ -22,8 +22,6 @@ import javax.xml.transform.TransformerException;
|
||||
import java.io.*;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
|
||||
/**
|
||||
@@ -49,7 +47,7 @@ public class Event {
|
||||
private Event() {
|
||||
try {
|
||||
try {
|
||||
this.raceXML = getRaceXMLAtCurrentTime(RaceXMLCreator.alterRaceToWind("mock/mockXML/raceSchemaTest.xml", 90));
|
||||
this.raceXML = RaceXMLCreator.alterRaceToWind("mock/mockXML/raceSchemaTest.xml", 90);
|
||||
} catch (SAXException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ParserConfigurationException e) {
|
||||
@@ -102,15 +100,16 @@ public class Event {
|
||||
sendXMLs();
|
||||
|
||||
//Parse the XML files into data sources.
|
||||
// RaceDataSource raceDataSource = new RaceXMLReader(this.raceXML, this.xmlFileType);
|
||||
Race race = (Race) XMLUtilities.xmlToClass(raceXML,
|
||||
RaceDataSource raceDataSource = new RaceXMLReader(this.raceXML, this.xmlFileType);
|
||||
//more work here
|
||||
XMLRace race = (XMLRace) XMLUtilities.xmlToClass(raceXML,
|
||||
RaceXMLCreator.class.getClassLoader().getResource("mock/mockXML/schema/raceSchema.xsd"),
|
||||
Race.class);
|
||||
XMLRace.class);
|
||||
BoatDataSource boatDataSource = new BoatXMLReader(this.boatXML, this.xmlFileType);
|
||||
RegattaDataSource regattaDataSource = new RegattaXMLReader(this.regattaXML, this.xmlFileType);
|
||||
|
||||
//Create and start race.
|
||||
MockRace newRace = new MockRace(boatDataSource, race, regattaDataSource, this.latestMessages, this.boatPolars, Constants.RaceTimeScale);
|
||||
MockRace newRace = new MockRace(boatDataSource, raceDataSource, regattaDataSource, this.latestMessages, this.boatPolars, Constants.RaceTimeScale);
|
||||
|
||||
new Thread(newRace).start();
|
||||
}
|
||||
@@ -127,28 +126,5 @@ public class Event {
|
||||
mockOutput.setBoatsXml(boatXML);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the xml description of the race to show the race was created now, and starts in 4 minutes
|
||||
* @param raceXML The race.xml contents.
|
||||
* @return String containing edited xml
|
||||
*/
|
||||
private String getRaceXMLAtCurrentTime(String raceXML) {
|
||||
|
||||
//The start time is current time + 4 minutes. prestart is 3 minutes, and we add another minute.
|
||||
long millisecondsToAdd = Constants.RacePreStartTime + (1 * 60 * 1000);
|
||||
long secondsToAdd = millisecondsToAdd / 1000;
|
||||
//Scale the time using our time scalar.
|
||||
secondsToAdd = secondsToAdd / Constants.RaceTimeScale;
|
||||
|
||||
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ");
|
||||
ZonedDateTime creationTime = ZonedDateTime.now();
|
||||
raceXML = raceXML.replace("CREATION_TIME", dateFormat.format(creationTime));
|
||||
|
||||
raceXML = raceXML.replace("START_TIME", dateFormat.format(creationTime.plusSeconds(secondsToAdd)));
|
||||
|
||||
return raceXML;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user