mapss.dif.language
Class DIFWriter

java.lang.Object
  extended by mapss.dif.language.DIFWriter
Direct Known Subclasses:
BCSDFToDIFWriter, BDFToDIFWriter, CSDFToDIFWriter, HSDFToDIFWriter, MDSDFToDIFWriter, PSDFSpecificationToDIFWriter, PSDFToDIFWriter, SDFToDIFWriter, SingleRateToDIFWriter

public class DIFWriter
extends java.lang.Object

DIFWriter class. Writer class for graphs / hierarchies of runtime type DIFGraph / DIFHierarchy.

This class compiles a DIFGraph or DIFHierarchy instance to dif specification. It traces down to lowest level hierarchies and all subhierarchies of the given hierarchy are compiled into dif specificaitons.

If a writer with another graph type is needed, this class can be extended overriding the methods _getEmptyGraph(), _graphType(), _writeBuiltinAttribute() and _isKeyWord(java.lang.String) in an appropriate way. Labels of graph elements are obtained using DIFGraph.getName() method.

The name of graph definition in the dif specificaiton is from Hierarchy.getName() not from DIFGraph.getName().

Version:
$Id: DIFWriter.java 420 2007-06-04 18:07:42Z jerryhsu $
Author:
Chia-Jui Hsu
See Also:
LanguageAnalysis, Reader, DIFHierarchy, DIFGraph, Writer

Field Summary
protected  DIFGraph _graph
           
protected  DIFHierarchy _hierarchy
           
 
Constructor Summary
DIFWriter()
          Constructor.
 
Method Summary
protected  java.lang.StringBuffer _blank(int num)
          Output blank spaces.
protected  void _checkLabel(java.lang.String label)
          Check to see if the name conflicts with reserved labels or not.
protected  DIFGraph _getEmptyGraph()
          Returns an empty graph with the runtime type of the graphs that are going to be written by this writer.
protected  java.lang.String _getObjectName(java.lang.Object reference)
          Get object name.
protected  java.lang.String _graphType()
          Returns a string containing the graph type keyword to be written into the dif file.
protected  boolean _isKeyWord(java.lang.String word)
          Checks if a string is a keyword in DIF.
protected  java.lang.String _writeActor()
          Generate the actor block.
protected  java.lang.String _writeBuiltinAttribute()
          Generate the built-in attribute block.
protected  java.lang.String _writeInterface()
          Generate the interface block.
protected  java.lang.String _writeParameter()
          Generate the parameter block.
protected  java.lang.String _writeRefinement()
          Generate the refinement block.
protected  java.lang.String _writeTopology()
          Generate the topology block.
protected  java.lang.String _writeUserDefAttribute()
          Generate the interface block.
 java.lang.String compile(DIFGraph graph)
          Compile the single level graph to dif specification.
 java.lang.String compile(DIFHierarchy hierarchy)
          Compile the single level hierarchy to dif specification.
 DIFGraph getSupportedGraph()
          Get the empty graph with runtime type supported by this class or the derived classes.
 java.lang.String objectToString(java.lang.Object value)
          Convert Object value to string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_graph

protected DIFGraph _graph

_hierarchy

protected DIFHierarchy _hierarchy
Constructor Detail

DIFWriter

public DIFWriter()
Constructor.

Method Detail

compile

public java.lang.String compile(DIFGraph graph)
                         throws DIFLanguageException
Compile the single level graph to dif specification.

Throws:
DIFLanguageException - If the runtime type of the graph is not the _getEmptyGraph() or encounter DIF language error in compiling.

compile

public java.lang.String compile(DIFHierarchy hierarchy)
                         throws DIFLanguageException
Compile the single level hierarchy to dif specification.

Throws:
DIFLanguageException - If the runtime type of the graph is not the _getEmptyGraph() or encounter DIF language error in compiling.

getSupportedGraph

public DIFGraph getSupportedGraph()
Get the empty graph with runtime type supported by this class or the derived classes.


objectToString

public java.lang.String objectToString(java.lang.Object value)
Convert Object value to string. value can be instanceof: Integer, Double, Complex, String, Boolean, int[], double[], Complex[], int[][], double[][], Complex[][], ArrayList.

Parameters:
value -
Returns:
A converted string.

_blank

protected java.lang.StringBuffer _blank(int num)
Output blank spaces.

Parameters:
num - Number of white spaces.
Returns:
A StringBuffer of white spaces.

_checkLabel

protected void _checkLabel(java.lang.String label)
                    throws DIFLanguageException
Check to see if the name conflicts with reserved labels or not.

Parameters:
label - The string need to be checked.
Throws:
DIFLanguageException - If label is a keyword.

_getEmptyGraph

protected DIFGraph _getEmptyGraph()
Returns an empty graph with the runtime type of the graphs that are going to be written by this writer. This is used for a class check in the constructor to prevent usage of incompatible graph types.

Returns:
An empty DIFGraph.

_graphType

protected java.lang.String _graphType()
Returns a string containing the graph type keyword to be written into the dif file. It is "dif" for this implementation.

Returns:
A string.

_getObjectName

protected java.lang.String _getObjectName(java.lang.Object reference)
Get object name.

Parameters:
reference - An object of Node/Edge/Port/DIFParameter or a LinkedList of above.
Returns:
The name of that object or a list of names. If it cannot find any one of the object's name in the LinkedList, it returns null.

_isKeyWord

protected boolean _isKeyWord(java.lang.String word)
Checks if a string is a keyword in DIF. Keywords should not be used as labels in graphs.

Parameters:
word - A string to be checked.
Returns:
True if the string is a keyword in DIF.

_writeActor

protected java.lang.String _writeActor()
                                throws DIFLanguageException
Generate the actor block.

Returns:
The DIF specification of the actor block .
Throws:
DIFLanguageException

_writeBuiltinAttribute

protected java.lang.String _writeBuiltinAttribute()
                                           throws DIFLanguageException
Generate the built-in attribute block. The subpackage of dif package should have a xxxToDIFWriter.java which inherits this class and override this method for the built-in attribute of that dataflow graph.

Returns:
The DIF specification of the built-in attribute block.
Throws:
DIFLanguageException

_writeInterface

protected java.lang.String _writeInterface()
                                    throws DIFLanguageException
Generate the interface block.

Returns:
The DIF specification of the interface block .
Throws:
DIFLanguageException

_writeParameter

protected java.lang.String _writeParameter()
                                    throws DIFLanguageException
Generate the parameter block.

Returns:
The DIF specification of the parameter block .
Throws:
DIFLanguageException

_writeRefinement

protected java.lang.String _writeRefinement()
                                     throws DIFLanguageException
Generate the refinement block.

Returns:
The DIF specification of the refinement block .
Throws:
DIFLanguageException

_writeTopology

protected java.lang.String _writeTopology()
                                   throws DIFLanguageException
Generate the topology block.

Returns:
The DIF specification of the topology block .
Throws:
DIFLanguageException

_writeUserDefAttribute

protected java.lang.String _writeUserDefAttribute()
                                           throws DIFLanguageException
Generate the interface block. All user defined arrtibutes regarding to nodes are writen in the actor block. At this time, user-defined attributes for graph and edges are allowed to be value only.

Returns:
The DIF specification of the interface block .
Throws:
DIFLanguageException