Boat and race XML now generated dynamically

- Removed course from XML Generator as it was not needed
- Boat and race XML added
- Method names in Yacht class updated to follow JavaBean standard so they can be read by the template engine

Tags: #story[984]
This commit is contained in:
Michael Rausch
2017-07-20 13:30:55 +12:00
parent 45053ba507
commit 82b219cdba
13 changed files with 180 additions and 40 deletions
+2 -13
View File
@@ -1,22 +1,11 @@
package seng302.models.xml;
import seng302.models.mark.Mark;
import seng302.models.Yacht;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Boats {
private List<Mark> marks;
public Boats(){
marks = new ArrayList<>();
}
public void addMark(Mark m){
marks.add(m);
}
public List<Mark> getMarks(){
return this.marks;
}
}
+19 -1
View File
@@ -1,5 +1,23 @@
package seng302.models.xml;
public class Race {
import seng302.models.Yacht;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Race {
private List<Yacht> yachts;
public Race(){
yachts = new ArrayList<>();
}
public void addBoat(Yacht yacht){
yachts.add(yacht);
}
public List<Yacht> getBoats(){
return Collections.unmodifiableList(yachts);
}
}
@@ -11,8 +11,11 @@ import java.net.URISyntaxException;
public class XMLGenerator {
private static final String XML_TEMPLATE_DIR = "/server_config/xml_templates";
private static final String REGATTA_TEMPLATE_NAME = "regatta.ftlh";
private static final String BOATS_TEMPLATE_NAME = "boats.ftlh";
private static final String RACE_TEMPLATE_NAME = "race.ftlh";
private Configuration configuration;
private Regatta regatta;
private Race race;
/**
* Set up a configuration instance for Apache Freemake
@@ -38,6 +41,10 @@ public class XMLGenerator {
public void setRegatta(Regatta regatta){
this.regatta = regatta;
}
public void setRace(Race race){
this.race = race;
}
private String parseToXmlString(String templateName, XMLMessageSubType type) throws IOException, TemplateException {
Template template;
@@ -52,11 +59,11 @@ public class XMLGenerator {
break;
case BOAT:
template.process(regatta, writer);
template.process(race, writer);
break;
case RACE:
template.process(regatta, writer);
template.process(race, writer);
break;
default:
@@ -88,5 +95,35 @@ public class XMLGenerator {
}
public String getBoatsAsXml() {
String result = null;
if (race == null) return null;
try {
result = parseToXmlString(BOATS_TEMPLATE_NAME, XMLMessageSubType.BOAT);
} catch (TemplateException e) {
System.out.println("[FATAL] Error parsing boats");
} catch (IOException e) {
System.out.println("[FATAL] Error reading boats");
}
return result;
}
public String getRaceAsXml() {
String result = null;
if (race == null) return null;
try {
result = parseToXmlString(RACE_TEMPLATE_NAME, XMLMessageSubType.RACE);
} catch (TemplateException e) {
System.out.println("[FATAL] Error parsing race");
} catch (IOException e) {
System.out.println("[FATAL] Error reading race");
}
return result;
}
}