diff --git a/racevisionGame/src/main/java/mock/model/RaceServer.java b/racevisionGame/src/main/java/mock/model/RaceServer.java index 37c21194..585fe615 100644 --- a/racevisionGame/src/main/java/mock/model/RaceServer.java +++ b/racevisionGame/src/main/java/mock/model/RaceServer.java @@ -112,7 +112,20 @@ public class RaceServer { * Checks if the regatta data source has changed, and if it has, updates LatestMessages' regatta xml message. */ private void updateRegattaXMLFile() { + if (regattaXMLSeqNumber != race.getRegattaDataSource().getSequenceNumber()) { + regattaXMLSeqNumber = race.getRegattaDataSource().getSequenceNumber(); + + try { + String regattaXMLString = RegattaDataSourceToXML.toString(race.getRegattaDataSource()); + XMLMessage message = createXMLMessage(regattaXMLString, XMLMessageType.REGATTA); + latestMessages.setXMLMessage(message); + + } catch (JAXBException e) { + Logger.getGlobal().log(Level.WARNING, "Could not serialise: " + race.getRegattaDataSource(), e); + } + + } } /** diff --git a/racevisionGame/src/main/java/shared/xml/regatta/ObjectFactory.java b/racevisionGame/src/main/java/shared/xml/regatta/ObjectFactory.java new file mode 100644 index 00000000..7fc72202 --- /dev/null +++ b/racevisionGame/src/main/java/shared/xml/regatta/ObjectFactory.java @@ -0,0 +1,47 @@ +// +// 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.09.01 at 10:37:23 PM NZST +// + + +package shared.xml.regatta; + +import javax.xml.bind.annotation.XmlRegistry; + + +/** + * This object contains factory methods for each + * Java content interface and Java element interface + * generated in the aaa 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: aaa + * + */ + public ObjectFactory() { + } + + /** + * Create an instance of {@link RegattaConfig } + * + */ + public RegattaConfig createRegattaConfig() { + return new RegattaConfig(); + } + +} diff --git a/racevisionGame/src/main/java/shared/xml/regatta/RegattaConfig.java b/racevisionGame/src/main/java/shared/xml/regatta/RegattaConfig.java new file mode 100644 index 00000000..cf72ed5b --- /dev/null +++ b/racevisionGame/src/main/java/shared/xml/regatta/RegattaConfig.java @@ -0,0 +1,219 @@ +// +// 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.09.01 at 10:37:23 PM NZST +// + + +package shared.xml.regatta; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +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="RegattaID" type="{http://www.w3.org/2001/XMLSchema}int"/>
+ * <element name="RegattaName" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ * <element name="CourseName" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ * <element name="CentralLatitude" type="{http://www.w3.org/2001/XMLSchema}double"/>
+ * <element name="CentralLongitude" type="{http://www.w3.org/2001/XMLSchema}double"/>
+ * <element name="CentralAltitude" type="{http://www.w3.org/2001/XMLSchema}double"/>
+ * <element name="UtcOffset" type="{http://www.w3.org/2001/XMLSchema}double"/>
+ * <element name="MagneticVariation" type="{http://www.w3.org/2001/XMLSchema}double"/>
+ * </sequence>
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ *
+ *
+ *
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "", propOrder = {
+ "regattaID",
+ "regattaName",
+ "courseName",
+ "centralLatitude",
+ "centralLongitude",
+ "centralAltitude",
+ "utcOffset",
+ "magneticVariation"
+})
+@XmlRootElement(name = "RegattaConfig")
+public class RegattaConfig {
+
+ @XmlElement(name = "RegattaID")
+ protected int regattaID;
+ @XmlElement(name = "RegattaName", required = true)
+ protected String regattaName;
+ @XmlElement(name = "CourseName", required = true)
+ protected String courseName;
+ @XmlElement(name = "CentralLatitude")
+ protected double centralLatitude;
+ @XmlElement(name = "CentralLongitude")
+ protected double centralLongitude;
+ @XmlElement(name = "CentralAltitude")
+ protected double centralAltitude;
+ @XmlElement(name = "UtcOffset")
+ protected double utcOffset;
+ @XmlElement(name = "MagneticVariation")
+ protected double magneticVariation;
+
+ /**
+ * Gets the value of the regattaID property.
+ *
+ */
+ public int getRegattaID() {
+ return regattaID;
+ }
+
+ /**
+ * Sets the value of the regattaID property.
+ *
+ */
+ public void setRegattaID(int value) {
+ this.regattaID = value;
+ }
+
+ /**
+ * Gets the value of the regattaName property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getRegattaName() {
+ return regattaName;
+ }
+
+ /**
+ * Sets the value of the regattaName property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setRegattaName(String value) {
+ this.regattaName = value;
+ }
+
+ /**
+ * Gets the value of the courseName property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getCourseName() {
+ return courseName;
+ }
+
+ /**
+ * Sets the value of the courseName property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setCourseName(String value) {
+ this.courseName = value;
+ }
+
+ /**
+ * Gets the value of the centralLatitude property.
+ *
+ */
+ public double getCentralLatitude() {
+ return centralLatitude;
+ }
+
+ /**
+ * Sets the value of the centralLatitude property.
+ *
+ */
+ public void setCentralLatitude(double value) {
+ this.centralLatitude = value;
+ }
+
+ /**
+ * Gets the value of the centralLongitude property.
+ *
+ */
+ public double getCentralLongitude() {
+ return centralLongitude;
+ }
+
+ /**
+ * Sets the value of the centralLongitude property.
+ *
+ */
+ public void setCentralLongitude(double value) {
+ this.centralLongitude = value;
+ }
+
+ /**
+ * Gets the value of the centralAltitude property.
+ *
+ */
+ public double getCentralAltitude() {
+ return centralAltitude;
+ }
+
+ /**
+ * Sets the value of the centralAltitude property.
+ *
+ */
+ public void setCentralAltitude(double value) {
+ this.centralAltitude = value;
+ }
+
+ /**
+ * Gets the value of the utcOffset property.
+ *
+ */
+ public double getUtcOffset() {
+ return utcOffset;
+ }
+
+ /**
+ * Sets the value of the utcOffset property.
+ *
+ */
+ public void setUtcOffset(double value) {
+ this.utcOffset = value;
+ }
+
+ /**
+ * Gets the value of the magneticVariation property.
+ *
+ */
+ public double getMagneticVariation() {
+ return magneticVariation;
+ }
+
+ /**
+ * Sets the value of the magneticVariation property.
+ *
+ */
+ public void setMagneticVariation(double value) {
+ this.magneticVariation = value;
+ }
+
+}
diff --git a/racevisionGame/src/main/java/shared/xml/regatta/RegattaDataSourceToXML.java b/racevisionGame/src/main/java/shared/xml/regatta/RegattaDataSourceToXML.java
new file mode 100644
index 00000000..bbe1dce6
--- /dev/null
+++ b/racevisionGame/src/main/java/shared/xml/regatta/RegattaDataSourceToXML.java
@@ -0,0 +1,54 @@
+package shared.xml.regatta;
+
+import shared.dataInput.RegattaDataSource;
+import shared.xml.Race.XMLRace;
+import shared.xml.XMLUtilities;
+
+import javax.xml.bind.JAXBException;
+
+/**
+ * Has functions to convert a {@link shared.dataInput.RegattaDataSource} to an {@link RegattaConfig} object.
+ */
+public class RegattaDataSourceToXML {
+
+
+ /**
+ * Converts a regatta data source to an XMLRace object.
+ * @param regattaDataSource The data source to convert.
+ * @return The XMLRace file.
+ */
+ public static RegattaConfig toXML(RegattaDataSource regattaDataSource) {
+
+ RegattaConfig regatta = new RegattaConfig();
+
+ regatta.setCentralAltitude(regattaDataSource.getCentralAltitude());
+ regatta.setCentralLatitude(regattaDataSource.getCentralLatitude());
+ regatta.setCentralLongitude(regattaDataSource.getCentralLongitude());
+
+ regatta.setCourseName(regattaDataSource.getCourseName());
+
+ regatta.setRegattaName(regattaDataSource.getRegattaName());
+
+ regatta.setMagneticVariation(regattaDataSource.getMagneticVariation());
+
+ regatta.setRegattaID(regattaDataSource.getRegattaID());
+
+ regatta.setUtcOffset(regattaDataSource.getUtcOffset());
+
+ return regatta;
+ }
+
+
+ /**
+ * Converts a regatta data source to an xml string.
+ * @param regattaDataSource Data source to convert.
+ * @return String containing xml file.
+ * @throws JAXBException Thrown if it cannot be converted.
+ */
+ public static String toString(RegattaDataSource regattaDataSource) throws JAXBException {
+ RegattaConfig regatta = toXML(regattaDataSource);
+ return XMLUtilities.classToXML(regatta);
+ }
+
+
+}
diff --git a/racevisionGame/src/main/resources/mock/mockXML/schema/regattaSchema.xsd b/racevisionGame/src/main/resources/mock/mockXML/schema/regattaSchema.xsd
new file mode 100644
index 00000000..5c9fb774
--- /dev/null
+++ b/racevisionGame/src/main/resources/mock/mockXML/schema/regattaSchema.xsd
@@ -0,0 +1,17 @@
+
+