public class RemoveProperties extends MoMLFilterSimple
For example, after Ptolemy II 5.0, the stopTime parameter has a default value as Infinity instead of MaxDouble (a macro with value of Double.MAX_VALUE). What is more, stopTime is not supposed to be stored in the MoML file. Therefore, this filter filters out those stopTime parameters with the old default value, MaxDouble. The new default value for the stopTime parameter will be created automatically by the Java classes and the parameter will not be exported into the MoML file.
A typical usage looks like the following.
// stopTime after Ptolemy II 5.0 // The stopTime used to have a default value as the Double.MAX_VALUE. // Now the default value is Infinity. HashMap removePropertyStopTime = new HashMap(); // Remove properties whose name is "stopTime" if their // class and value properties are in the HashMap. _propertiesToBeRemoved.put("stopTime", removePropertyStopTime); // The class must be a Parameter for this to be removed. removePropertyStopTime.put("ptolemy.data.expr.Parameter", null); // The value must be one of the following representations of Double.MAX_VALUE. removePropertyStopTime.put("1.7976931348623E308", null); removePropertyStopTime.put("1.797693134862316E308", null); removePropertyStopTime.put("MaxDouble", null); removePropertyStopTime.put(""+Double.MAX_VALUE, null);The removePropertyStopTime HashMap stores all possible matches of the name and class attributes of the MoML entry for this attribute. Given MoML with both a class and a value, then both must match for the property to be removed. The _propertiesToBeRemoved HashMap contains all the properties such as the stopTime parameter that will be removed.
Note that this filter has a limitation. This filter assumes that the property to be removed always has three attributes, name, class, and value, and they are always in this order.
Red (hyzheng) |
Red (hyzheng) |
Constructor and Description |
---|
RemoveProperties() |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
filterAttributeValue(NamedObj container,
java.lang.String element,
java.lang.String attributeName,
java.lang.String attributeValue,
java.lang.String xmlFile)
Return the old attribute value for properties that are not registered
to be removed.
|
void |
filterEndElement(NamedObj container,
java.lang.String elementName,
java.lang.StringBuffer currentCharData,
java.lang.String xmlFile)
Reset private variables.
|
java.lang.String |
toString()
Return a string that describes what the filter does.
|
filterAttributeValue, filterEndElement
public java.lang.String filterAttributeValue(NamedObj container, java.lang.String element, java.lang.String attributeName, java.lang.String attributeValue, java.lang.String xmlFile)
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.public void filterEndElement(NamedObj container, java.lang.String elementName, java.lang.StringBuffer currentCharData, java.lang.String xmlFile) throws java.lang.Exception
container
- The object created by this element.elementName
- The element name.currentCharData
- The character data, which appears
only in the doc and configure elementsxmlFile
- The file currently being parsed.java.lang.Exception
- if there is a problem substituting
in the new value.public java.lang.String toString()
toString
in interface MoMLFilter
toString
in class java.lang.Object