org.shredzone.repowatch.sync
Class PrimaryParser

java.lang.Object
  extended by org.shredzone.repowatch.sync.PrimaryParser
All Implemented Interfaces:
Iterable<Version>

public class PrimaryParser
extends Object
implements Iterable<Version>

This beast parses a primary.xml file. It also takes care for gunzipping the file and computing the checksum, if desired. The single Version objects found in the xml file are available via readNextVersion(), but this class also implements the Iterable interface, so it can be simply used in a for loop.

Invoke parse() before reading the content. The xml file is processed on the fly, so the memory footprint is rather small even for large xml files. Always invoke discard() after processing or when an exception occured!

Version:
$Revision: 323 $

Constructor Summary
PrimaryParser(Repository repository, DatabaseLocation location)
          Creates a new PrimaryParser.
 
Method Summary
 void discard()
          Frees all resources bound by the parser.
 Iterator<Version> iterator()
          Returns an iterator over the Version entities found.
 void parse()
          Parses the database.
 Version readNextVersion()
          Reads the next Version entity found in the xml file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PrimaryParser

public PrimaryParser(Repository repository,
                     DatabaseLocation location)
Creates a new PrimaryParser. The parser is just created, no network connection is opened yet.

Parameters:
repository - Repository to parse
location - DatabaseLocation with details for the database to be read.
Method Detail

parse

public void parse()
           throws SynchronizerException
Parses the database. A network connection is opened and the xml file is read and processed. The content is available by invoking readNextVersion() or getting an interator by iterator().

Always invoke discard() after completion! Also invoke discard() if an exception occured.

Throws:
SynchronizerException - An error occured while parsing.

readNextVersion

public Version readNextVersion()
                        throws SynchronizerException
Reads the next Version entity found in the xml file. If there are no more entries, null is returned.

Note that a bad checksum is only reported after the last entry was read.

Returns:
Next Version entity that was found, or null if the last entity was processed.
Throws:
SynchronizerException - An error occured while reading.

discard

public void discard()
Frees all resources bound by the parser. Always invoke this method when you are done reading the xml file. You can safely invoke it multiple times.


iterator

public Iterator<Version> iterator()
Returns an iterator over the Version entities found. parse() must be invoked prior to this method.

Specified by:
iterator in interface Iterable<Version>
Returns:
Iterator


Copyright © 2007-2011 shredzone.org. All Rights Reserved.