ptolemy.moml.filter
Class PropertyClassChanges

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

public class PropertyClassChanges
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 for classes with properties where the class name has changed.

For example, after Ptolemy II 2.0.1, the Expression actor changed in such a way that the expression property changed from being a Parameter to being a StringAttribute. To add this change to this filter, we add a code to the static section at the bottom of the file.

 // Expression: After 2.0.1, expression
 // property is now a StringAttribute
 HashMap expressionClassChanges = new HashMap();
 // Key = property name, Value = new class name
 expressionClassChanges.put("expression",
 "ptolemy.kernel.util.StringAttribute");
 
The expressionClassChange HashMap maps property names to the new classname

 _actorsWithPropertyClassChanges
 .put("ptolemy.actor.lib.Expression",
 expressionClassChanges);
 
The _actorsWithPropertyClassChanges HashMap contains all the classes such as Expression that have changes and each class has a map of the property changes that are to be made.

Conceptually, how the code works is that when we see a class while parsing, we check to see if the class is in _actorsWithPropertyClassChanges. If the class was present in the HashMap, then as we go through the code, we look for property names that need to have their classes changed.

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

Field Summary
private static java.util.HashMap _actorsWithPropertyClassChanges
           
private  java.lang.String _currentActorFullName
           
private  boolean _currentlyProcessingActorWithPropertyClassChanges
           
private  boolean _foundChange
           
private  java.lang.String _lastNameSeen
           
private  java.lang.String _newClass
           
private static java.util.HashMap _propertyMap
           
 
Constructor Summary
PropertyClassChanges()
           
 
Method Summary
static void clear()
          Clear the map of actors with property class changes.
 java.lang.String filterAttributeValue(NamedObj container, java.lang.String element, java.lang.String attributeName, java.lang.String attributeValue, java.lang.String xmlFile)
          Return new class names for properties that have been registered as having changed classes.
 void filterEndElement(NamedObj container, java.lang.String elementName, java.lang.StringBuffer currentCharData, java.lang.String xmlFile)
          Reset private variables.
 void put(java.lang.String className, java.util.HashMap propertyClassMap)
          Add a class to be filtered and the old and new property class types.
 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

_actorsWithPropertyClassChanges

private static java.util.HashMap _actorsWithPropertyClassChanges

_currentActorFullName

private java.lang.String _currentActorFullName

_currentlyProcessingActorWithPropertyClassChanges

private boolean _currentlyProcessingActorWithPropertyClassChanges

_lastNameSeen

private java.lang.String _lastNameSeen

_newClass

private java.lang.String _newClass

_foundChange

private boolean _foundChange

_propertyMap

private static java.util.HashMap _propertyMap
Constructor Detail

PropertyClassChanges

public PropertyClassChanges()
Method Detail

clear

public static void clear()
Clear the map of actors with property class changes.


filterAttributeValue

public java.lang.String filterAttributeValue(NamedObj container,
                                             java.lang.String element,
                                             java.lang.String attributeName,
                                             java.lang.String attributeValue,
                                             java.lang.String xmlFile)
Return new class names for properties that have been registered as having changed classes. This filter may also return null to remove the element.

Specified by:
filterAttributeValue in interface MoMLFilter
Parameters:
container - The container for this attribute. in this method.
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 or a new value if the value has changed.

filterEndElement

public void filterEndElement(NamedObj container,
                             java.lang.String elementName,
                             java.lang.StringBuffer currentCharData,
                             java.lang.String xmlFile)
                      throws java.lang.Exception
Reset private variables.

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 - if there is a problem substituting in the new value.

put

public void put(java.lang.String className,
                java.util.HashMap propertyClassMap)
Add a class to be filtered and the old and new property class types. Note that if you add a class with this method, then you must remove it with remove(String), calling "new PropertyClassChanges()" will not remove a class that was added with this method.

Parameters:
className - The name of the class to be filtered out, for example "ptolemy.copernicus.kernel.GeneratorAttribute".
propertyClassMap - The HashMap that has the property name as a key and the new class name as a value. If the value of the HashMap is null then the rest of the attribute is skipped.
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, HashMap)

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.