Refactored mock.Event to work with MockRace.
Fixed the networking imports. Race now keeps a reference to its Race, Boat, and Regatta data sources. VisualiserRace can be provided with new Race/Boat/Regatta data sources during runtime. Currently it updates boundary and legs with a new RaceDataSource, and marker boats with a new BoatDataSource.
This commit is contained in:
@@ -8,6 +8,7 @@ import mock.model.Polars;
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import shared.dataInput.XMLReader;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
@@ -51,7 +52,7 @@ public class App extends Application {
|
||||
* Reads the Initial Race XML files that are necessary to run the mock.
|
||||
* @param path path of the XML
|
||||
* @param encoding encoding of the xml
|
||||
* @return
|
||||
* @return A string containing the contents of the specified file.
|
||||
* @throws IOException No file etc
|
||||
* @throws ParserConfigurationException Issue with the XML formatting
|
||||
* @throws SAXException Issue with XML formatting
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
package mock.app;
|
||||
|
||||
import mock.model.MockRace;
|
||||
import mock.model.Polars;
|
||||
import network.Messages.Enums.MessageType;
|
||||
import org.xml.sax.SAXException;
|
||||
import shared.dataInput.*;
|
||||
import shared.exceptions.InvalidBoatDataException;
|
||||
import shared.exceptions.InvalidRaceDataException;
|
||||
import shared.exceptions.InvalidRegattaDataException;
|
||||
import shared.exceptions.XMLReaderException;
|
||||
import shared.model.Constants;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
@@ -17,11 +23,11 @@ import java.time.format.DateTimeFormatter;
|
||||
*/
|
||||
public class Event {
|
||||
|
||||
String raceXML;
|
||||
String regattaXML;
|
||||
String boatXML;
|
||||
Polars boatPolars;
|
||||
MockOutput mockOutput;
|
||||
private String raceXML;
|
||||
private String regattaXML;
|
||||
private String boatXML;
|
||||
private Polars boatPolars;
|
||||
private MockOutput mockOutput;
|
||||
|
||||
public Event(String raceXML, String regattaXML, String boatXML, Polars boatPolars) {
|
||||
|
||||
@@ -29,6 +35,7 @@ public class Event {
|
||||
this.boatXML = boatXML;
|
||||
this.regattaXML = regattaXML;
|
||||
this.boatPolars = boatPolars;
|
||||
|
||||
try {
|
||||
mockOutput = new MockOutput();
|
||||
new Thread(mockOutput).start();
|
||||
@@ -43,10 +50,18 @@ public class Event {
|
||||
public void start() {
|
||||
try {
|
||||
sendXMLs();
|
||||
Race newRace = new Race(new RaceXMLReader(this.raceXML, new BoatXMLReader(boatXML, this.boatPolars)), mockOutput);
|
||||
new Thread((newRace)).start();
|
||||
|
||||
} catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
|
||||
//Parse the XML files into data sources.
|
||||
RaceDataSource raceDataSource = new RaceXMLReader(this.raceXML);
|
||||
BoatDataSource boatDataSource = new BoatXMLReader(this.boatXML);
|
||||
RegattaDataSource regattaDataSource = new RegattaXMLReader(this.regattaXML);
|
||||
|
||||
//Create and start race.
|
||||
MockRace newRace = new MockRace(boatDataSource, raceDataSource, regattaDataSource, this.boatPolars, this.mockOutput);
|
||||
|
||||
new Thread(newRace).start();
|
||||
|
||||
} catch (XMLReaderException | InvalidBoatDataException | InvalidRaceDataException | InvalidRegattaDataException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user