ptolemy.moml.filter
Class RelationWidthChanges

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

public class RelationWidthChanges
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 relations that have a width equal to zero for Ptolemy versions 7.2.devel or older. The width value will be changed from 0 to -1, which is the new default for width inference. If the width has not been specified for a models with Ptolemy version less than 7.2.devel, the width will be changed to 1. This because 1 used to be the default value, while now -1 has become the default.

Since:
Ptolemy II 8.0
Version:
$Id: RelationWidthChanges.java 59167 2010-09-21 17:08:02Z cxh $
Author:
Bert Rodiers
Accepted Rating:
Red (rodiers)
Proposed Rating:
Red (rodiers)

Field Summary
private  java.util.Map<java.lang.String,java.lang.Boolean> _changesNeededForXmlFile
          A flag that specifies whether changes might be needed for the model with a certain xmlPath.
private  boolean _currentlyProcessingRelation
          A flag that specifies whether we are currently processing a relation
private  boolean _currentlyProcessingWidth
          A flag that specifies whether we are currently processing the width of a relation
 
Constructor Summary
RelationWidthChanges()
           
 
Method Summary
private  boolean _changedNeeded(NamedObj container, java.lang.String xmlFile)
          Return whether changes are necessary.
 java.lang.String filterAttributeValue(NamedObj container, java.lang.String element, java.lang.String attributeName, java.lang.String attributeValue, java.lang.String xmlFile)
          Filter relations widths and change 0 to -1.
 void filterEndElement(NamedObj container, java.lang.String elementName, java.lang.StringBuffer currentCharData, java.lang.String xmlFile)
          Make modifications to the specified container, which is defined in a MoML element with the specified name.
 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

_currentlyProcessingRelation

private boolean _currentlyProcessingRelation
A flag that specifies whether we are currently processing a relation


_currentlyProcessingWidth

private boolean _currentlyProcessingWidth
A flag that specifies whether we are currently processing the width of a relation


_changesNeededForXmlFile

private java.util.Map<java.lang.String,java.lang.Boolean> _changesNeededForXmlFile
A flag that specifies whether changes might be needed for the model with a certain xmlPath. This is only the case for models older than version 7.2.devel

Constructor Detail

RelationWidthChanges

public RelationWidthChanges()
Method Detail

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 relations widths and change 0 to -1.

Specified by:
filterAttributeValue in interface MoMLFilter
Parameters:
container - The container for XML element.
element - The XML element name.
attributeName - The name of the attribute.
attributeValue - The value of the attribute.
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 java.lang.Exception
Make modifications to the specified container, which is defined in a MoML element with the specified name. This method is called when an end element in MoML is encountered. A typical use of this method is to make some modification to the object (the container) that was constructed.

If an implementor makes changes to the specified container, then it should call MoMLParser.setModified(true) which indicates that the model was modified so that the user can optionally save the modified model.

Specified by:
filterEndElement in interface MoMLFilter
Parameters:
container - The object defined by the element that this is the end of.
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 modifying the specified container.

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:
A description of the filter (ending with a newline).

_changedNeeded

private boolean _changedNeeded(NamedObj container,
                               java.lang.String xmlFile)
Return whether changes are necessary. This is only the case for models older than version 7.2.devel

Parameters:
container - The container.
xmlFile - The xmlFile
Returns:
True when changes are necessary.