From 4e8d4f24333ef785852ba8623b13e85aabb9b649 Mon Sep 17 00:00:00 2001 From: Fan-Wu Yang Date: Thu, 3 Aug 2017 02:42:33 +1200 Subject: [PATCH] Created Schema for Race xml's and generated classes for reading xml with xjc, made the RaceXMLReader read Corner classes in as well as making a corner class #story[1092] --- .../src/main/java/mock/app/Event.java | 105 +- .../src/main/java/mock/xml/ObjectFactory.java | 127 ++ .../src/main/java/mock/xml/Race.java | 1258 +++++++++++++++++ .../src/main/java/mock/xml/RaceFactory.java | 127 ++ .../java/shared/dataInput/RaceXMLReader.java | 15 + .../src/main/java/shared/model/Corner.java | 23 + .../resources/mock/mockXML/raceSchemaTest.xml | 52 + .../mock/mockXML/schema/raceSchema.xsd | 77 + 8 files changed, 1782 insertions(+), 2 deletions(-) create mode 100644 racevisionGame/src/main/java/mock/xml/ObjectFactory.java create mode 100644 racevisionGame/src/main/java/mock/xml/Race.java create mode 100644 racevisionGame/src/main/java/mock/xml/RaceFactory.java create mode 100644 racevisionGame/src/main/java/shared/model/Corner.java create mode 100644 racevisionGame/src/main/resources/mock/mockXML/raceSchemaTest.xml create mode 100644 racevisionGame/src/main/resources/mock/mockXML/schema/raceSchema.xsd diff --git a/racevisionGame/src/main/java/mock/app/Event.java b/racevisionGame/src/main/java/mock/app/Event.java index c94a691f..631f431d 100644 --- a/racevisionGame/src/main/java/mock/app/Event.java +++ b/racevisionGame/src/main/java/mock/app/Event.java @@ -3,6 +3,8 @@ package mock.app; import mock.dataInput.PolarParser; import mock.model.MockRace; import mock.model.Polars; +import mock.xml.Race; +import mock.xml.RaceFactory; import network.Messages.LatestMessages; import shared.dataInput.*; import shared.enums.XMLFileType; @@ -10,10 +12,15 @@ import shared.exceptions.InvalidBoatDataException; import shared.exceptions.InvalidRaceDataException; import shared.exceptions.InvalidRegattaDataException; import shared.exceptions.XMLReaderException; +import shared.model.CompoundMark; import shared.model.Constants; +import shared.model.Corner; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; import javax.xml.transform.TransformerException; -import java.io.IOException; +import java.io.*; import java.net.UnknownHostException; import java.nio.charset.StandardCharsets; import java.time.ZonedDateTime; @@ -42,7 +49,7 @@ public class Event { */ private Event() { try { - this.raceXML = getRaceXMLAtCurrentTime(XMLReader.readXMLFileToString("mock/mockXML/raceTest.xml", StandardCharsets.UTF_8)); + this.raceXML = getRaceXMLAtCurrentTime(alterRaceToWind("mock/mockXML/raceSchemaTest.xml", 0)); 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; @@ -58,6 +65,10 @@ public class Event { e.printStackTrace(); } catch (TransformerException e) { e.printStackTrace(); + } catch (InvalidRaceDataException e) { + e.printStackTrace(); + } catch (JAXBException e) { + e.printStackTrace(); } } @@ -130,4 +141,94 @@ public class Event { return raceXML; } + + + private Race copyRace(RaceXMLReader reader) throws InvalidRaceDataException, XMLReaderException { + mock.xml.RaceFactory raceFactory = new RaceFactory(); + mock.xml.Race race = raceFactory.createRace(); + race.setRaceID(String.valueOf(reader.getRaceId())); + race.setRaceType(String.valueOf(reader.getRaceType())); + race.setCreationTimeDate("CREATION_TIME");//this needs to be changed later + + //Race Start Time + mock.xml.Race.RaceStartTime raceStartTime = raceFactory.createRaceRaceStartTime(); + raceStartTime.setPostpone("false"); + raceStartTime.setTime("START_TIME");//this needs to be changed later + race.setRaceStartTime(raceStartTime); + + //Participants + Race.Participants participants = raceFactory.createRaceParticipants(); + for (int i :reader.getParticipants()) { + Race.Participants.Yacht yacht = raceFactory.createRaceParticipantsYacht(); + yacht.setSourceID(String.valueOf(i)); + participants.getYacht().add(yacht); //java schema does not clone the array so this is "safe". + } + race.setParticipants(participants); + + //compound marks sequence + Race.CompoundMarkSequence cms = raceFactory.createRaceCompoundMarkSequence(); + for (Corner mark: reader.getCornersList()){ + Race.CompoundMarkSequence.Corner corner = raceFactory.createRaceCompoundMarkSequenceCorner(); + corner.setCompoundMarkID(String.valueOf(mark.getId())); + corner.setSeqID(String.valueOf(mark.getSeqID())); + cms.getCorner().add(corner); + } + race.setCompoundMarkSequence(cms); + + //Course + Race.Course course = raceFactory.createRaceCourse(); + for (CompoundMark mark: reader.getCompoundMarks()){ + Race.Course.CompoundMark cm = raceFactory.createRaceCourseCompoundMark(); + cm.setName(mark.getName()); + cm.setCompoundMarkID(String.valueOf(mark.getId())); + if (mark.getMark1() != null){ + Race.Course.CompoundMark.Mark m1 = raceFactory.createRaceCourseCompoundMarkMark(); + m1.setName(mark.getMark1().getName()); + m1.setTargetLat(String.valueOf(mark.getMark1().getPosition().getLatitude())); + m1.setTargetLng(String.valueOf(mark.getMark1().getPosition().getLongitude())); + m1.setSourceID(String.valueOf(mark.getMark1().getSourceID())); + cm.getMark().add(m1); + } + //make this not copy paste later but just need the concept working right now + if (mark.getMark2() != null){ + Race.Course.CompoundMark.Mark m2 = raceFactory.createRaceCourseCompoundMarkMark(); + m2.setName(mark.getMark1().getName()); + m2.setTargetLat(String.valueOf(mark.getMark1().getPosition().getLatitude())); + m2.setTargetLng(String.valueOf(mark.getMark1().getPosition().getLongitude())); + m2.setSourceID(String.valueOf(mark.getMark1().getSourceID())); + cm.getMark().add(m2); + } + course.getCompoundMark().add(cm); + } + race.setCourse(course); + + //Course Limit + Race.CourseLimit courseLimit = raceFactory.createRaceCourseLimit(); + for (int i = 0; i < reader.getBoundary().size(); i++){ + Race.CourseLimit.Limit limit = raceFactory.createRaceCourseLimitLimit(); + limit.setSeqID(String.valueOf(i+1)); + limit.setLat(String.valueOf(reader.getBoundary().get(i).getLatitude())); + limit.setLon(String.valueOf(reader.getBoundary().get(i).getLongitude())); + courseLimit.getLimit().add(limit); + } + race.setCourseLimit(courseLimit); + + return race; + } + + private String alterRaceToWind(String s, double degrees) throws XMLReaderException, InvalidRaceDataException, JAXBException { + RaceXMLReader reader = new RaceXMLReader(s, XMLFileType.ResourcePath); + + mock.xml.Race race = copyRace(reader); + + JAXBContext context = JAXBContext.newInstance(mock.xml.Race.class); + Marshaller jaxbMarshaller = context.createMarshaller(); + jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + + StringWriter sw = new StringWriter(); + + jaxbMarshaller.marshal(race, sw); + return sw.toString(); + } + } diff --git a/racevisionGame/src/main/java/mock/xml/ObjectFactory.java b/racevisionGame/src/main/java/mock/xml/ObjectFactory.java new file mode 100644 index 00000000..46d95ee5 --- /dev/null +++ b/racevisionGame/src/main/java/mock/xml/ObjectFactory.java @@ -0,0 +1,127 @@ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2017.08.03 at 02:28:57 AM NZST +// + + +package mock.xml; + +import javax.xml.bind.annotation.XmlRegistry; + + +/** + * This object contains factory methods for each + * Java content interface and Java element interface + * generated in the race package. + *

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 ObjectFactory { + + + /** + * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: race + * + */ + public ObjectFactory() { + } + + /** + * Create an instance of {@link Race } + * + */ + public Race createRace() { + return new Race(); + } + + /** + * Create an instance of {@link Race.CourseLimit } + * + */ + public Race.CourseLimit createRaceCourseLimit() { + return new Race.CourseLimit(); + } + + /** + * Create an instance of {@link Race.Course } + * + */ + public Race.Course createRaceCourse() { + return new Race.Course(); + } + + /** + * Create an instance of {@link Race.Course.CompoundMark } + * + */ + public Race.Course.CompoundMark createRaceCourseCompoundMark() { + return new Race.Course.CompoundMark(); + } + + /** + * Create an instance of {@link Race.CompoundMarkSequence } + * + */ + public Race.CompoundMarkSequence createRaceCompoundMarkSequence() { + return new Race.CompoundMarkSequence(); + } + + /** + * Create an instance of {@link Race.Participants } + * + */ + public Race.Participants createRaceParticipants() { + return new Race.Participants(); + } + + /** + * Create an instance of {@link Race.RaceStartTime } + * + */ + public Race.RaceStartTime createRaceRaceStartTime() { + return new Race.RaceStartTime(); + } + + /** + * Create an instance of {@link Race.CourseLimit.Limit } + * + */ + public Race.CourseLimit.Limit createRaceCourseLimitLimit() { + return new Race.CourseLimit.Limit(); + } + + /** + * Create an instance of {@link Race.Course.CompoundMark.Mark } + * + */ + public Race.Course.CompoundMark.Mark createRaceCourseCompoundMarkMark() { + return new Race.Course.CompoundMark.Mark(); + } + + /** + * Create an instance of {@link Race.CompoundMarkSequence.Corner } + * + */ + public Race.CompoundMarkSequence.Corner createRaceCompoundMarkSequenceCorner() { + return new Race.CompoundMarkSequence.Corner(); + } + + /** + * Create an instance of {@link Race.Participants.Yacht } + * + */ + public Race.Participants.Yacht createRaceParticipantsYacht() { + return new Race.Participants.Yacht(); + } + +} diff --git a/racevisionGame/src/main/java/mock/xml/Race.java b/racevisionGame/src/main/java/mock/xml/Race.java new file mode 100644 index 00000000..e2f1837d --- /dev/null +++ b/racevisionGame/src/main/java/mock/xml/Race.java @@ -0,0 +1,1258 @@ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2017.08.03 at 02:28:57 AM NZST +// + + +package mock.xml; + +import java.util.ArrayList; +import java.util.List; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType>
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element name="RaceID" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ *         <element name="RaceType" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ *         <element name="CreationTimeDate" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ *         <element name="RaceStartTime">
+ *           <complexType>
+ *             <complexContent>
+ *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *                 <attribute name="Postpone" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *                 <attribute name="Time" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *               </restriction>
+ *             </complexContent>
+ *           </complexType>
+ *         </element>
+ *         <element name="Participants">
+ *           <complexType>
+ *             <complexContent>
+ *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *                 <sequence>
+ *                   <element name="Yacht" maxOccurs="unbounded">
+ *                     <complexType>
+ *                       <complexContent>
+ *                         <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *                           <attribute name="SourceID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *                         </restriction>
+ *                       </complexContent>
+ *                     </complexType>
+ *                   </element>
+ *                 </sequence>
+ *               </restriction>
+ *             </complexContent>
+ *           </complexType>
+ *         </element>
+ *         <element name="CompoundMarkSequence">
+ *           <complexType>
+ *             <complexContent>
+ *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *                 <sequence>
+ *                   <element name="Corner" maxOccurs="unbounded">
+ *                     <complexType>
+ *                       <complexContent>
+ *                         <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *                           <attribute name="CompoundMarkID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *                           <attribute name="SeqID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *                         </restriction>
+ *                       </complexContent>
+ *                     </complexType>
+ *                   </element>
+ *                 </sequence>
+ *               </restriction>
+ *             </complexContent>
+ *           </complexType>
+ *         </element>
+ *         <element name="Course">
+ *           <complexType>
+ *             <complexContent>
+ *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *                 <sequence>
+ *                   <element name="CompoundMark" maxOccurs="unbounded">
+ *                     <complexType>
+ *                       <complexContent>
+ *                         <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *                           <sequence>
+ *                             <element name="Mark" maxOccurs="unbounded">
+ *                               <complexType>
+ *                                 <complexContent>
+ *                                   <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *                                     <attribute name="SeqId" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *                                     <attribute name="Name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *                                     <attribute name="TargetLat" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *                                     <attribute name="TargetLng" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *                                     <attribute name="SourceID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *                                   </restriction>
+ *                                 </complexContent>
+ *                               </complexType>
+ *                             </element>
+ *                           </sequence>
+ *                           <attribute name="CompoundMarkID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *                           <attribute name="Name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *                         </restriction>
+ *                       </complexContent>
+ *                     </complexType>
+ *                   </element>
+ *                 </sequence>
+ *               </restriction>
+ *             </complexContent>
+ *           </complexType>
+ *         </element>
+ *         <element name="CourseLimit">
+ *           <complexType>
+ *             <complexContent>
+ *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *                 <sequence>
+ *                   <element name="Limit" maxOccurs="unbounded">
+ *                     <complexType>
+ *                       <complexContent>
+ *                         <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *                           <attribute name="Lat" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *                           <attribute name="Lon" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *                           <attribute name="SeqID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *                         </restriction>
+ *                       </complexContent>
+ *                     </complexType>
+ *                   </element>
+ *                 </sequence>
+ *               </restriction>
+ *             </complexContent>
+ *           </complexType>
+ *         </element>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { + "raceID", + "raceType", + "creationTimeDate", + "raceStartTime", + "participants", + "compoundMarkSequence", + "course", + "courseLimit" +}) +@XmlRootElement(name = "Race") +public class Race { + + @XmlElement(name = "RaceID", required = true) + protected String raceID; + @XmlElement(name = "RaceType", required = true) + protected String raceType; + @XmlElement(name = "CreationTimeDate", required = true) + protected String creationTimeDate; + @XmlElement(name = "RaceStartTime", required = true) + protected Race.RaceStartTime raceStartTime; + @XmlElement(name = "Participants", required = true) + protected Race.Participants participants; + @XmlElement(name = "CompoundMarkSequence", required = true) + protected Race.CompoundMarkSequence compoundMarkSequence; + @XmlElement(name = "Course", required = true) + protected Race.Course course; + @XmlElement(name = "CourseLimit", required = true) + protected Race.CourseLimit courseLimit; + + /** + * Gets the value of the raceID property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getRaceID() { + return raceID; + } + + /** + * Sets the value of the raceID property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setRaceID(String value) { + this.raceID = value; + } + + /** + * Gets the value of the raceType property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getRaceType() { + return raceType; + } + + /** + * Sets the value of the raceType property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setRaceType(String value) { + this.raceType = value; + } + + /** + * Gets the value of the creationTimeDate property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getCreationTimeDate() { + return creationTimeDate; + } + + /** + * Sets the value of the creationTimeDate property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setCreationTimeDate(String value) { + this.creationTimeDate = value; + } + + /** + * Gets the value of the raceStartTime property. + * + * @return + * possible object is + * {@link Race.RaceStartTime } + * + */ + public Race.RaceStartTime getRaceStartTime() { + return raceStartTime; + } + + /** + * Sets the value of the raceStartTime property. + * + * @param value + * allowed object is + * {@link Race.RaceStartTime } + * + */ + public void setRaceStartTime(Race.RaceStartTime value) { + this.raceStartTime = value; + } + + /** + * Gets the value of the participants property. + * + * @return + * possible object is + * {@link Race.Participants } + * + */ + public Race.Participants getParticipants() { + return participants; + } + + /** + * Sets the value of the participants property. + * + * @param value + * allowed object is + * {@link Race.Participants } + * + */ + public void setParticipants(Race.Participants value) { + this.participants = value; + } + + /** + * Gets the value of the compoundMarkSequence property. + * + * @return + * possible object is + * {@link Race.CompoundMarkSequence } + * + */ + public Race.CompoundMarkSequence getCompoundMarkSequence() { + return compoundMarkSequence; + } + + /** + * Sets the value of the compoundMarkSequence property. + * + * @param value + * allowed object is + * {@link Race.CompoundMarkSequence } + * + */ + public void setCompoundMarkSequence(Race.CompoundMarkSequence value) { + this.compoundMarkSequence = value; + } + + /** + * Gets the value of the course property. + * + * @return + * possible object is + * {@link Race.Course } + * + */ + public Race.Course getCourse() { + return course; + } + + /** + * Sets the value of the course property. + * + * @param value + * allowed object is + * {@link Race.Course } + * + */ + public void setCourse(Race.Course value) { + this.course = value; + } + + /** + * Gets the value of the courseLimit property. + * + * @return + * possible object is + * {@link Race.CourseLimit } + * + */ + public Race.CourseLimit getCourseLimit() { + return courseLimit; + } + + /** + * Sets the value of the courseLimit property. + * + * @param value + * allowed object is + * {@link Race.CourseLimit } + * + */ + public void setCourseLimit(Race.CourseLimit value) { + this.courseLimit = value; + } + + + /** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+     * <complexType>
+     *   <complexContent>
+     *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+     *       <sequence>
+     *         <element name="Corner" maxOccurs="unbounded">
+     *           <complexType>
+     *             <complexContent>
+     *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+     *                 <attribute name="CompoundMarkID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+     *                 <attribute name="SeqID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+     *               </restriction>
+     *             </complexContent>
+     *           </complexType>
+     *         </element>
+     *       </sequence>
+     *     </restriction>
+     *   </complexContent>
+     * </complexType>
+     * 
+ * + * + */ + @XmlAccessorType(XmlAccessType.FIELD) + @XmlType(name = "", propOrder = { + "corner" + }) + public static class CompoundMarkSequence { + + @XmlElement(name = "Corner", required = true) + protected List corner; + + /** + * Gets the value of the corner property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the corner property. + * + *

+ * For example, to add a new item, do as follows: + *

+         *    getCorner().add(newItem);
+         * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link Race.CompoundMarkSequence.Corner } + * + * + */ + public List getCorner() { + if (corner == null) { + corner = new ArrayList(); + } + return this.corner; + } + + + /** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+         * <complexType>
+         *   <complexContent>
+         *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+         *       <attribute name="CompoundMarkID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+         *       <attribute name="SeqID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+         *     </restriction>
+         *   </complexContent>
+         * </complexType>
+         * 
+ * + * + */ + @XmlAccessorType(XmlAccessType.FIELD) + @XmlType(name = "") + public static class Corner { + + @XmlAttribute(name = "CompoundMarkID", required = true) + protected String compoundMarkID; + @XmlAttribute(name = "SeqID", required = true) + protected String seqID; + + /** + * Gets the value of the compoundMarkID property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getCompoundMarkID() { + return compoundMarkID; + } + + /** + * Sets the value of the compoundMarkID property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setCompoundMarkID(String value) { + this.compoundMarkID = value; + } + + /** + * Gets the value of the seqID property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getSeqID() { + return seqID; + } + + /** + * Sets the value of the seqID property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setSeqID(String value) { + this.seqID = value; + } + + } + + } + + + /** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+     * <complexType>
+     *   <complexContent>
+     *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+     *       <sequence>
+     *         <element name="CompoundMark" maxOccurs="unbounded">
+     *           <complexType>
+     *             <complexContent>
+     *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+     *                 <sequence>
+     *                   <element name="Mark" maxOccurs="unbounded">
+     *                     <complexType>
+     *                       <complexContent>
+     *                         <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+     *                           <attribute name="SeqId" type="{http://www.w3.org/2001/XMLSchema}string" />
+     *                           <attribute name="Name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+     *                           <attribute name="TargetLat" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+     *                           <attribute name="TargetLng" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+     *                           <attribute name="SourceID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+     *                         </restriction>
+     *                       </complexContent>
+     *                     </complexType>
+     *                   </element>
+     *                 </sequence>
+     *                 <attribute name="CompoundMarkID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+     *                 <attribute name="Name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+     *               </restriction>
+     *             </complexContent>
+     *           </complexType>
+     *         </element>
+     *       </sequence>
+     *     </restriction>
+     *   </complexContent>
+     * </complexType>
+     * 
+ * + * + */ + @XmlAccessorType(XmlAccessType.FIELD) + @XmlType(name = "", propOrder = { + "compoundMark" + }) + public static class Course { + + @XmlElement(name = "CompoundMark", required = true) + protected List compoundMark; + + /** + * Gets the value of the compoundMark property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the compoundMark property. + * + *

+ * For example, to add a new item, do as follows: + *

+         *    getCompoundMark().add(newItem);
+         * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link Race.Course.CompoundMark } + * + * + */ + public List getCompoundMark() { + if (compoundMark == null) { + compoundMark = new ArrayList(); + } + return this.compoundMark; + } + + + /** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+         * <complexType>
+         *   <complexContent>
+         *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+         *       <sequence>
+         *         <element name="Mark" maxOccurs="unbounded">
+         *           <complexType>
+         *             <complexContent>
+         *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+         *                 <attribute name="SeqId" type="{http://www.w3.org/2001/XMLSchema}string" />
+         *                 <attribute name="Name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+         *                 <attribute name="TargetLat" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+         *                 <attribute name="TargetLng" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+         *                 <attribute name="SourceID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+         *               </restriction>
+         *             </complexContent>
+         *           </complexType>
+         *         </element>
+         *       </sequence>
+         *       <attribute name="CompoundMarkID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+         *       <attribute name="Name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+         *     </restriction>
+         *   </complexContent>
+         * </complexType>
+         * 
+ * + * + */ + @XmlAccessorType(XmlAccessType.FIELD) + @XmlType(name = "", propOrder = { + "mark" + }) + public static class CompoundMark { + + @XmlElement(name = "Mark", required = true) + protected List mark; + @XmlAttribute(name = "CompoundMarkID", required = true) + protected String compoundMarkID; + @XmlAttribute(name = "Name", required = true) + protected String name; + + /** + * Gets the value of the mark property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the mark property. + * + *

+ * For example, to add a new item, do as follows: + *

+             *    getMark().add(newItem);
+             * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link Race.Course.CompoundMark.Mark } + * + * + */ + public List getMark() { + if (mark == null) { + mark = new ArrayList(); + } + return this.mark; + } + + /** + * Gets the value of the compoundMarkID property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getCompoundMarkID() { + return compoundMarkID; + } + + /** + * Sets the value of the compoundMarkID property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setCompoundMarkID(String value) { + this.compoundMarkID = value; + } + + /** + * Gets the value of the name property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getName() { + return name; + } + + /** + * Sets the value of the name property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setName(String value) { + this.name = value; + } + + + /** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+             * <complexType>
+             *   <complexContent>
+             *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+             *       <attribute name="SeqId" type="{http://www.w3.org/2001/XMLSchema}string" />
+             *       <attribute name="Name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+             *       <attribute name="TargetLat" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+             *       <attribute name="TargetLng" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+             *       <attribute name="SourceID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+             *     </restriction>
+             *   </complexContent>
+             * </complexType>
+             * 
+ * + * + */ + @XmlAccessorType(XmlAccessType.FIELD) + @XmlType(name = "") + public static class Mark { + + @XmlAttribute(name = "SeqId") + protected String seqId; + @XmlAttribute(name = "Name", required = true) + protected String name; + @XmlAttribute(name = "TargetLat", required = true) + protected String targetLat; + @XmlAttribute(name = "TargetLng", required = true) + protected String targetLng; + @XmlAttribute(name = "SourceID", required = true) + protected String sourceID; + + /** + * Gets the value of the seqId property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getSeqId() { + return seqId; + } + + /** + * Sets the value of the seqId property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setSeqId(String value) { + this.seqId = value; + } + + /** + * Gets the value of the name property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getName() { + return name; + } + + /** + * Sets the value of the name property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setName(String value) { + this.name = value; + } + + /** + * Gets the value of the targetLat property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getTargetLat() { + return targetLat; + } + + /** + * Sets the value of the targetLat property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setTargetLat(String value) { + this.targetLat = value; + } + + /** + * Gets the value of the targetLng property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getTargetLng() { + return targetLng; + } + + /** + * Sets the value of the targetLng property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setTargetLng(String value) { + this.targetLng = value; + } + + /** + * Gets the value of the sourceID property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getSourceID() { + return sourceID; + } + + /** + * Sets the value of the sourceID property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setSourceID(String value) { + this.sourceID = value; + } + + } + + } + + } + + + /** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+     * <complexType>
+     *   <complexContent>
+     *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+     *       <sequence>
+     *         <element name="Limit" maxOccurs="unbounded">
+     *           <complexType>
+     *             <complexContent>
+     *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+     *                 <attribute name="Lat" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+     *                 <attribute name="Lon" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+     *                 <attribute name="SeqID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+     *               </restriction>
+     *             </complexContent>
+     *           </complexType>
+     *         </element>
+     *       </sequence>
+     *     </restriction>
+     *   </complexContent>
+     * </complexType>
+     * 
+ * + * + */ + @XmlAccessorType(XmlAccessType.FIELD) + @XmlType(name = "", propOrder = { + "limit" + }) + public static class CourseLimit { + + @XmlElement(name = "Limit", required = true) + protected List limit; + + /** + * Gets the value of the limit property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the limit property. + * + *

+ * For example, to add a new item, do as follows: + *

+         *    getLimit().add(newItem);
+         * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link Race.CourseLimit.Limit } + * + * + */ + public List getLimit() { + if (limit == null) { + limit = new ArrayList(); + } + return this.limit; + } + + + /** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+         * <complexType>
+         *   <complexContent>
+         *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+         *       <attribute name="Lat" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+         *       <attribute name="Lon" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+         *       <attribute name="SeqID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+         *     </restriction>
+         *   </complexContent>
+         * </complexType>
+         * 
+ * + * + */ + @XmlAccessorType(XmlAccessType.FIELD) + @XmlType(name = "") + public static class Limit { + + @XmlAttribute(name = "Lat", required = true) + protected String lat; + @XmlAttribute(name = "Lon", required = true) + protected String lon; + @XmlAttribute(name = "SeqID", required = true) + protected String seqID; + + /** + * Gets the value of the lat property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getLat() { + return lat; + } + + /** + * Sets the value of the lat property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setLat(String value) { + this.lat = value; + } + + /** + * Gets the value of the lon property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getLon() { + return lon; + } + + /** + * Sets the value of the lon property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setLon(String value) { + this.lon = value; + } + + /** + * Gets the value of the seqID property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getSeqID() { + return seqID; + } + + /** + * Sets the value of the seqID property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setSeqID(String value) { + this.seqID = value; + } + + } + + } + + + /** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+     * <complexType>
+     *   <complexContent>
+     *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+     *       <sequence>
+     *         <element name="Yacht" maxOccurs="unbounded">
+     *           <complexType>
+     *             <complexContent>
+     *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+     *                 <attribute name="SourceID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+     *               </restriction>
+     *             </complexContent>
+     *           </complexType>
+     *         </element>
+     *       </sequence>
+     *     </restriction>
+     *   </complexContent>
+     * </complexType>
+     * 
+ * + * + */ + @XmlAccessorType(XmlAccessType.FIELD) + @XmlType(name = "", propOrder = { + "yacht" + }) + public static class Participants { + + @XmlElement(name = "Yacht", required = true) + protected List yacht; + + /** + * Gets the value of the yacht property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the yacht property. + * + *

+ * For example, to add a new item, do as follows: + *

+         *    getYacht().add(newItem);
+         * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link Race.Participants.Yacht } + * + * + */ + public List getYacht() { + if (yacht == null) { + yacht = new ArrayList(); + } + return this.yacht; + } + + + /** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+         * <complexType>
+         *   <complexContent>
+         *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+         *       <attribute name="SourceID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+         *     </restriction>
+         *   </complexContent>
+         * </complexType>
+         * 
+ * + * + */ + @XmlAccessorType(XmlAccessType.FIELD) + @XmlType(name = "") + public static class Yacht { + + @XmlAttribute(name = "SourceID", required = true) + protected String sourceID; + + /** + * Gets the value of the sourceID property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getSourceID() { + return sourceID; + } + + /** + * Sets the value of the sourceID property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setSourceID(String value) { + this.sourceID = value; + } + + } + + } + + + /** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+     * <complexType>
+     *   <complexContent>
+     *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+     *       <attribute name="Postpone" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+     *       <attribute name="Time" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+     *     </restriction>
+     *   </complexContent>
+     * </complexType>
+     * 
+ * + * + */ + @XmlAccessorType(XmlAccessType.FIELD) + @XmlType(name = "") + public static class RaceStartTime { + + @XmlAttribute(name = "Postpone", required = true) + protected String postpone; + @XmlAttribute(name = "Time", required = true) + protected String time; + + /** + * Gets the value of the postpone property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getPostpone() { + return postpone; + } + + /** + * Sets the value of the postpone property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setPostpone(String value) { + this.postpone = value; + } + + /** + * Gets the value of the time property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getTime() { + return time; + } + + /** + * Sets the value of the time property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setTime(String value) { + this.time = value; + } + + } + +} diff --git a/racevisionGame/src/main/java/mock/xml/RaceFactory.java b/racevisionGame/src/main/java/mock/xml/RaceFactory.java new file mode 100644 index 00000000..674fa849 --- /dev/null +++ b/racevisionGame/src/main/java/mock/xml/RaceFactory.java @@ -0,0 +1,127 @@ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 +// See http://java.sun.com/xml/jaxb +// 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 +// + + +package mock.xml; + +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. + *

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 + * + */ + public RaceFactory() { + } + + /** + * Create an instance of {@link Race } + * + */ + public Race createRace() { + return new Race(); + } + + /** + * Create an instance of {@link Race.CourseLimit } + * + */ + public Race.CourseLimit createRaceCourseLimit() { + return new Race.CourseLimit(); + } + + /** + * Create an instance of {@link Race.Course } + * + */ + public Race.Course createRaceCourse() { + return new Race.Course(); + } + + /** + * Create an instance of {@link Race.Course.CompoundMark } + * + */ + public Race.Course.CompoundMark createRaceCourseCompoundMark() { + return new Race.Course.CompoundMark(); + } + + /** + * Create an instance of {@link Race.CompoundMarkSequence } + * + */ + public Race.CompoundMarkSequence createRaceCompoundMarkSequence() { + return new Race.CompoundMarkSequence(); + } + + /** + * Create an instance of {@link Race.Participants } + * + */ + public Race.Participants createRaceParticipants() { + return new Race.Participants(); + } + + /** + * Create an instance of {@link Race.RaceStartTime } + * + */ + public Race.RaceStartTime createRaceRaceStartTime() { + return new Race.RaceStartTime(); + } + + /** + * Create an instance of {@link Race.CourseLimit.Limit } + * + */ + public Race.CourseLimit.Limit createRaceCourseLimitLimit() { + return new Race.CourseLimit.Limit(); + } + + /** + * Create an instance of {@link Race.Course.CompoundMark.Mark } + * + */ + public Race.Course.CompoundMark.Mark createRaceCourseCompoundMarkMark() { + return new Race.Course.CompoundMark.Mark(); + } + + /** + * Create an instance of {@link Race.CompoundMarkSequence.Corner } + * + */ + public Race.CompoundMarkSequence.Corner createRaceCompoundMarkSequenceCorner() { + return new Race.CompoundMarkSequence.Corner(); + } + + /** + * Create an instance of {@link Race.Participants.Yacht } + * + */ + public Race.Participants.Yacht createRaceParticipantsYacht() { + return new Race.Participants.Yacht(); + } + +} diff --git a/racevisionGame/src/main/java/shared/dataInput/RaceXMLReader.java b/racevisionGame/src/main/java/shared/dataInput/RaceXMLReader.java index 7e61b3de..361fefd4 100644 --- a/racevisionGame/src/main/java/shared/dataInput/RaceXMLReader.java +++ b/racevisionGame/src/main/java/shared/dataInput/RaceXMLReader.java @@ -51,6 +51,10 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource { */ private final List legs = new ArrayList<>(); + /** + * List of corners in the race + */ + private final List cornersList = new ArrayList<>(); /** * The time that the race.xml file was created. @@ -331,6 +335,10 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource { //Gets the ID number of this corner element. int cornerID = getCompoundMarkID(cornerElement); + int cornerSeq = Integer.parseInt(getAttribute(cornerElement, "SeqID")); + + cornersList.add(new Corner(cornerID, cornerSeq)); + //Gets the CompoundMark associated with this corner. CompoundMark lastCompoundMark = this.compoundMarkMap.get(cornerID); @@ -346,6 +354,9 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource { //Gets the ID number of this corner element. cornerID = getCompoundMarkID(cornerElement); + cornerSeq = Integer.parseInt(getAttribute(cornerElement, "SeqID")); + + cornersList.add(new Corner(cornerID, cornerSeq)); //Gets the CompoundMark associated with this corner. CompoundMark currentCompoundMark = this.compoundMarkMap.get(cornerID); @@ -460,4 +471,8 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource { public List getParticipants() { return participants; } + + public List getCornersList() { + return cornersList; + } } diff --git a/racevisionGame/src/main/java/shared/model/Corner.java b/racevisionGame/src/main/java/shared/model/Corner.java new file mode 100644 index 00000000..9956b40e --- /dev/null +++ b/racevisionGame/src/main/java/shared/model/Corner.java @@ -0,0 +1,23 @@ +package shared.model; + +/** + * Created by Gondr on 3/08/2017. + */ +public class Corner { + + private int id; + private int seqID; + + public Corner(int id, int seqID){ + this.id = id; + this.seqID = seqID; + } + + public int getId() { + return id; + } + + public int getSeqID() { + return seqID; + } +} diff --git a/racevisionGame/src/main/resources/mock/mockXML/raceSchemaTest.xml b/racevisionGame/src/main/resources/mock/mockXML/raceSchemaTest.xml new file mode 100644 index 00000000..344279ff --- /dev/null +++ b/racevisionGame/src/main/resources/mock/mockXML/raceSchemaTest.xml @@ -0,0 +1,52 @@ + + + 5326 + FLEET + 2017-08-03T02:13:14+1200 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/racevisionGame/src/main/resources/mock/mockXML/schema/raceSchema.xsd b/racevisionGame/src/main/resources/mock/mockXML/schema/raceSchema.xsd new file mode 100644 index 00000000..8cc15218 --- /dev/null +++ b/racevisionGame/src/main/resources/mock/mockXML/schema/raceSchema.xsd @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file