Skip to content

Instantly share code, notes, and snippets.

@mattiasarro
Created March 8, 2012 03:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattiasarro/1998309 to your computer and use it in GitHub Desktop.
Save mattiasarro/1998309 to your computer and use it in GitHub Desktop.
port = new Airport(1);
port = new Airport("/custom/path.xml");
port.save();
port.save("/custom/path.xml")
private XMLHandler handler;
public Airport() {
this(240, 50, 300, "Heathrow");
handler = new XMLHandler();
}
// load from XML/airport_ID.xml
public Airport(int airportId) {
handler = new XMLHandler(airportId);
handler.initializeAirport(this);
}
// could point to a user-specified location
public Airport(String xmlLocation) {
handler = new XMLHandler(xmlLocation);
handler.initializeAirport(this);
}
// When initialized from airportID or xmlLocation, save back to the same file.
// Otherwise save to the next free XML/airport_ID.xml
public void saveXML() {
if (handler == null) {
handler = new XMLHandler();
}
handler.saveAirport(this);
}
// No matter how it was initialized, save to xmlLocation.
public void saveXML(String xmlLocation) {
handler.saveAirport(this, xmlLocation);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment