mock.app.App now tells mock.app.Event that the xml file strings are XMLFileType.Contents.
Made network.MessageEncoders.RaceVisionByteEncoder methods static (they were effectively static already). shared.dataInput.XMLReader#readXMLFileToString(..) now throws an XMLReaderException if the file cannot be found. visualiser.Controllers.StartController assumed XML messages were resource paths instead of file contents - fixed. Testing: networking tests now work again.
This commit is contained in:
@@ -9,6 +9,7 @@ import org.w3c.dom.Document;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import shared.dataInput.XMLReader;
|
||||
import shared.enums.XMLFileType;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
@@ -38,7 +39,7 @@ public class App extends Application {
|
||||
String raceXML = XMLReader.readXMLFileToString("mock/mockXML/raceTest.xml", StandardCharsets.UTF_8);
|
||||
String boatXML = XMLReader.readXMLFileToString("mock/mockXML/boatTest.xml", StandardCharsets.UTF_8);
|
||||
|
||||
Event raceEvent = new Event(raceXML, regattaXML, boatXML, boatPolars);
|
||||
Event raceEvent = new Event(raceXML, regattaXML, boatXML, XMLFileType.Contents, boatPolars);
|
||||
raceEvent.start();
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -2,11 +2,7 @@ package mock.app;
|
||||
|
||||
import mock.model.MockRace;
|
||||
import mock.model.Polars;
|
||||
import network.Messages.Enums.MessageType;
|
||||
import network.Messages.Enums.XMLMessageType;
|
||||
import network.Messages.LatestMessages;
|
||||
import network.Messages.XMLMessage;
|
||||
import org.xml.sax.SAXException;
|
||||
import shared.dataInput.*;
|
||||
import shared.enums.XMLFileType;
|
||||
import shared.exceptions.InvalidBoatDataException;
|
||||
@@ -15,9 +11,7 @@ import shared.exceptions.InvalidRegattaDataException;
|
||||
import shared.exceptions.XMLReaderException;
|
||||
import shared.model.Constants;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
@@ -30,16 +24,31 @@ public class Event {
|
||||
private String raceXML;
|
||||
private String regattaXML;
|
||||
private String boatXML;
|
||||
|
||||
private XMLFileType xmlFileType;
|
||||
|
||||
private Polars boatPolars;
|
||||
|
||||
private MockOutput mockOutput;
|
||||
private LatestMessages latestMessages;
|
||||
|
||||
|
||||
public Event(String raceXML, String regattaXML, String boatXML, Polars boatPolars) {
|
||||
/**
|
||||
* Constructs an event, using various XML files.
|
||||
* @param raceXML The race.xml file.
|
||||
* @param regattaXML The regatta.xml file.
|
||||
* @param boatXML The boat.xml file.
|
||||
* @param type How to read the file - e.g., load as resource.
|
||||
* @param boatPolars
|
||||
*/
|
||||
public Event(String raceXML, String regattaXML, String boatXML, XMLFileType type, Polars boatPolars) {
|
||||
|
||||
this.raceXML = getRaceXMLAtCurrentTime(raceXML);
|
||||
this.boatXML = boatXML;
|
||||
this.regattaXML = regattaXML;
|
||||
|
||||
this.xmlFileType = type;
|
||||
|
||||
this.boatPolars = boatPolars;
|
||||
|
||||
this.latestMessages = new LatestMessages();
|
||||
@@ -55,26 +64,26 @@ public class Event {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the initial race data and then begins race simulation
|
||||
* Sends the initial race data and then begins race simulation.
|
||||
* @throws InvalidRaceDataException Thrown if the race xml file cannot be parsed.
|
||||
* @throws XMLReaderException Thrown if any of the xml files cannot be parsed.
|
||||
* @throws InvalidBoatDataException Thrown if the boat xml file cannot be parsed.
|
||||
* @throws InvalidRegattaDataException Thrown if the regatta xml file cannot be parsed.
|
||||
*/
|
||||
public void start() {
|
||||
try {
|
||||
sendXMLs();
|
||||
public void start() throws InvalidRaceDataException, XMLReaderException, InvalidBoatDataException, InvalidRegattaDataException {
|
||||
|
||||
//Parse the XML files into data sources.
|
||||
RaceDataSource raceDataSource = new RaceXMLReader(this.raceXML, XMLFileType.ResourcePath);
|
||||
BoatDataSource boatDataSource = new BoatXMLReader(this.boatXML, XMLFileType.ResourcePath);
|
||||
RegattaDataSource regattaDataSource = new RegattaXMLReader(this.regattaXML, XMLFileType.ResourcePath);
|
||||
sendXMLs();
|
||||
|
||||
//Create and start race.
|
||||
MockRace newRace = new MockRace(boatDataSource, raceDataSource, regattaDataSource, this.latestMessages, this.boatPolars, Constants.RaceTimeScale);
|
||||
//Parse the XML files into data sources.
|
||||
RaceDataSource raceDataSource = new RaceXMLReader(this.raceXML, this.xmlFileType);
|
||||
BoatDataSource boatDataSource = new BoatXMLReader(this.boatXML, this.xmlFileType);
|
||||
RegattaDataSource regattaDataSource = new RegattaXMLReader(this.regattaXML, this.xmlFileType);
|
||||
|
||||
new Thread(newRace).start();
|
||||
//Create and start race.
|
||||
MockRace newRace = new MockRace(boatDataSource, raceDataSource, regattaDataSource, this.latestMessages, this.boatPolars, Constants.RaceTimeScale);
|
||||
|
||||
new Thread(newRace).start();
|
||||
|
||||
} catch (XMLReaderException | InvalidBoatDataException | InvalidRaceDataException | InvalidRegattaDataException e) {
|
||||
e.printStackTrace();
|
||||
//TODO if this occurs, we should print and error and abort.
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user