ptolemy.backtrack.ui
Class BacktrackTransformer.RenameClassMoMLFilter

java.lang.Object
  extended by ptolemy.backtrack.ui.BacktrackTransformer.RenameClassMoMLFilter
All Implemented Interfaces:
MoMLFilter
Enclosing class:
BacktrackTransformer

private static class BacktrackTransformer.RenameClassMoMLFilter
extends java.lang.Object
implements MoMLFilter

The MoML filter that renames the actor classes in the model, if there are backtracking versions for them. No change is done on the actor classes that do not have backtracking versions.

Since:
Ptolemy II 5.1
Version:
$Id: BacktrackTransformer.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Thomas Feng
Accepted Rating:
Red (tfeng)
Proposed Rating:
Red (tfeng)

Field Summary
private  java.util.Stack<java.lang.String> _classStack
          The stack of the name of the classes that have been changed.
private  java.util.List<NamedObj> _entitiesChanged
          The list of entities changed during the parsing.
private  MoMLParser _parser
          The parser to parse extra content (e.g., icon MoML).
static java.lang.String AUTOMATIC_PREFIX
          The prefix to the automatically generated backtracking version of actors.
static java.lang.String MANUAL_PREFIX
          The prefix to the manually written backtracking version of actors.
 
Constructor Summary
private BacktrackTransformer.RenameClassMoMLFilter()
           
 
Method Summary
private static boolean _classExists(java.lang.String className)
          Test whether a class with the given name can be found.
private  void _copyIcon(NamedObj container)
          Copy the icon of the last modified class (of a Ptolemy actor) to the MoML within the container's context.
private static java.lang.String _newClassName(java.lang.String oldClassName)
          Get the new name for class to be changed to its backtracking version.
private  NamedObj _parse(java.io.Reader reader, java.lang.String systemID, NamedObj container)
          Parse the content in the reader within the context of the container.
 java.util.Iterator<NamedObj> entitiesChanged()
          Return the entities that are changed during the last XML parsing.
 java.lang.String filterAttributeValue(NamedObj container, java.lang.String element, java.lang.String attributeName, java.lang.String attributeValue, java.lang.String xmlFile)
          Filter the value of the attribute.
 void filterEndElement(NamedObj container, java.lang.String elementName, java.lang.StringBuffer currentCharData, java.lang.String xmlFile)
          Further process the XML element when it is closed with an end tag.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface ptolemy.moml.MoMLFilter
toString
 

Field Detail

AUTOMATIC_PREFIX

public static final java.lang.String AUTOMATIC_PREFIX
The prefix to the automatically generated backtracking version of actors.

See Also:
Constant Field Values

MANUAL_PREFIX

public static final java.lang.String MANUAL_PREFIX
The prefix to the manually written backtracking version of actors.

See Also:
Constant Field Values

_classStack

private java.util.Stack<java.lang.String> _classStack
The stack of the name of the classes that have been changed.


_entitiesChanged

private java.util.List<NamedObj> _entitiesChanged
The list of entities changed during the parsing.


_parser

private MoMLParser _parser
The parser to parse extra content (e.g., icon MoML).

Constructor Detail

BacktrackTransformer.RenameClassMoMLFilter

private BacktrackTransformer.RenameClassMoMLFilter()
Method Detail

entitiesChanged

public java.util.Iterator<NamedObj> entitiesChanged()
Return the entities that are changed during the last XML parsing.

Returns:
The entities that are changed.

filterAttributeValue

public java.lang.String filterAttributeValue(NamedObj container,
                                             java.lang.String element,
                                             java.lang.String attributeName,
                                             java.lang.String attributeValue,
                                             java.lang.String xmlFile)
Filter the value of the attribute. If the attribute corresponds to a Ptolemy actor with a backtracking version, its class name is changed to the class name of its backtracking version.

Specified by:
filterAttributeValue in interface MoMLFilter
Parameters:
container - The container of the attribute.
element - The XML element.
attributeName - The attribute name.
attributeValue - The attribute value.
xmlFile - The file currently being parsed.
Returns:
A new value for the attribute, or the same value to leave it unchanged, or null to cause the current element to be ignored (unless the attributeValue argument is null).

filterEndElement

public void filterEndElement(NamedObj container,
                             java.lang.String elementName,
                             java.lang.StringBuffer currentCharData,
                             java.lang.String xmlFile)
                      throws IllegalActionException
Further process the XML element when it is closed with an end tag. If the element corresponds to a Ptolemy actor that has been changed to its backtracking version, the MoML description of the original actor's icon is copied to the new model, because the backtracking version does not have an icon associated with it.

Specified by:
filterEndElement in interface MoMLFilter
Parameters:
container - The container of the element.
elementName - The XML element to be closed.
currentCharData - The character data, which appears only in the doc and configure elements
xmlFile - The file currently being parsed.
Throws:
IllegalActionException - If the MoML of the original actor's icon cannot be read and inserted into the new model.

_classExists

private static boolean _classExists(java.lang.String className)
Test whether a class with the given name can be found.

Parameters:
className - The name of the class.
Returns:
true if the class is found; false, otherwise.

_copyIcon

private void _copyIcon(NamedObj container)
                throws IllegalActionException
Copy the icon of the last modified class (of a Ptolemy actor) to the MoML within the container's context.

Parameters:
container - The container.
Throws:
IllegalActionException - If the parsing is not successful.

_newClassName

private static java.lang.String _newClassName(java.lang.String oldClassName)
Get the new name for class to be changed to its backtracking version. If the class has a manually written backtracking version, the name of that backtracking version will be returned; if there is no manually written backtracking version for it, but there is an automatically generated backtracking version, the automatically name of the generated version will be returned; otherwise, null will be returned.

Parameters:
oldClassName - The name of the class before change.
Returns:
The new class name, or null.

_parse

private NamedObj _parse(java.io.Reader reader,
                        java.lang.String systemID,
                        NamedObj container)
                 throws java.lang.Exception
Parse the content in the reader within the context of the container.

Parameters:
reader - The reader to be read from.
container - The context of the parsing.
Returns:
The NamedObj returned by the parser.
Throws:
java.lang.Exception - If the parsing is not successful.