mapss.dif.language
Class Writer

java.lang.Object
  extended by mapss.dif.language.Writer

public class Writer
extends java.lang.Object

Writer class. This class writes all hierarchies to DIF specification. All derived class of DIFGraph or DIFHierarchy can be applied to this Writer. In other words, this Writer class can handle all types of graphs in the DIF package.

The following codes illustrate the usage of Writer:

Writer writer = new Writer(topHierarchy);
writer.compile();
writer.write(fileName);

Version:
$Id: Writer.java 417 2007-06-01 03:52:14Z jerryhsu $
Author:
Chia-Jui Hsu
See Also:
LanguageAnalysis, Reader, DIFHierarchy, DIFGraph, DIFWriter

Constructor Summary
Writer(DIFGraph graph)
          Constructs a Writer object from a graph with a runtime type of DIFGraph.
Writer(DIFHierarchy hierarchy)
          Constructs a Writer object from a DIFHierarchy object.
 
Method Summary
protected  void _depthFirstRetrive(DIFHierarchy hierarchy, java.util.LinkedList levelLinkedList)
          This method will perform depth first traverse of hierarchical Hierarchies.
protected  void _setDIFWriters()
           
 void addDIFWriter(java.lang.Class graphClass, DIFWriter writer)
          Add DIFWriter subclass to writers.
 void compile()
          Compile the DIFHierarchy object associated with this Writer into DIF specification.
 java.util.LinkedList retrieveHierarchy(DIFHierarchy hierarchy)
          This method will retrieve all hierarchies inside the top level DIFHierarchy and put them into a LinkedList in depth first order.
 java.lang.String toString()
          Returns the string representation of this Writer object.
 void write(java.lang.String fileName)
          Write the DIF specification to a DIF file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Writer

public Writer(DIFGraph graph)
       throws DIFLanguageException
Constructs a Writer object from a graph with a runtime type of DIFGraph.

Parameters:
graph - A DIFGraph object.
Throws:
DIFLanguageException

Writer

public Writer(DIFHierarchy hierarchy)
       throws DIFLanguageException
Constructs a Writer object from a DIFHierarchy object. Runtime type of the contained graph should be DIFGraph.

Parameters:
hierarchy - A DIFHierarchy object.
Throws:
DIFLanguageException
Method Detail

addDIFWriter

public void addDIFWriter(java.lang.Class graphClass,
                         DIFWriter writer)
Add DIFWriter subclass to writers. In case of DIFWriter subclass is not specified in writers.txt.

Parameters:
graphClass - The Class of the particular graph object.
writer - The DIFWriter subclass object.

compile

public void compile()
             throws DIFLanguageException
Compile the DIFHierarchy object associated with this Writer into DIF specification. This method traces down to lowest level hierarchies.

Throws:
DIFLanguageException

retrieveHierarchy

public java.util.LinkedList retrieveHierarchy(DIFHierarchy hierarchy)
This method will retrieve all hierarchies inside the top level DIFHierarchy and put them into a LinkedList in depth first order. Hierarchies in the same level are stored in a LinkedList. This method returns a LinkedList of LinkedLists of hierarchies in the lowest level first order.

Parameters:
hierarchy - A DIFHierarchy object.
Returns:
A LinkedList of LinkedLists of hierarchies.

toString

public java.lang.String toString()
Returns the string representation of this Writer object.

Overrides:
toString in class java.lang.Object
Returns:
A DIF string.

write

public void write(java.lang.String fileName)
           throws java.io.IOException
Write the DIF specification to a DIF file.

Parameters:
fileName - A file name string. A ".dif" extension will automatically be appended.
Throws:
java.io.IOException - If the file cannot be written.

_depthFirstRetrive

protected void _depthFirstRetrive(DIFHierarchy hierarchy,
                                  java.util.LinkedList levelLinkedList)
This method will perform depth first traverse of hierarchical Hierarchies.


_setDIFWriters

protected void _setDIFWriters()