Changed the XML reader to take an InputStream rather than InputSource- this has changed everything that used an InputSource to use an InputStream. Made the XML Readers actually read after they received a new InputStream. Changed it so the table updates when the boats in the race change. #pair[jjg64, cbt24] #story[782]

This commit is contained in:
Joseph Gardner
2017-05-01 16:42:47 +12:00
parent 3f42d56502
commit 41a94495aa
12 changed files with 42 additions and 28 deletions
@@ -188,6 +188,8 @@ public class StartController extends Controller implements Observer {
if(o instanceof StreamedCourse) {
if(((StreamedCourse) o).getBoats() != null) {
initialiseTables();
}
if(((StreamedCourse)o).getZonedDateTime() != null) {
setRaceClock();
}
}
@@ -11,6 +11,7 @@ import seng302.XMLReader;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.ElementType;
import java.text.ParseException;
import java.util.*;
@@ -48,8 +49,9 @@ public class BoatXMLReader extends XMLReader {
}
}
public BoatXMLReader(InputSource xmlString) throws IOException, SAXException, ParserConfigurationException {
public BoatXMLReader(InputStream xmlString) throws IOException, SAXException, ParserConfigurationException {
super(xmlString);
read();
}
public void read() {
@@ -8,6 +8,7 @@ import seng302.XMLReader;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.io.InputStream;
/**
* Created by jjg64 on 19/04/17.
@@ -43,8 +44,9 @@ public class RegattaXMLReader extends XMLReader {
}
}
public RegattaXMLReader(InputSource xmlString) throws IOException, SAXException, ParserConfigurationException {
public RegattaXMLReader(InputStream xmlString) throws IOException, SAXException, ParserConfigurationException {
super(xmlString);
read();
}
/**
@@ -31,6 +31,8 @@ public class StreamedCourse extends Observable implements RaceDataSource {
boatXMLReader.setParticipants(streamedCourseXMLReader.getParticipants());
boatXMLReader.read();
}
setChanged();
notifyObservers();
}
public StreamedCourseXMLReader getStreamedCourseXMLReader() {
@@ -14,6 +14,7 @@ import seng302.XMLReader;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.io.InputStream;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@@ -64,12 +65,13 @@ public class StreamedCourseXMLReader extends XMLReader {
}
}
public StreamedCourseXMLReader(InputSource xmlString) throws IOException, SAXException, ParserConfigurationException {
public StreamedCourseXMLReader(InputStream xmlString) throws IOException, SAXException, ParserConfigurationException, ParseException, StreamedCourseXMLException {
super(xmlString);
read();
}
private void read() throws ParseException, StreamedCourseXMLException {
readRace();
// readRace();
readParticipants();
readCourse();
}
@@ -128,7 +128,7 @@ public class VisualiserInput implements Runnable
System.out.println("HeartBeat Message! " + heartbeatSeqNum);
break;
case RACESTATUS:
System.out.println("Race Status Message");
//System.out.println("Race Status Message");
break;
case DISPLAYTEXTMESSAGE:
// System.out.println("Display Text Message");
@@ -152,10 +152,14 @@ public class VisualiserInput implements Runnable
e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
} catch (StreamedCourseXMLException e) {
e.printStackTrace();
}
break;
case RACESTARTSTATUS:
System.out.println("Race Start Status Message");
//System.out.println("Race Start Status Message");
break;
case YACHTEVENTCODE:
// System.out.println("Yacht Action Code!");
@@ -11,6 +11,7 @@ import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
/**
* Created by fwy13 on 26/03/2017.
@@ -27,7 +28,8 @@ public abstract class XMLReader {
doc.getDocumentElement().normalize();
}
public XMLReader(InputSource xmlInput) throws ParserConfigurationException, IOException, SAXException {
public XMLReader(InputStream xmlInput) throws ParserConfigurationException, IOException, SAXException {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
doc = dBuilder.parse(xmlInput);