Moving stuff from school pc to home

This commit is contained in:
Fan-Wu Yang
2017-08-13 23:03:16 +12:00
parent 8999cddf8b
commit 70d5447e88
25 changed files with 4995 additions and 282 deletions
@@ -3,6 +3,7 @@ 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;
@@ -13,6 +14,7 @@ import shared.exceptions.InvalidRaceDataException;
import shared.exceptions.InvalidRegattaDataException;
import shared.exceptions.XMLReaderException;
import shared.model.Constants;
import shared.xml.XMLUtilities;
import javax.xml.bind.JAXBException;
import javax.xml.parsers.ParserConfigurationException;
@@ -53,7 +55,6 @@ public class Event {
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
System.out.println(this.raceXML);
this.boatXML = XMLReader.readXMLFileToString("mock/mockXML/boatsSinglePlayer.xml", StandardCharsets.UTF_8);
this.regattaXML = XMLReader.readXMLFileToString("mock/mockXML/regattaTest.xml", StandardCharsets.UTF_8);
this.xmlFileType = XMLFileType.Contents;
@@ -95,18 +96,21 @@ public class Event {
* @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() throws InvalidRaceDataException, XMLReaderException, InvalidBoatDataException, InvalidRegattaDataException {
public void start() throws InvalidRaceDataException, XMLReaderException, InvalidBoatDataException, InvalidRegattaDataException, ParserConfigurationException, JAXBException, SAXException, IOException {
new Thread(mockOutput).start();
sendXMLs();
//Parse the XML files into data sources.
RaceDataSource raceDataSource = new RaceXMLReader(this.raceXML, this.xmlFileType);
// RaceDataSource raceDataSource = new RaceXMLReader(this.raceXML, this.xmlFileType);
Race race = (Race) XMLUtilities.xmlToClass(raceXML,
RaceXMLCreator.class.getClassLoader().getResource("mock/mockXML/schema/raceSchema.xsd"),
Race.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, raceDataSource, regattaDataSource, this.latestMessages, this.boatPolars, Constants.RaceTimeScale);
MockRace newRace = new MockRace(boatDataSource, race, regattaDataSource, this.latestMessages, this.boatPolars, Constants.RaceTimeScale);
new Thread(newRace).start();
}
@@ -1,6 +1,7 @@
package mock.model;
import javafx.animation.AnimationTimer;
import mock.xml.*;
import network.Messages.BoatLocation;
import network.Messages.BoatStatus;
import network.Messages.Enums.BoatStatusEnum;
@@ -12,6 +13,7 @@ import shared.dataInput.RaceDataSource;
import network.Messages.Enums.RaceStatusEnum;
import shared.dataInput.RegattaDataSource;
import shared.model.*;
import shared.model.Race;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
@@ -88,7 +90,7 @@ public class MockRace extends Race {
* @param polars The polars table to be used for boat simulation.
* @param timeScale The timeScale for the race. See {@link Constants#RaceTimeScale}.
*/
public MockRace(BoatDataSource boatDataSource, RaceDataSource raceDataSource, RegattaDataSource regattaDataSource, LatestMessages latestMessages, Polars polars, int timeScale) {
public MockRace(BoatDataSource boatDataSource, mock.xml.Race raceDataSource, RegattaDataSource regattaDataSource, LatestMessages latestMessages, Polars polars, int timeScale) {
super(boatDataSource, raceDataSource, regattaDataSource, latestMessages);
File diff suppressed because it is too large Load Diff
@@ -2,7 +2,7 @@
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2017.08.03 at 01:07:33 AM NZST
// Generated on: 2017.08.13 at 10:39:29 PM NZST
//
@@ -12,33 +12,33 @@ import javax.xml.bind.annotation.XmlRegistry;
/**
* This object contains factory methods for each
* Java content interface and Java element interface
* generated in the main.java.mock.xml package.
* <p>An ObjectFactory allows you to programatically
* construct new instances of the Java representation
* for XML content. The Java representation of XML
* content can consist of schema derived interfaces
* and classes representing the binding of schema
* type definitions, element declarations and model
* groups. Factory methods for each of these are
* This object contains factory methods for each
* Java content interface and Java element interface
* generated in the scd package.
* <p>An ObjectFactory allows you to programatically
* construct new instances of the Java representation
* for XML content. The Java representation of XML
* content can consist of schema derived interfaces
* and classes representing the binding of schema
* type definitions, element declarations and model
* groups. Factory methods for each of these are
* provided in this class.
*
*
*/
@XmlRegistry
public class RaceFactory {
/**
* Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: main.java.mock.xml
*
* Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: scd
*
*/
public RaceFactory() {
}
/**
* Create an instance of {@link Race }
* @return new Race instance
*
*/
public Race createRace() {
return new Race();
@@ -46,7 +46,7 @@ public class RaceFactory {
/**
* Create an instance of {@link Race.CourseLimit }
* @return new RaceCourseLimit Instance
*
*/
public Race.CourseLimit createRaceCourseLimit() {
return new Race.CourseLimit();
@@ -54,7 +54,7 @@ public class RaceFactory {
/**
* Create an instance of {@link Race.Course }
* @return new Course Instance
*
*/
public Race.Course createRaceCourse() {
return new Race.Course();
@@ -62,7 +62,7 @@ public class RaceFactory {
/**
* Create an instance of {@link Race.Course.CompoundMark }
* @return new CompoundMark Instance
*
*/
public Race.Course.CompoundMark createRaceCourseCompoundMark() {
return new Race.Course.CompoundMark();
@@ -70,7 +70,7 @@ public class RaceFactory {
/**
* Create an instance of {@link Race.CompoundMarkSequence }
* @return new CompoundMarkSequence Instance
*
*/
public Race.CompoundMarkSequence createRaceCompoundMarkSequence() {
return new Race.CompoundMarkSequence();
@@ -78,7 +78,7 @@ public class RaceFactory {
/**
* Create an instance of {@link Race.Participants }
* @return new Race.Participants Instance
*
*/
public Race.Participants createRaceParticipants() {
return new Race.Participants();
@@ -86,7 +86,7 @@ public class RaceFactory {
/**
* Create an instance of {@link Race.RaceStartTime }
* @return new RaceStartTime instance
*
*/
public Race.RaceStartTime createRaceRaceStartTime() {
return new Race.RaceStartTime();
@@ -94,7 +94,7 @@ public class RaceFactory {
/**
* Create an instance of {@link Race.CourseLimit.Limit }
* @return new Limit instance
*
*/
public Race.CourseLimit.Limit createRaceCourseLimitLimit() {
return new Race.CourseLimit.Limit();
@@ -102,7 +102,7 @@ public class RaceFactory {
/**
* Create an instance of {@link Race.Course.CompoundMark.Mark }
* @return new CompoundMark.Mark instance
*
*/
public Race.Course.CompoundMark.Mark createRaceCourseCompoundMarkMark() {
return new Race.Course.CompoundMark.Mark();
@@ -110,7 +110,7 @@ public class RaceFactory {
/**
* Create an instance of {@link Race.CompoundMarkSequence.Corner }
* @return new Race.CompoundMarkSequence.Corner instance
*
*/
public Race.CompoundMarkSequence.Corner createRaceCompoundMarkSequenceCorner() {
return new Race.CompoundMarkSequence.Corner();
@@ -118,10 +118,10 @@ public class RaceFactory {
/**
* Create an instance of {@link Race.Participants.Yacht }
* @return new Race.Participants.Yacht Instance.
*
*/
public Race.Participants.Yacht createRaceParticipantsYacht() {
return new Race.Participants.Yacht();
}
}
}
@@ -10,6 +10,7 @@ import shared.model.CompoundMark;
import shared.model.Corner;
import shared.model.GPSCoordinate;
import shared.model.Mark;
import shared.xml.XMLUtilities;
import javax.xml.XMLConstants;
import javax.xml.bind.JAXBContext;
@@ -157,7 +158,9 @@ public class RaceXMLCreator {
public static String alterRaceToWind(String s, double degrees) throws XMLReaderException, InvalidRaceDataException, JAXBException, IOException, SAXException, ParserConfigurationException {
RaceXMLReader reader = new RaceXMLReader(s, XMLFileType.ResourcePath);
Race race = readRace(RaceXMLCreator.class.getClassLoader().getResource(s).getFile());
Race race = (Race) XMLUtilities.xmlToClass(new File(RaceXMLCreator.class.getClassLoader().getResource(s).getFile()),
RaceXMLCreator.class.getClassLoader().getResource("mock/mockXML/schema/raceSchema.xsd"),
Race.class);
double raceOriginalBearing = getLineAngle(getLeewardGate(reader).getMark1Position(), getWindwardGate(reader).getMark1Position());
@@ -262,33 +265,4 @@ public class RaceXMLCreator {
return Math.atan2(dy, dx)/Math.PI * 180;
}
public static Race readRace(String file) throws IOException, SAXException, JAXBException, ParserConfigurationException {
//validateRace(file);
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = parser.parse(new File(file));
JAXBContext jc = JAXBContext.newInstance(Race.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
URL schemaURL = RaceXMLCreator.class.getClassLoader().getResource("mock/mockXML/schema/raceSchema.xsd");// The URL to your XML Schema;
Schema schema = sf.newSchema(schemaURL);
unmarshaller.setSchema(schema);
return (Race) unmarshaller.unmarshal(new DOMSource(document));
}
public static boolean validateRace(String file) throws SAXException, IOException, ParserConfigurationException {
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = parser.parse(new File(file));
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
URL schemaURL = RaceXMLCreator.class.getClassLoader().getResource("mock/mockXML/schema/raceSchema.xsd");// The URL to your XML Schema;
Schema schema = sf.newSchema(schemaURL);
Validator validator = schema.newValidator();
validator.validate(new DOMSource(document));
return true;
}
}
@@ -23,7 +23,7 @@ public abstract class Race implements Runnable {
/**
* The source of race related data.
*/
protected RaceDataSource raceDataSource;
protected mock.xml.Race raceDataSource;
/**
* The source of boat related data.
@@ -134,7 +134,7 @@ public abstract class Race implements Runnable {
* @param regattaDataSource Data source for race related data (course name, location, timezone, etc...).
* @param latestMessages The collection of latest messages, which can be written to, or read from.
*/
public Race(BoatDataSource boatDataSource, RaceDataSource raceDataSource, RegattaDataSource regattaDataSource, LatestMessages latestMessages) {
public Race(BoatDataSource boatDataSource, mock.xml.Race raceDataSource, RegattaDataSource regattaDataSource, LatestMessages latestMessages) {
//Keep a reference to data sources.
this.raceDataSource = raceDataSource;
@@ -1,9 +1,26 @@
package shared.xml;
import mock.xml.Race;
import mock.xml.RaceXMLCreator;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import javax.xml.XMLConstants;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.dom.DOMSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.net.URL;
/**
* Created by fwy13 on 13/08/17.
@@ -21,16 +38,49 @@ public class XMLUtilities {
return sw.toString();
}
public static String xmlToClass(){
// JAXBContext jc = JAXBContext.newInstance(YourXMLClass.class);
// Unmarshaller unmarshaller = jc.createUnmarshaller();
//
// SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
// URL schemaURL = // The URL to your XML Schema;
// Schema schema = sf.newSchema(schemaURL);
// unmarshaller.setSchema(schema);
//
// YourXMLClass yourXMLClass = (YourXMLClass) unmarshaller.unmarshal(xml);
public static Object xmlToClass(File file, URL schemaURL, Class c) throws ParserConfigurationException, IOException, SAXException, JAXBException {
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = parser.parse(file);
return xmlToClass(document, schemaURL, c);
}
public static Object xmlToClass(String xml, URL schemaURL, Class c) throws ParserConfigurationException, IOException, SAXException, JAXBException {
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = parser.parse(xml);
return xmlToClass(document, schemaURL, c);
}
public static Object xmlToClass(Document document, URL schemaURL, Class c) throws ParserConfigurationException, IOException, SAXException, JAXBException {
JAXBContext jc = JAXBContext.newInstance(c);
Unmarshaller unmarshaller = jc.createUnmarshaller();
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = sf.newSchema(schemaURL);
unmarshaller.setSchema(schema);
return unmarshaller.unmarshal(new DOMSource(document));
}
public static boolean validateXML(String file, URL schemaURL){
try {
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = parser.parse(new File(file));
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = sf.newSchema(schemaURL);
Validator validator = schema.newValidator();
validator.validate(new DOMSource(document));
} catch (ParserConfigurationException e) {
return false;
} catch (IOException e) {
return false;
} catch (SAXException e) {
return false;
}
return true;
}
}