org.geotools.graph.io.standard
Class TextfileReaderWriter

java.lang.Object
  extended byorg.geotools.graph.io.standard.AbstractReaderWriter
      extended byorg.geotools.graph.io.standard.TextfileReaderWriter
All Implemented Interfaces:
FileReaderWriter, GraphReaderWriter

public abstract class TextfileReaderWriter
extends AbstractReaderWriter
implements FileReaderWriter

An implementation of GraphReaderWriter that reads/writes graphs from/to text files. Each line of the text file represents an object to be modelled by the graph.
When performing a read, the text file is read line by line. As each line is read it is tokenized based on the delimiter property, and passed to the template method readInternal(StringTokenizer), which must be implemented by a subclass. The method returns the object that is to be represented in the graph. The returned object is then passed to an underlying GraphGenerator which creates the necessary graph components to modell the object.

When performing a write, the graph is read component by component based on set properties. If the NODES property is set, nodes will be written. If the EDGES property is set, edges will be written as well. As each component is processed, it is passed to the repspective template methods writeNode(Writer,Node) and writeEdge(Writer,Edge). The methods then write out the text representation of the component.

Author:
Justin Deoliveira, Refractions Research Inc, jdeolive@refractions.net

Field Summary
static java.lang.String DELIMITER
          line delimiter key
 
Fields inherited from class org.geotools.graph.io.standard.AbstractReaderWriter
BUILDER, EDGES, GENERATOR, NODES
 
Fields inherited from interface org.geotools.graph.io.standard.FileReaderWriter
FILENAME
 
Constructor Summary
TextfileReaderWriter()
           
 
Method Summary
 Graph read()
          Performs a read of the text file line by line.
protected abstract  java.lang.Object readInternal(java.util.StringTokenizer st)
          Template method for returning the object represented by a line in the text file being read.
 void write(Graph g)
          Performs a write on the graph out to a text file.
protected  void writeEdge(java.io.Writer out, Edge e)
          Template method for writing the text representation of an edge to an text file.
protected  void writeNode(java.io.Writer out, Node n)
          Template method for writing the text representation of a node to an text file.
 
Methods inherited from class org.geotools.graph.io.standard.AbstractReaderWriter
getProperty, setProperty, setProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.geotools.graph.io.GraphReaderWriter
getProperty, setProperty
 

Field Detail

DELIMITER

public static final java.lang.String DELIMITER
line delimiter key

See Also:
Constant Field Values
Constructor Detail

TextfileReaderWriter

public TextfileReaderWriter()
Method Detail

read

public Graph read()
           throws java.lang.Exception
Performs a read of the text file line by line. As each line is read the corresponding graph components represented by the line of text are created by an underlying GraphGenerator.

Specified by:
read in interface GraphReaderWriter
Returns:
The represented graph.
Throws:
java.lang.Exception
See Also:
GraphGenerator#read()

write

public void write(Graph g)
           throws java.lang.Exception
Performs a write on the graph out to a text file. If the NODES property is set, the nodes of the graph will be written, and if the EDGES property is set, the edges of the graph will be written. * @see GraphGenerator#write()

Specified by:
write in interface GraphReaderWriter
Parameters:
g - The graph to be
Throws:
java.lang.Exception

writeNode

protected void writeNode(java.io.Writer out,
                         Node n)
Template method for writing the text representation of a node to an text file.

Parameters:
out - The text file writer.
n - The node to write.

writeEdge

protected void writeEdge(java.io.Writer out,
                         Edge e)
Template method for writing the text representation of an edge to an text file.

Parameters:
out - The text file writer.
e - The edge to write.

readInternal

protected abstract java.lang.Object readInternal(java.util.StringTokenizer st)
Template method for returning the object represented by a line in the text file being read.

Parameters:
st - The tokenized line read from text file.
Returns:
The object represented by the line of text.


Copyright © GeoTools. All Rights Reserved.