world
Class WorldFileParser

java.lang.Object
  extended byorg.xml.sax.helpers.DefaultHandler
      extended byworld.WorldFileParser
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

public final class WorldFileParser
extends org.xml.sax.helpers.DefaultHandler

A parser for world files.

Author:
Piotrek

Field Summary
private  int airportID
          An ID of the current airport.
private  java.lang.String airportName
          A name of the airport.
private  int arrivalTime
          An arrival time for the station assigned to the connection.
private  int busStopID
          An ID of the current bus stop.
private  java.lang.String busStopName
          A name of the bus stop.
private  java.util.ArrayList cities
          A list of all parsed cities.
private  java.lang.String cityName
          A name of a city.
private  java.util.ArrayList connectionArrivalTimes
          A list of arrival times for the current connection.
private  java.util.ArrayList connectionDepartureTimes
          A list of departure times for the current connection.
private  int connectionMeanOfTransportation
          A mean of transportation for the connection.
private  java.lang.String connectionName
          A name of the connection.
private  java.util.ArrayList connections
          A list of all parsed connections.
private  java.util.ArrayList connectionStations
          A list of stations assigned to the current connection.
private  java.lang.String continentName
          The continentName name in the location.
private  char dayOfWeekFlag
          A day of the week flag for the connection.
private  int departureTime
          A departure time for the station assigned to the connection.
private  boolean fInAirport
          Indicates whether the parser is inside an `airport' tag.
private  boolean fInAirports
          Indicates whether the parser is inside an `airports' tag.
private  boolean fInArrivalTimes
          Indicates whether the parser is inside a `arrival times' tag.
private  boolean fInBusStop
          Indicates whether the parser is inside a `bus stop' tag.
private  boolean fInBusStops
          Indicates whether the parser is inside a `bus stops' tag.
private  boolean fInCities
          Indicates whether the parser is inside a `cities' tag.
private  boolean fInCity
          Indicates whether the parser is inside a `city' tag.
private  boolean fInConnection
          Indicates whether the parser is inside a `connection' tag.
private  boolean fInConnections
          Indicates whether the parser is inside a `connections' tag.
private  boolean fInDaysOfWeek
          Indicates whether the parser is inside a `days of week' tag.
private  boolean fInDepartureTimes
          Indicates whether the parser is inside a `departure times' tag.
private  boolean fInHarbour
          Indicates whether the parser is inside a `harbour' tag.
private  boolean fInHarbours
          Indicates whether the parser is inside a `harbours' tag.
private  boolean fInLocation
          Indicates whether the parser is inside a `location' tag.
private  boolean fInStationIDs
          Indicates whether the parser is inside a `stations ids' tag.
private  boolean fInTrainStation
          Indicates whether the parser is inside a `train station' tag.
private  boolean fInTrainStations
          Indicates whether the parser is inside a `train stations' tag.
private  boolean fInWorld
          Indicates whether the parser is inside a `world' tag.
private  int harbourID
          An ID of the current harbour.
private  java.lang.String harbourName
          A name of the harbour.
private  java.util.HashMap idToStationMap
          A maping from tha station ID to the station.
private  java.lang.String islandName
          The the island name in the location.
private  org.xml.sax.Locator locator
          The SAX locator.
private  int stationID
          An ID of the station assigned to the connection.
private  java.util.ArrayList stations
          A list of all parsed stations.
private  int trainStationID
          An ID of the current train station.
private  java.lang.String trainStationName
          A name of the train station.
private  java.util.ArrayList usedConnectionNames
          A list of used connection names.
private  java.util.ArrayList usedIDs
          A list of used IDs for the stations.
private  int x
          The x coordinate of the location.
private  int y
          The y coordinate of the location.
 
Constructor Summary
WorldFileParser()
          Constructor.
 
Method Summary
private  void ChangeWorld()
          Changes the world to the parsed one.
private  void ClearData()
          Clears all the internal data, so the parser is ready to parse a new file.
private  void ClearLocation()
          Clears the data of the connection.
private static javax.xml.parsers.SAXParser CreateSAXParser()
          Creates an instance of the SAXParser.
 void endElement(java.lang.String uriNamespace, java.lang.String qualifiedName, java.lang.String simpleName)
           
private  Location GetLocation()
          Gets the location built basing on the parsed data.
private  boolean IsLocationParsed()
          Indicates whether the location tag has been parsed completely.
 void Parse(java.lang.String fileName)
          Parses the given file.
 void setDocumentLocator(org.xml.sax.Locator locator)
           
 void startElement(java.lang.String uriNamespace, java.lang.String simpleName, java.lang.String qualifiedName, org.xml.sax.Attributes attributes)
           
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
characters, endDocument, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fInWorld

private boolean fInWorld
Indicates whether the parser is inside a `world' tag.


fInCities

private boolean fInCities
Indicates whether the parser is inside a `cities' tag.


fInCity

private boolean fInCity
Indicates whether the parser is inside a `city' tag.


fInLocation

private boolean fInLocation
Indicates whether the parser is inside a `location' tag.


fInAirports

private boolean fInAirports
Indicates whether the parser is inside an `airports' tag.


fInAirport

private boolean fInAirport
Indicates whether the parser is inside an `airport' tag.


fInBusStops

private boolean fInBusStops
Indicates whether the parser is inside a `bus stops' tag.


fInBusStop

private boolean fInBusStop
Indicates whether the parser is inside a `bus stop' tag.


fInTrainStations

private boolean fInTrainStations
Indicates whether the parser is inside a `train stations' tag.


fInTrainStation

private boolean fInTrainStation
Indicates whether the parser is inside a `train station' tag.


fInHarbours

private boolean fInHarbours
Indicates whether the parser is inside a `harbours' tag.


fInHarbour

private boolean fInHarbour
Indicates whether the parser is inside a `harbour' tag.


fInConnections

private boolean fInConnections
Indicates whether the parser is inside a `connections' tag.


fInConnection

private boolean fInConnection
Indicates whether the parser is inside a `connection' tag.


fInStationIDs

private boolean fInStationIDs
Indicates whether the parser is inside a `stations ids' tag.


fInArrivalTimes

private boolean fInArrivalTimes
Indicates whether the parser is inside a `arrival times' tag.


fInDepartureTimes

private boolean fInDepartureTimes
Indicates whether the parser is inside a `departure times' tag.


fInDaysOfWeek

private boolean fInDaysOfWeek
Indicates whether the parser is inside a `days of week' tag.


cityName

private java.lang.String cityName
A name of a city. Valid only if in a city tag.


airportName

private java.lang.String airportName
A name of the airport. Valid only if in an airport tag.


airportID

private int airportID
An ID of the current airport. Valid only if in an airport tag.


busStopName

private java.lang.String busStopName
A name of the bus stop. Valid only if in a bus stop tag.


busStopID

private int busStopID
An ID of the current bus stop. Valid only if in a bus stop tag.


trainStationName

private java.lang.String trainStationName
A name of the train station. Valid only if in a train station tag.


trainStationID

private int trainStationID
An ID of the current train station. Valid only if in a train station tag.


harbourName

private java.lang.String harbourName
A name of the harbour. Valid only if in a harbour tag.


harbourID

private int harbourID
An ID of the current harbour. Valid only if in a harbour tag.


connectionName

private java.lang.String connectionName
A name of the connection.


connectionMeanOfTransportation

private int connectionMeanOfTransportation
A mean of transportation for the connection.


usedIDs

private java.util.ArrayList usedIDs
A list of used IDs for the stations. Used to verify if the new ID is unique.


usedConnectionNames

private java.util.ArrayList usedConnectionNames
A list of used connection names. Used to verify if the new connection name is unique.


stationID

private int stationID
An ID of the station assigned to the connection.


idToStationMap

private java.util.HashMap idToStationMap
A maping from tha station ID to the station.


stations

private java.util.ArrayList stations
A list of all parsed stations.


arrivalTime

private int arrivalTime
An arrival time for the station assigned to the connection.


departureTime

private int departureTime
A departure time for the station assigned to the connection.


dayOfWeekFlag

private char dayOfWeekFlag
A day of the week flag for the connection.


x

private int x
The x coordinate of the location.


y

private int y
The y coordinate of the location.


continentName

private java.lang.String continentName
The continentName name in the location.


islandName

private java.lang.String islandName
The the island name in the location.


cities

private java.util.ArrayList cities
A list of all parsed cities.


connectionStations

private java.util.ArrayList connectionStations
A list of stations assigned to the current connection.


connectionArrivalTimes

private java.util.ArrayList connectionArrivalTimes
A list of arrival times for the current connection.


connectionDepartureTimes

private java.util.ArrayList connectionDepartureTimes
A list of departure times for the current connection.


connections

private java.util.ArrayList connections
A list of all parsed connections.


locator

private org.xml.sax.Locator locator
The SAX locator.

Constructor Detail

WorldFileParser

public WorldFileParser()
Constructor.

Method Detail

Parse

public void Parse(java.lang.String fileName)
           throws java.lang.Exception,
                  java.io.IOException,
                  org.xml.sax.SAXException
Parses the given file. After a call to this method a world singleton contains a world stored in the given file. The world is changed only if the file has been parsed without any errors.

Parameters:
fileName - The name of the file to be parsed.
Throws:
java.lang.Exception - Thrown in case of error.
java.io.IOException - In case of any IO error.
org.xml.sax.SAXException - In case of some parsing error.

ClearData

private void ClearData()
Clears all the internal data, so the parser is ready to parse a new file.


CreateSAXParser

private static javax.xml.parsers.SAXParser CreateSAXParser()
                                                    throws javax.xml.parsers.ParserConfigurationException,
                                                           org.xml.sax.SAXException
Creates an instance of the SAXParser.

Returns:
The requested parser.
Throws:
javax.xml.parsers.ParserConfigurationException - If it was imposible to create a parser satisfing the current configuration.
org.xml.sax.SAXException

startElement

public void startElement(java.lang.String uriNamespace,
                         java.lang.String simpleName,
                         java.lang.String qualifiedName,
                         org.xml.sax.Attributes attributes)
                  throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException
See Also:
ContentHandler.startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)

endElement

public void endElement(java.lang.String uriNamespace,
                       java.lang.String qualifiedName,
                       java.lang.String simpleName)
                throws org.xml.sax.SAXParseException
Throws:
org.xml.sax.SAXParseException
See Also:
ContentHandler.endElement(java.lang.String, java.lang.String, java.lang.String)

setDocumentLocator

public void setDocumentLocator(org.xml.sax.Locator locator)
See Also:
ContentHandler.setDocumentLocator(org.xml.sax.Locator)

ChangeWorld

private void ChangeWorld()
                  throws java.lang.Exception
Changes the world to the parsed one.

Throws:
java.lang.Exception - Thrown in case of data error.

IsLocationParsed

private boolean IsLocationParsed()
Indicates whether the location tag has been parsed completely.

Returns:
A boolean value indicating whether the location tag has been parsed completely.

GetLocation

private Location GetLocation()
Gets the location built basing on the parsed data.

Returns:
The location builr basing on the parsed data.

ClearLocation

private void ClearLocation()
Clears the data of the connection. Done to detect missing location tags.