ptolemy.moml.filter
Class ClassChanges

java.lang.Object
  extended by ptolemy.moml.filter.ClassChanges
All Implemented Interfaces:
MoMLFilter

public class ClassChanges
extends java.lang.Object
implements MoMLFilter

When this class is registered with the MoMLParser.setMoMLFilter() method, it will cause MoMLParser to filter so that models from earlier releases will run in the current release.

This class will filter moml for simple class changes where the context of the class name to be changed does not matter - all occurrences of the class name will be changed. This class can be though of as a primitive form of sed.

If a class within an actor is what has changed, use (@see PropertyClassChanges) instead.

Since:
Ptolemy II 2.0
Version:
$Id: ClassChanges.java 57046 2010-01-27 23:35:53Z cxh $
Author:
Christopher Hylands
Accepted Rating:
Red (cxh)
Proposed Rating:
Red (cxh)

Field Summary
private static java.util.HashMap _classChanges
           
private static java.util.HashSet _classesToRemove
           
 
Constructor Summary
ClassChanges()
           
 
Method Summary
static void clear()
          Clear the map of class renames and the set of class removals.
 java.lang.String filterAttributeValue(NamedObj container, java.lang.String element, java.lang.String attributeName, java.lang.String attributeValue, java.lang.String xmlFile)
          If the attributeName is "class" and attributeValue names a class that needs to be renamed, then substitute in the new class name.
 void filterEndElement(NamedObj container, java.lang.String elementName, java.lang.StringBuffer currentCharData, java.lang.String xmlFile)
          In this class, do nothing.
 void put(java.lang.String oldName, java.lang.String newName)
          Add a class to be filtered.
 void remove(java.lang.String className)
          Remove a class to be filtered.
 java.lang.String toString()
          Return a string that describes what the filter does.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_classChanges

private static java.util.HashMap _classChanges

_classesToRemove

private static java.util.HashSet _classesToRemove
Constructor Detail

ClassChanges

public ClassChanges()
Method Detail

clear

public static void clear()
Clear the map of class renames and the set of class removals.


filterAttributeValue

public java.lang.String filterAttributeValue(NamedObj container,
                                             java.lang.String element,
                                             java.lang.String attributeName,
                                             java.lang.String attributeValue,
                                             java.lang.String xmlFile)
If the attributeName is "class" and attributeValue names a class that needs to be renamed, then substitute in the new class name. If the attributeValue names a class that needs to be removed, then return null, which will cause the MoMLParser to skip the rest of the element;

Specified by:
filterAttributeValue in interface MoMLFilter
Parameters:
container - The container for this attribute.
element - The XML element name.
attributeName - The name of the attribute.
attributeValue - The value of the attribute.
xmlFile - The file currently being parsed.
Returns:
the value of the attributeValue argument.

filterEndElement

public void filterEndElement(NamedObj container,
                             java.lang.String elementName,
                             java.lang.StringBuffer currentCharData,
                             java.lang.String xmlFile)
                      throws java.lang.Exception
In this class, do nothing.

Specified by:
filterEndElement in interface MoMLFilter
Parameters:
container - The object created by this element.
elementName - The element name.
currentCharData - The character data, which appears only in the doc and configure elements
xmlFile - The file currently being parsed.
Throws:
java.lang.Exception - Not thrown in this base class.

put

public void put(java.lang.String oldName,
                java.lang.String newName)
Add a class to be filtered. Note that if you add a class with this method, then you must remove it with remove(String), calling "new ClassChanges()" will not remove a class that was added with this method.

Parameters:
oldName - The old name of the class to be filtered.
newName - The new name of the class to be filtered. If the value is null, then the class in oldName will be removed.
See Also:
remove(String)

remove

public void remove(java.lang.String className)
Remove a class to be filtered.

Parameters:
className - The name of the class to be filtered out, for example "ptolemy.copernicus.kernel.GeneratorAttribute".
See Also:
put(String, String)

toString

public java.lang.String toString()
Return a string that describes what the filter does.

Specified by:
toString in interface MoMLFilter
Overrides:
toString in class java.lang.Object
Returns:
the description of the filter that ends with a newline.