mapss.dif.ptolemy
Class DIFGraphImporter

java.lang.Object
  extended by mapss.dif.ptolemy.DIFGraphImporter

public class DIFGraphImporter
extends java.lang.Object

Importing DIF to Ptolemy models. This class provides methods for converting from DIF to Ptolemy II MoML models.

If the computation attribute of a node starts with "ptolemy.actor.lib" or "ptolemy.domains.sdf.lib", it is an AtomicActor and it's ptolemy class can be found based on the computation attribute. If the computation attribute of a node is "ptolemy.actor.TypedCompositeActor", it is a CompositeActor. If the computation attribute of a node is "dif.fork", it is used to represent a TypedIORelation with multiple destinations. If the computation attribute of a node is not above, we decide it's ptolemy class based on the computation attribute.

This class performs the reverse functions of DIFGraphExporter. Usage:

DIFGraphImporter importer = new DIFGraphImporter(DIFHierarchy object);
TypedCompositeActor composite = importer.convert();
String xmlString = importer.toXML();
importer.write(fileName);

Version:
$Id: DIFGraphImporter.java 409 2007-05-13 19:47:16Z plishker $
Author:
Chia-Jui Hsu
See Also:
DIFGraph, DIFGraphImporter, Hierarchy

Constructor Summary
DIFGraphImporter(DIFGraph graph)
          Constructor.
DIFGraphImporter(DIFHierarchy hierarchy)
          Constructor.
DIFGraphImporter(java.lang.String fileName)
          Constructor.
 
Method Summary
protected  void _convertHierarchy(DIFHierarchy hierarchy, ptolemy.actor.TypedCompositeActor composite)
          After make sure a supernode in DIF is really corresponding to a composite actor in ptolemy, this function will be call for that supernode.
protected  ptolemy.data.Token _getAttributeValue(DIFAttribute attribute)
          Convert the value contained by the DIFAttribute to Token.
protected  java.lang.String _getComputation(mocgraph.Node node, DIFGraph graph)
          Get the "computation" attribute if Node node.
protected  void _initializeImporter()
          Initialize DIFGraphImporter.
protected  int _nodeType(mocgraph.Node node, DIFHierarchy hierarchy)
          Find the node type.
protected  DIFHierarchy _readFile(java.lang.String difFileName)
          Read .dif file.
 java.lang.Object convert()
          Converting from the associated DIFHierarchy to CompositeActor.
 java.lang.String toXML()
          Import ptolemy .xml model as a string.
 void write(java.lang.String fileName)
          Write the converted composite actor to ptolemy .xml file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DIFGraphImporter

public DIFGraphImporter(DIFHierarchy hierarchy)
Constructor.

Parameters:
hierarchy - The DIFHierarchy associated with this DIFGraphImporter.

DIFGraphImporter

public DIFGraphImporter(DIFGraph graph)
Constructor.

Parameters:
graph - The DIFGraph associated with this DIFGraphImporter. In this case, there is only a single level graph (hierarchy).

DIFGraphImporter

public DIFGraphImporter(java.lang.String fileName)
Constructor.

Parameters:
fileName - The .dif file.
Method Detail

convert

public java.lang.Object convert()
Converting from the associated DIFHierarchy to CompositeActor.

Returns:
The converted Ptolemy CompositeActor.

toXML

public java.lang.String toXML()
Import ptolemy .xml model as a string.

Returns:
The converted xml string.

write

public void write(java.lang.String fileName)
Write the converted composite actor to ptolemy .xml file.

Parameters:
fileName -

_convertHierarchy

protected void _convertHierarchy(DIFHierarchy hierarchy,
                                 ptolemy.actor.TypedCompositeActor composite)
After make sure a supernode in DIF is really corresponding to a composite actor in ptolemy, this function will be call for that supernode. This function will first create AtomicActor or CompositeActor in ptolemy according to the dif specification. If CompositeActor, then this function will be called recursively. After deploying all actors, this function will put TypedIOPort for interface, and then use relations to link all components.

Parameters:
hierarchy - The DIFHierarchy to be converted.
composite - The corresponding ptolemy CompositeActor.

_getAttributeValue

protected ptolemy.data.Token _getAttributeValue(DIFAttribute attribute)
Convert the value contained by the DIFAttribute to Token. If the value of DIFAttribute refers to Port, Edge, Node, this method returns null. If the value of DIFAttribute refers to DIFParameter, this method will find the value recursively.

Returns:
Token value.

_getComputation

protected java.lang.String _getComputation(mocgraph.Node node,
                                           DIFGraph graph)
Get the "computation" attribute if Node node. This attribute stores the class name of the actor represented by node.

Parameters:
node - The Node.
graph - The DIFGraph contains node.
Returns:
The string of the class name of the actor represented by node.

_nodeType

protected int _nodeType(mocgraph.Node node,
                        DIFHierarchy hierarchy)
Find the node type.

0: illegal, 1: TypedAtomicActor in lib, 2: TypedCompositeActor, 3: user-defined actor, 4: TypedIORelaation.

Returns:
The int represented the node type.

_initializeImporter

protected void _initializeImporter()
Initialize DIFGraphImporter.


_readFile

protected DIFHierarchy _readFile(java.lang.String difFileName)
Read .dif file. DIFGraphImporter will first convert this dif specification to DIFHierarchy.

Parameters:
difFileName -
Returns:
The DIFHierarchy.