Class RemoveProperties

  • All Implemented Interfaces:
    MoMLFilter

    public class RemoveProperties
    extends MoMLFilterSimple
    When this class is registered with the MoMLParser.setMoMLFilter() method, it will cause MoMLParser to filter out the properties included in this classes.

    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.

    Since:
    Ptolemy II 4.1
    Version:
    $Id$
    Author:
    Haiyang Zheng
    Pt.AcceptedRating:
    Red (hyzheng)
    Pt.ProposedRating:
    Red (hyzheng)
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • RemoveProperties

        public RemoveProperties()
    • 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)
        Return the old attribute value for properties that are not registered to be removed. Otherwise, return null to remove the property.
        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
        Reset private variables.
        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.
      • 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.