Pre merge commit

main
Fan-Wu Yang 8 years ago
commit 8999cddf8b

@ -1,3 +0,0 @@
<component name="CopyrightManager">
<settings default="" />
</component>

@ -5,6 +5,7 @@ import mock.model.MockRace;
import mock.model.Polars; import mock.model.Polars;
import mock.xml.RaceXMLCreator; import mock.xml.RaceXMLCreator;
import network.Messages.LatestMessages; import network.Messages.LatestMessages;
import org.xml.sax.SAXException;
import shared.dataInput.*; import shared.dataInput.*;
import shared.enums.XMLFileType; import shared.enums.XMLFileType;
import shared.exceptions.InvalidBoatDataException; import shared.exceptions.InvalidBoatDataException;
@ -14,6 +15,7 @@ import shared.exceptions.XMLReaderException;
import shared.model.Constants; import shared.model.Constants;
import javax.xml.bind.JAXBException; import javax.xml.bind.JAXBException;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerException;
import java.io.*; import java.io.*;
import java.net.UnknownHostException; import java.net.UnknownHostException;
@ -43,8 +45,14 @@ public class Event {
* Constructs an event, using various XML files. * Constructs an event, using various XML files.
*/ */
private Event() { private Event() {
try {
try { try {
this.raceXML = getRaceXMLAtCurrentTime(RaceXMLCreator.alterRaceToWind("mock/mockXML/raceSchemaTest.xml", 90)); this.raceXML = getRaceXMLAtCurrentTime(RaceXMLCreator.alterRaceToWind("mock/mockXML/raceSchemaTest.xml", 90));
} catch (SAXException e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
System.out.println(this.raceXML); System.out.println(this.raceXML);
this.boatXML = XMLReader.readXMLFileToString("mock/mockXML/boatsSinglePlayer.xml", StandardCharsets.UTF_8); this.boatXML = XMLReader.readXMLFileToString("mock/mockXML/boatsSinglePlayer.xml", StandardCharsets.UTF_8);
this.regattaXML = XMLReader.readXMLFileToString("mock/mockXML/regattaTest.xml", StandardCharsets.UTF_8); this.regattaXML = XMLReader.readXMLFileToString("mock/mockXML/regattaTest.xml", StandardCharsets.UTF_8);

@ -24,122 +24,122 @@ import javax.xml.bind.annotation.XmlType;
* <p>The following schema fragment specifies the expected content contained within this class. * <p>The following schema fragment specifies the expected content contained within this class.
* *
* <pre> * <pre>
* &lt;complexType> * &lt;complexType&gt;
* &lt;complexContent> * &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;sequence> * &lt;sequence&gt;
* &lt;element name="RaceID" type="{http://www.w3.org/2001/XMLSchema}string"/> * &lt;element name="RaceID" type="{http://www.w3.org/2001/XMLSchema}string"/&gt;
* &lt;element name="RaceType" type="{http://www.w3.org/2001/XMLSchema}string"/> * &lt;element name="RaceType" type="{http://www.w3.org/2001/XMLSchema}string"/&gt;
* &lt;element name="CreationTimeDate" type="{http://www.w3.org/2001/XMLSchema}string"/> * &lt;element name="CreationTimeDate" type="{http://www.w3.org/2001/XMLSchema}string"/&gt;
* &lt;element name="RaceStartTime"> * &lt;element name="RaceStartTime"&gt;
* &lt;complexType> * &lt;complexType&gt;
* &lt;complexContent> * &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;attribute name="Postpone" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="Postpone" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;attribute name="Time" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="Time" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;/restriction> * &lt;/restriction&gt;
* &lt;/complexContent> * &lt;/complexContent&gt;
* &lt;/complexType> * &lt;/complexType&gt;
* &lt;/element> * &lt;/element&gt;
* &lt;element name="Participants"> * &lt;element name="Participants"&gt;
* &lt;complexType> * &lt;complexType&gt;
* &lt;complexContent> * &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;sequence> * &lt;sequence&gt;
* &lt;element name="Yacht" maxOccurs="unbounded"> * &lt;element name="Yacht" maxOccurs="unbounded"&gt;
* &lt;complexType> * &lt;complexType&gt;
* &lt;complexContent> * &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;attribute name="SourceID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="SourceID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;/restriction> * &lt;/restriction&gt;
* &lt;/complexContent> * &lt;/complexContent&gt;
* &lt;/complexType> * &lt;/complexType&gt;
* &lt;/element> * &lt;/element&gt;
* &lt;/sequence> * &lt;/sequence&gt;
* &lt;/restriction> * &lt;/restriction&gt;
* &lt;/complexContent> * &lt;/complexContent&gt;
* &lt;/complexType> * &lt;/complexType&gt;
* &lt;/element> * &lt;/element&gt;
* &lt;element name="CompoundMarkSequence"> * &lt;element name="CompoundMarkSequence"&gt;
* &lt;complexType> * &lt;complexType&gt;
* &lt;complexContent> * &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;sequence> * &lt;sequence&gt;
* &lt;element name="Corner" maxOccurs="unbounded"> * &lt;element name="Corner" maxOccurs="unbounded"&gt;
* &lt;complexType> * &lt;complexType&gt;
* &lt;complexContent> * &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;attribute name="CompoundMarkID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="CompoundMarkID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;attribute name="SeqID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="SeqID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;/restriction> * &lt;/restriction&gt;
* &lt;/complexContent> * &lt;/complexContent&gt;
* &lt;/complexType> * &lt;/complexType&gt;
* &lt;/element> * &lt;/element&gt;
* &lt;/sequence> * &lt;/sequence&gt;
* &lt;/restriction> * &lt;/restriction&gt;
* &lt;/complexContent> * &lt;/complexContent&gt;
* &lt;/complexType> * &lt;/complexType&gt;
* &lt;/element> * &lt;/element&gt;
* &lt;element name="Course"> * &lt;element name="Course"&gt;
* &lt;complexType> * &lt;complexType&gt;
* &lt;complexContent> * &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;sequence> * &lt;sequence&gt;
* &lt;element name="CompoundMark" maxOccurs="unbounded"> * &lt;element name="CompoundMark" maxOccurs="unbounded"&gt;
* &lt;complexType> * &lt;complexType&gt;
* &lt;complexContent> * &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;sequence> * &lt;sequence&gt;
* &lt;element name="Mark" maxOccurs="unbounded"> * &lt;element name="Mark" maxOccurs="unbounded"&gt;
* &lt;complexType> * &lt;complexType&gt;
* &lt;complexContent> * &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;attribute name="SeqId" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="SeqId" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;attribute name="Name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="Name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;attribute name="TargetLat" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="TargetLat" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;attribute name="TargetLng" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="TargetLng" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;attribute name="SourceID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="SourceID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;/restriction> * &lt;/restriction&gt;
* &lt;/complexContent> * &lt;/complexContent&gt;
* &lt;/complexType> * &lt;/complexType&gt;
* &lt;/element> * &lt;/element&gt;
* &lt;/sequence> * &lt;/sequence&gt;
* &lt;attribute name="CompoundMarkID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="CompoundMarkID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;attribute name="Name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="Name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;/restriction> * &lt;/restriction&gt;
* &lt;/complexContent> * &lt;/complexContent&gt;
* &lt;/complexType> * &lt;/complexType&gt;
* &lt;/element> * &lt;/element&gt;
* &lt;/sequence> * &lt;/sequence&gt;
* &lt;/restriction> * &lt;/restriction&gt;
* &lt;/complexContent> * &lt;/complexContent&gt;
* &lt;/complexType> * &lt;/complexType&gt;
* &lt;/element> * &lt;/element&gt;
* &lt;element name="CourseLimit"> * &lt;element name="CourseLimit"&gt;
* &lt;complexType> * &lt;complexType&gt;
* &lt;complexContent> * &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;sequence> * &lt;sequence&gt;
* &lt;element name="Limit" maxOccurs="unbounded"> * &lt;element name="Limit" maxOccurs="unbounded"&gt;
* &lt;complexType> * &lt;complexType&gt;
* &lt;complexContent> * &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;attribute name="Lat" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="Lat" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;attribute name="Lon" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="Lon" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;attribute name="SeqID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="SeqID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;/restriction> * &lt;/restriction&gt;
* &lt;/complexContent> * &lt;/complexContent&gt;
* &lt;/complexType> * &lt;/complexType&gt;
* &lt;/element> * &lt;/element&gt;
* &lt;/sequence> * &lt;/sequence&gt;
* &lt;/restriction> * &lt;/restriction&gt;
* &lt;/complexContent> * &lt;/complexContent&gt;
* &lt;/complexType> * &lt;/complexType&gt;
* &lt;/element> * &lt;/element&gt;
* &lt;/sequence> * &lt;/sequence&gt;
* &lt;/restriction> * &lt;/restriction&gt;
* &lt;/complexContent> * &lt;/complexContent&gt;
* &lt;/complexType> * &lt;/complexType&gt;
* </pre> * </pre>
* *
* *
@ -374,24 +374,24 @@ public class Race {
* <p>The following schema fragment specifies the expected content contained within this class. * <p>The following schema fragment specifies the expected content contained within this class.
* *
* <pre> * <pre>
* &lt;complexType> * &lt;complexType&gt;
* &lt;complexContent> * &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;sequence> * &lt;sequence&gt;
* &lt;element name="Corner" maxOccurs="unbounded"> * &lt;element name="Corner" maxOccurs="unbounded"&gt;
* &lt;complexType> * &lt;complexType&gt;
* &lt;complexContent> * &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;attribute name="CompoundMarkID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="CompoundMarkID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;attribute name="SeqID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="SeqID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;/restriction> * &lt;/restriction&gt;
* &lt;/complexContent> * &lt;/complexContent&gt;
* &lt;/complexType> * &lt;/complexType&gt;
* &lt;/element> * &lt;/element&gt;
* &lt;/sequence> * &lt;/sequence&gt;
* &lt;/restriction> * &lt;/restriction&gt;
* &lt;/complexContent> * &lt;/complexContent&gt;
* &lt;/complexType> * &lt;/complexType&gt;
* </pre> * </pre>
* *
* *
@ -424,7 +424,7 @@ public class Race {
* <p> * <p>
* Objects of the following type(s) are allowed in the list * Objects of the following type(s) are allowed in the list
* {@link Race.CompoundMarkSequence.Corner } * {@link Race.CompoundMarkSequence.Corner }
* * @return corners in the CompoundMarkSequence.
* *
*/ */
public List<Race.CompoundMarkSequence.Corner> getCorner() { public List<Race.CompoundMarkSequence.Corner> getCorner() {
@ -441,14 +441,14 @@ public class Race {
* <p>The following schema fragment specifies the expected content contained within this class. * <p>The following schema fragment specifies the expected content contained within this class.
* *
* <pre> * <pre>
* &lt;complexType> * &lt;complexType&gt;
* &lt;complexContent> * &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;attribute name="CompoundMarkID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="CompoundMarkID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;attribute name="SeqID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="SeqID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;/restriction> * &lt;/restriction&gt;
* &lt;/complexContent> * &lt;/complexContent&gt;
* &lt;/complexType> * &lt;/complexType&gt;
* </pre> * </pre>
* *
* *
@ -521,39 +521,39 @@ public class Race {
* <p>The following schema fragment specifies the expected content contained within this class. * <p>The following schema fragment specifies the expected content contained within this class.
* *
* <pre> * <pre>
* &lt;complexType> * &lt;complexType&gt;
* &lt;complexContent> * &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;sequence> * &lt;sequence&gt;
* &lt;element name="CompoundMark" maxOccurs="unbounded"> * &lt;element name="CompoundMark" maxOccurs="unbounded"&gt;
* &lt;complexType> * &lt;complexType&gt;
* &lt;complexContent> * &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;sequence> * &lt;sequence&gt;
* &lt;element name="Mark" maxOccurs="unbounded"> * &lt;element name="Mark" maxOccurs="unbounded"&gt;
* &lt;complexType> * &lt;complexType&gt;
* &lt;complexContent> * &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;attribute name="SeqId" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="SeqId" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;attribute name="Name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="Name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;attribute name="TargetLat" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="TargetLat" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;attribute name="TargetLng" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="TargetLng" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;attribute name="SourceID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="SourceID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;/restriction> * &lt;/restriction&gt;
* &lt;/complexContent> * &lt;/complexContent&gt;
* &lt;/complexType> * &lt;/complexType&gt;
* &lt;/element> * &lt;/element&gt;
* &lt;/sequence> * &lt;/sequence&gt;
* &lt;attribute name="CompoundMarkID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="CompoundMarkID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;attribute name="Name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="Name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;/restriction> * &lt;/restriction&gt;
* &lt;/complexContent> * &lt;/complexContent&gt;
* &lt;/complexType> * &lt;/complexType&gt;
* &lt;/element> * &lt;/element&gt;
* &lt;/sequence> * &lt;/sequence&gt;
* &lt;/restriction> * &lt;/restriction&gt;
* &lt;/complexContent> * &lt;/complexContent&gt;
* &lt;/complexType> * &lt;/complexType&gt;
* </pre> * </pre>
* *
* *
@ -586,7 +586,7 @@ public class Race {
* <p> * <p>
* Objects of the following type(s) are allowed in the list * Objects of the following type(s) are allowed in the list
* {@link Race.Course.CompoundMark } * {@link Race.Course.CompoundMark }
* * @return CompoundMarks in a Course
* *
*/ */
public List<Race.Course.CompoundMark> getCompoundMark() { public List<Race.Course.CompoundMark> getCompoundMark() {
@ -603,29 +603,29 @@ public class Race {
* <p>The following schema fragment specifies the expected content contained within this class. * <p>The following schema fragment specifies the expected content contained within this class.
* *
* <pre> * <pre>
* &lt;complexType> * &lt;complexType&gt;
* &lt;complexContent> * &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;sequence> * &lt;sequence&gt;
* &lt;element name="Mark" maxOccurs="unbounded"> * &lt;element name="Mark" maxOccurs="unbounded"&gt;
* &lt;complexType> * &lt;complexType&gt;
* &lt;complexContent> * &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;attribute name="SeqId" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="SeqId" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;attribute name="Name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="Name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;attribute name="TargetLat" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="TargetLat" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;attribute name="TargetLng" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="TargetLng" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;attribute name="SourceID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="SourceID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;/restriction> * &lt;/restriction&gt;
* &lt;/complexContent> * &lt;/complexContent&gt;
* &lt;/complexType> * &lt;/complexType&gt;
* &lt;/element> * &lt;/element&gt;
* &lt;/sequence> * &lt;/sequence&gt;
* &lt;attribute name="CompoundMarkID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="CompoundMarkID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;attribute name="Name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="Name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;/restriction> * &lt;/restriction&gt;
* &lt;/complexContent> * &lt;/complexContent&gt;
* &lt;/complexType> * &lt;/complexType&gt;
* </pre> * </pre>
* *
* *
@ -662,7 +662,7 @@ public class Race {
* <p> * <p>
* Objects of the following type(s) are allowed in the list * Objects of the following type(s) are allowed in the list
* {@link Race.Course.CompoundMark.Mark } * {@link Race.Course.CompoundMark.Mark }
* * @return Marks in a CompoundMark
* *
*/ */
public List<Race.Course.CompoundMark.Mark> getMark() { public List<Race.Course.CompoundMark.Mark> getMark() {
@ -727,17 +727,17 @@ public class Race {
* <p>The following schema fragment specifies the expected content contained within this class. * <p>The following schema fragment specifies the expected content contained within this class.
* *
* <pre> * <pre>
* &lt;complexType> * &lt;complexType&gt;
* &lt;complexContent> * &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;attribute name="SeqId" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="SeqId" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;attribute name="Name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="Name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;attribute name="TargetLat" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="TargetLat" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;attribute name="TargetLng" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="TargetLng" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;attribute name="SourceID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="SourceID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;/restriction> * &lt;/restriction&gt;
* &lt;/complexContent> * &lt;/complexContent&gt;
* &lt;/complexType> * &lt;/complexType&gt;
* </pre> * </pre>
* *
* *
@ -890,25 +890,25 @@ public class Race {
* <p>The following schema fragment specifies the expected content contained within this class. * <p>The following schema fragment specifies the expected content contained within this class.
* *
* <pre> * <pre>
* &lt;complexType> * &lt;complexType&gt;
* &lt;complexContent> * &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;sequence> * &lt;sequence&gt;
* &lt;element name="Limit" maxOccurs="unbounded"> * &lt;element name="Limit" maxOccurs="unbounded"&gt;
* &lt;complexType> * &lt;complexType&gt;
* &lt;complexContent> * &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;attribute name="Lat" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="Lat" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;attribute name="Lon" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="Lon" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;attribute name="SeqID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="SeqID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;/restriction> * &lt;/restriction&gt;
* &lt;/complexContent> * &lt;/complexContent&gt;
* &lt;/complexType> * &lt;/complexType&gt;
* &lt;/element> * &lt;/element&gt;
* &lt;/sequence> * &lt;/sequence&gt;
* &lt;/restriction> * &lt;/restriction&gt;
* &lt;/complexContent> * &lt;/complexContent&gt;
* &lt;/complexType> * &lt;/complexType&gt;
* </pre> * </pre>
* *
* *
@ -941,7 +941,7 @@ public class Race {
* <p> * <p>
* Objects of the following type(s) are allowed in the list * Objects of the following type(s) are allowed in the list
* {@link Race.CourseLimit.Limit } * {@link Race.CourseLimit.Limit }
* * @return Limits in CourseLimits
* *
*/ */
public List<Race.CourseLimit.Limit> getLimit() { public List<Race.CourseLimit.Limit> getLimit() {
@ -958,15 +958,15 @@ public class Race {
* <p>The following schema fragment specifies the expected content contained within this class. * <p>The following schema fragment specifies the expected content contained within this class.
* *
* <pre> * <pre>
* &lt;complexType> * &lt;complexType&gt;
* &lt;complexContent> * &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;attribute name="Lat" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="Lat" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;attribute name="Lon" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="Lon" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;attribute name="SeqID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="SeqID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;/restriction> * &lt;/restriction&gt;
* &lt;/complexContent> * &lt;/complexContent&gt;
* &lt;/complexType> * &lt;/complexType&gt;
* </pre> * </pre>
* *
* *
@ -1065,23 +1065,23 @@ public class Race {
* <p>The following schema fragment specifies the expected content contained within this class. * <p>The following schema fragment specifies the expected content contained within this class.
* *
* <pre> * <pre>
* &lt;complexType> * &lt;complexType&gt;
* &lt;complexContent> * &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;sequence> * &lt;sequence&gt;
* &lt;element name="Yacht" maxOccurs="unbounded"> * &lt;element name="Yacht" maxOccurs="unbounded"&gt;
* &lt;complexType> * &lt;complexType&gt;
* &lt;complexContent> * &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;attribute name="SourceID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="SourceID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;/restriction> * &lt;/restriction&gt;
* &lt;/complexContent> * &lt;/complexContent&gt;
* &lt;/complexType> * &lt;/complexType&gt;
* &lt;/element> * &lt;/element&gt;
* &lt;/sequence> * &lt;/sequence&gt;
* &lt;/restriction> * &lt;/restriction&gt;
* &lt;/complexContent> * &lt;/complexContent&gt;
* &lt;/complexType> * &lt;/complexType&gt;
* </pre> * </pre>
* *
* *
@ -1114,7 +1114,7 @@ public class Race {
* <p> * <p>
* Objects of the following type(s) are allowed in the list * Objects of the following type(s) are allowed in the list
* {@link Race.Participants.Yacht } * {@link Race.Participants.Yacht }
* * @return yachts in a race.
* *
*/ */
public List<Race.Participants.Yacht> getYacht() { public List<Race.Participants.Yacht> getYacht() {
@ -1131,13 +1131,13 @@ public class Race {
* <p>The following schema fragment specifies the expected content contained within this class. * <p>The following schema fragment specifies the expected content contained within this class.
* *
* <pre> * <pre>
* &lt;complexType> * &lt;complexType&gt;
* &lt;complexContent> * &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;attribute name="SourceID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="SourceID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;/restriction> * &lt;/restriction&gt;
* &lt;/complexContent> * &lt;/complexContent&gt;
* &lt;/complexType> * &lt;/complexType&gt;
* </pre> * </pre>
* *
* *
@ -1184,14 +1184,14 @@ public class Race {
* <p>The following schema fragment specifies the expected content contained within this class. * <p>The following schema fragment specifies the expected content contained within this class.
* *
* <pre> * <pre>
* &lt;complexType> * &lt;complexType&gt;
* &lt;complexContent> * &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;attribute name="Postpone" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="Postpone" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;attribute name="Time" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="Time" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;/restriction> * &lt;/restriction&gt;
* &lt;/complexContent> * &lt;/complexContent&gt;
* &lt;/complexType> * &lt;/complexType&gt;
* </pre> * </pre>
* *
* *

@ -38,7 +38,7 @@ public class RaceFactory {
/** /**
* Create an instance of {@link Race } * Create an instance of {@link Race }
* * @return new Race instance
*/ */
public Race createRace() { public Race createRace() {
return new Race(); return new Race();
@ -46,7 +46,7 @@ public class RaceFactory {
/** /**
* Create an instance of {@link Race.CourseLimit } * Create an instance of {@link Race.CourseLimit }
* * @return new RaceCourseLimit Instance
*/ */
public Race.CourseLimit createRaceCourseLimit() { public Race.CourseLimit createRaceCourseLimit() {
return new Race.CourseLimit(); return new Race.CourseLimit();
@ -54,7 +54,7 @@ public class RaceFactory {
/** /**
* Create an instance of {@link Race.Course } * Create an instance of {@link Race.Course }
* * @return new Course Instance
*/ */
public Race.Course createRaceCourse() { public Race.Course createRaceCourse() {
return new Race.Course(); return new Race.Course();
@ -62,7 +62,7 @@ public class RaceFactory {
/** /**
* Create an instance of {@link Race.Course.CompoundMark } * Create an instance of {@link Race.Course.CompoundMark }
* * @return new CompoundMark Instance
*/ */
public Race.Course.CompoundMark createRaceCourseCompoundMark() { public Race.Course.CompoundMark createRaceCourseCompoundMark() {
return new Race.Course.CompoundMark(); return new Race.Course.CompoundMark();
@ -70,7 +70,7 @@ public class RaceFactory {
/** /**
* Create an instance of {@link Race.CompoundMarkSequence } * Create an instance of {@link Race.CompoundMarkSequence }
* * @return new CompoundMarkSequence Instance
*/ */
public Race.CompoundMarkSequence createRaceCompoundMarkSequence() { public Race.CompoundMarkSequence createRaceCompoundMarkSequence() {
return new Race.CompoundMarkSequence(); return new Race.CompoundMarkSequence();
@ -78,7 +78,7 @@ public class RaceFactory {
/** /**
* Create an instance of {@link Race.Participants } * Create an instance of {@link Race.Participants }
* * @return new Race.Participants Instance
*/ */
public Race.Participants createRaceParticipants() { public Race.Participants createRaceParticipants() {
return new Race.Participants(); return new Race.Participants();
@ -86,7 +86,7 @@ public class RaceFactory {
/** /**
* Create an instance of {@link Race.RaceStartTime } * Create an instance of {@link Race.RaceStartTime }
* * @return new RaceStartTime instance
*/ */
public Race.RaceStartTime createRaceRaceStartTime() { public Race.RaceStartTime createRaceRaceStartTime() {
return new Race.RaceStartTime(); return new Race.RaceStartTime();
@ -94,7 +94,7 @@ public class RaceFactory {
/** /**
* Create an instance of {@link Race.CourseLimit.Limit } * Create an instance of {@link Race.CourseLimit.Limit }
* * @return new Limit instance
*/ */
public Race.CourseLimit.Limit createRaceCourseLimitLimit() { public Race.CourseLimit.Limit createRaceCourseLimitLimit() {
return new Race.CourseLimit.Limit(); return new Race.CourseLimit.Limit();
@ -102,7 +102,7 @@ public class RaceFactory {
/** /**
* Create an instance of {@link Race.Course.CompoundMark.Mark } * Create an instance of {@link Race.Course.CompoundMark.Mark }
* * @return new CompoundMark.Mark instance
*/ */
public Race.Course.CompoundMark.Mark createRaceCourseCompoundMarkMark() { public Race.Course.CompoundMark.Mark createRaceCourseCompoundMarkMark() {
return new Race.Course.CompoundMark.Mark(); return new Race.Course.CompoundMark.Mark();
@ -110,7 +110,7 @@ public class RaceFactory {
/** /**
* Create an instance of {@link Race.CompoundMarkSequence.Corner } * Create an instance of {@link Race.CompoundMarkSequence.Corner }
* * @return new Race.CompoundMarkSequence.Corner instance
*/ */
public Race.CompoundMarkSequence.Corner createRaceCompoundMarkSequenceCorner() { public Race.CompoundMarkSequence.Corner createRaceCompoundMarkSequenceCorner() {
return new Race.CompoundMarkSequence.Corner(); return new Race.CompoundMarkSequence.Corner();
@ -118,7 +118,7 @@ public class RaceFactory {
/** /**
* Create an instance of {@link Race.Participants.Yacht } * Create an instance of {@link Race.Participants.Yacht }
* * @return new Race.Participants.Yacht Instance.
*/ */
public Race.Participants.Yacht createRaceParticipantsYacht() { public Race.Participants.Yacht createRaceParticipantsYacht() {
return new Race.Participants.Yacht(); return new Race.Participants.Yacht();

@ -1,5 +1,7 @@
package mock.xml; package mock.xml;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import shared.dataInput.RaceXMLReader; import shared.dataInput.RaceXMLReader;
import shared.enums.XMLFileType; import shared.enums.XMLFileType;
import shared.exceptions.InvalidRaceDataException; import shared.exceptions.InvalidRaceDataException;
@ -9,16 +11,37 @@ import shared.model.Corner;
import shared.model.GPSCoordinate; import shared.model.GPSCoordinate;
import shared.model.Mark; import shared.model.Mark;
import javax.xml.XMLConstants;
import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException; import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller; import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.util.JAXBSource;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Source;
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.io.StringWriter;
import java.net.URL;
/** /**
* Created by Gondr on 3/08/2017. * Helper Class for creating a Race XML
*/ */
public class RaceXMLCreator { public class RaceXMLCreator {
/**
* Copy the race to a mock.xml.Race class from a RaceXMlReader
* @param reader RaceXMlReader
* @return string of the new mock.xml.Race
* @throws InvalidRaceDataException If the reader is unable to be read
* @throws XMLReaderException If the reader is unable to be read
*/
public static Race copyRace(RaceXMLReader reader) throws InvalidRaceDataException, XMLReaderException { public static Race copyRace(RaceXMLReader reader) throws InvalidRaceDataException, XMLReaderException {
RaceFactory raceFactory = new RaceFactory(); RaceFactory raceFactory = new RaceFactory();
Race race = raceFactory.createRace(); Race race = raceFactory.createRace();
@ -80,6 +103,12 @@ public class RaceXMLCreator {
return race; return race;
} }
/**
* Sets a mock.xml.Mark from a shared.model.Mark
* @param raceFactory race Factory for creating mock.xml.Race classes and subclasses
* @param mark Mark to be converted.
* @return converted mock.xml.Mark.
*/
public static Race.Course.CompoundMark.Mark setMarkFromMark(RaceFactory raceFactory, Mark mark){ public static Race.Course.CompoundMark.Mark setMarkFromMark(RaceFactory raceFactory, Mark mark){
if (mark != null) { if (mark != null) {
Race.Course.CompoundMark.Mark m = raceFactory.createRaceCourseCompoundMarkMark(); Race.Course.CompoundMark.Mark m = raceFactory.createRaceCourseCompoundMarkMark();
@ -92,6 +121,11 @@ public class RaceXMLCreator {
return null; return null;
} }
/**
* get the windward gate in a race
* @param reader reads in the mark
* @return the windward gate.
*/
public static CompoundMark getWindwardGate(RaceXMLReader reader){ public static CompoundMark getWindwardGate(RaceXMLReader reader){
for (CompoundMark mark: reader.getCompoundMarks()){ for (CompoundMark mark: reader.getCompoundMarks()){
if (mark.getName().equals("Windward Gate")) return mark; if (mark.getName().equals("Windward Gate")) return mark;
@ -99,6 +133,11 @@ public class RaceXMLCreator {
return null; return null;
} }
/**
* get the leeward gate in a race
* @param reader reads in the mark
* @return the leeward gate.
*/
public static CompoundMark getLeewardGate(RaceXMLReader reader){ public static CompoundMark getLeewardGate(RaceXMLReader reader){
for (CompoundMark mark: reader.getCompoundMarks()){ for (CompoundMark mark: reader.getCompoundMarks()){
if (mark.getName().equals("Leeward Gate")) return mark; if (mark.getName().equals("Leeward Gate")) return mark;
@ -106,10 +145,19 @@ public class RaceXMLCreator {
return null; return null;
} }
public static String alterRaceToWind(String s, double degrees) throws XMLReaderException, InvalidRaceDataException, JAXBException { /**
* Rotates the race in a specified direction.
* @param s xml file name
* @param degrees degrees to rotate
* @return the new xml file as a string
* @throws XMLReaderException if the xml is not readable
* @throws InvalidRaceDataException if the race is invalid
* @throws JAXBException if the Race class cannot be parsed into a xml.
*/
public static String alterRaceToWind(String s, double degrees) throws XMLReaderException, InvalidRaceDataException, JAXBException, IOException, SAXException, ParserConfigurationException {
RaceXMLReader reader = new RaceXMLReader(s, XMLFileType.ResourcePath); RaceXMLReader reader = new RaceXMLReader(s, XMLFileType.ResourcePath);
Race race = copyRace(reader); Race race = readRace(RaceXMLCreator.class.getClassLoader().getResource(s).getFile());
double raceOriginalBearing = getLineAngle(getLeewardGate(reader).getMark1Position(), getWindwardGate(reader).getMark1Position()); double raceOriginalBearing = getLineAngle(getLeewardGate(reader).getMark1Position(), getWindwardGate(reader).getMark1Position());
@ -127,6 +175,11 @@ public class RaceXMLCreator {
return sw.toString(); return sw.toString();
} }
/**
* Rotate the features in a race such as the boundary, and the marks.
* @param race the race to alter
* @param degrees the degrees to rotate by.
*/
public static void alterRaceRotation(Race race, double degrees){ public static void alterRaceRotation(Race race, double degrees){
GPSCoordinate center = getCenter(race); GPSCoordinate center = getCenter(race);
for(Race.CourseLimit.Limit limit: race.getCourseLimit().getLimit()){ for(Race.CourseLimit.Limit limit: race.getCourseLimit().getLimit()){
@ -145,10 +198,22 @@ public class RaceXMLCreator {
} }
} }
/**
* Converts a Race.CourseLimit.Limit to a GPS coordinate
* @param limit limit to convert
* @return gps coordinate corresponding to the limit
*/
public static GPSCoordinate limitToGPSCoordinate(Race.CourseLimit.Limit limit){ public static GPSCoordinate limitToGPSCoordinate(Race.CourseLimit.Limit limit){
return new GPSCoordinate(Double.parseDouble(limit.getLat()), Double.parseDouble(limit.getLon())); return new GPSCoordinate(Double.parseDouble(limit.getLat()), Double.parseDouble(limit.getLon()));
} }
/**
* get new gps coordinate after rotating
* @param pivot center point to rotating from.
* @param point point to rotate
* @param degrees number of degress to rotate by
* @return the new GPSCoordinate of the transformed point.
*/
public static GPSCoordinate rotate(GPSCoordinate pivot, GPSCoordinate point, double degrees){ public static GPSCoordinate rotate(GPSCoordinate pivot, GPSCoordinate point, double degrees){
double radDeg = Math.toRadians(degrees); double radDeg = Math.toRadians(degrees);
double deltaLat = (point.getLatitude() - pivot.getLatitude()); double deltaLat = (point.getLatitude() - pivot.getLatitude());
@ -159,10 +224,20 @@ public class RaceXMLCreator {
return new GPSCoordinate(resLat, resLon); return new GPSCoordinate(resLat, resLon);
} }
/**
* obtains the GPSCoordinates of a mark
* @param mark mark to obtain the GPSCoordinates of
* @return the GPSCOordinatess of a mark
*/
public static GPSCoordinate markToGPSCoordinate(Race.Course.CompoundMark.Mark mark){ public static GPSCoordinate markToGPSCoordinate(Race.Course.CompoundMark.Mark mark){
return new GPSCoordinate(Double.parseDouble(mark.getTargetLat()), Double.parseDouble(mark.getTargetLng())); return new GPSCoordinate(Double.parseDouble(mark.getTargetLat()), Double.parseDouble(mark.getTargetLng()));
} }
/**
* get the center of a race
* @param race race to get the center of
* @return GPSCoordinates of the center
*/
public static GPSCoordinate getCenter(Race race){ public static GPSCoordinate getCenter(Race race){
double avgLat = 0; double avgLat = 0;
double avgLng = 0; double avgLng = 0;
@ -174,10 +249,46 @@ public class RaceXMLCreator {
avgLng = avgLng/race.getCourseLimit().getLimit().size(); avgLng = avgLng/race.getCourseLimit().getLimit().size();
return new GPSCoordinate(avgLat, avgLng); return new GPSCoordinate(avgLat, avgLng);
} }
/**
* gets the angle of a line
* @param coord1 point a of the line
* @param coord2 point b of the line
* @return the angle in degrees that the bearing of the line is [-180, 180]
*/
public static double getLineAngle(GPSCoordinate coord1, GPSCoordinate coord2){ public static double getLineAngle(GPSCoordinate coord1, GPSCoordinate coord2){
double dx = coord1.getLongitude() - coord2.getLongitude(); double dx = coord1.getLongitude() - coord2.getLongitude();
double dy = coord1.getLatitude() - coord2.getLatitude(); double dy = coord1.getLatitude() - coord2.getLatitude();
return Math.atan2(dy, dx)/Math.PI * 180; 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;
}
} }

@ -0,0 +1,36 @@
package shared.xml;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import java.io.StringWriter;
/**
* Created by fwy13 on 13/08/17.
*/
public class XMLUtilities {
public static String classToXML(Object o) throws JAXBException {
JAXBContext context = JAXBContext.newInstance(o.getClass());
Marshaller jaxbMarshaller = context.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
StringWriter sw = new StringWriter();
jaxbMarshaller.marshal(o, sw);
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);
}
}

@ -1,26 +1,14 @@
package visualiser.app; package visualiser.app;
import javafx.application.Platform;
import network.BinaryMessageDecoder; import network.BinaryMessageDecoder;
import network.Exceptions.InvalidMessageException; import network.Exceptions.InvalidMessageException;
import network.Messages.*; import network.Messages.*;
import org.xml.sax.SAXException;
import shared.dataInput.BoatXMLReader;
import shared.dataInput.RaceXMLReader;
import shared.dataInput.RegattaXMLReader;
import shared.exceptions.InvalidBoatDataException;
import shared.exceptions.InvalidRaceDataException;
import shared.exceptions.InvalidRegattaDataException;
import shared.exceptions.XMLReaderException;
import javax.xml.parsers.ParserConfigurationException;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.IOException; import java.io.IOException;
import java.net.Socket; import java.net.Socket;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ArrayBlockingQueue;
import static network.Utils.ByteConverter.bytesToShort; import static network.Utils.ByteConverter.bytesToShort;

@ -3,7 +3,7 @@
<xs:element name="Race"> <xs:element name="Race">
<xs:complexType> <xs:complexType>
<xs:sequence> <xs:sequence>
<xs:element name="RaceID" type="xs:string"/> <xs:element name="RaceID" type="xs:positiveInteger"/>
<xs:element name="RaceType" type="xs:string"/> <xs:element name="RaceType" type="xs:string"/>
<xs:element name="CreationTimeDate" type="xs:string"/> <xs:element name="CreationTimeDate" type="xs:string"/>
<xs:element name="RaceStartTime"> <xs:element name="RaceStartTime">
@ -18,6 +18,7 @@
<xs:element name="Yacht" maxOccurs="unbounded"> <xs:element name="Yacht" maxOccurs="unbounded">
<xs:complexType> <xs:complexType>
<xs:attribute name="SourceID" type="xs:string" use="required"/> <xs:attribute name="SourceID" type="xs:string" use="required"/>
<xs:attribute name="Entry" type="xs:string"/>
</xs:complexType> </xs:complexType>
</xs:element> </xs:element>
</xs:sequence> </xs:sequence>
@ -28,8 +29,10 @@
<xs:sequence> <xs:sequence>
<xs:element name="Corner" maxOccurs="unbounded"> <xs:element name="Corner" maxOccurs="unbounded">
<xs:complexType> <xs:complexType>
<xs:attribute name="CompoundMarkID" type="xs:string" use="required"/> <xs:attribute name="CompoundMarkID" type="xs:positiveInteger" use="required"/>
<xs:attribute name="SeqID" type="xs:string" use="required"/> <xs:attribute name="SeqID" type="xs:positiveInteger" use="required"/>
<xs:attribute name="Rounding" type="xs:string" use="required"/>
<xs:attribute name="ZoneSize" type="xs:positiveInteger" use="required"/>
</xs:complexType> </xs:complexType>
</xs:element> </xs:element>
</xs:sequence> </xs:sequence>

@ -0,0 +1,31 @@
package mock.xml;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import shared.dataInput.RaceXMLReader;
import shared.exceptions.InvalidRaceDataException;
import shared.exceptions.XMLReaderException;
import javax.xml.bind.JAXBException;
import static org.mockito.Mockito.mock;
public class RaceXMLCreatorTest {
String fileToTest = "mock/mockXML/raceSchemaTest.xml";
@Mock
RaceXMLReader reader;
@Before
public void setup() throws XMLReaderException, JAXBException, InvalidRaceDataException {
}
@Test
public void getLineAngleTest(){
}
}
Loading…
Cancel
Save