ptolemy.moml
Interface MoMLFilter

All Known Implementing Classes:
AddEditorFactory, AddIcon, BacktrackTransformer.RenameClassMoMLFilter, ChangeFixedWidth1ToAuto, ClassChanges, DesignPatternImporter.MoMLContentFilter, GRColorChanges, HideAnnotationNames, LazyTypedCompositeActorChanges, MultiportToSinglePort, NamedObjClassesSeen, ParameterNameChanges, PortClassChanges, PortNameChanges, PropertyClassChanges, RelationWidthChanges, RemoveClasses, RemoveGraphicalClasses, RemoveNonPtinyClasses, RemoveProperties, UpdateAnnotations

public interface MoMLFilter

This class filters MoML (modeling markup language) identifiers. It can be used to

  • Remove graphical classes for use in a non-graphical environment
  • Change the names of actors and ports for backward compatibility.
  • Since:
    Ptolemy II 2.0
    Version:
    $Id: MoMLFilter.java 53042 2009-04-10 20:31:21Z cxh $
    Author:
    Christopher Hylands, Edward A. Lee
    Accepted Rating:
    Red (cxh)
    Proposed Rating:
    Red (cxh)

    Method Summary
     java.lang.String filterAttributeValue(NamedObj container, java.lang.String element, java.lang.String attributeName, java.lang.String attributeValue, java.lang.String xmlFile)
              Given a container, attribute name and attribute value, return a new attribute value.
     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.
     

    Method Detail

    filterAttributeValue

    java.lang.String filterAttributeValue(NamedObj container,
                                          java.lang.String element,
                                          java.lang.String attributeName,
                                          java.lang.String attributeValue,
                                          java.lang.String xmlFile)
    Given a container, attribute name and attribute value, return a new attribute value. Note that "attribute" means XML attribute, not Ptolemy II attribute. Also, the container is the context of the current of XML element. So, for example, if you have:
        <entity name="foo" class="...">
           <property name="x" value="10"/>
        </entity>
      
    then this method will be called twice with the container being the instance "foo". On the first call, the attributeName will be "name" and the attributeValue will be "x". On the second call, attributeName will be "value" and the attributeValue will be "10". To make no change to the attribute value, an implementer should simply return the same attributeValue. To cause the MoMLParser to ignore the current element altogether, an implementer should return null. For example, to skip a graphical class, create a filter that looks for attributeName equal to "class" and attributeValue equal to the class name to skip. Note that if the attributeValue argument is null, then returning null is interpreted as no change, rather than as an indication to skip the element. To change the value of the attribute, simply return a a new value for the attribute.

    If modifies the attribute value, then it should call the static method MoMLParser.setModified(true), which indicates that the model was modified so that the user can optionally save the modified model.

    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

    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.

    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

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

    Overrides:
    toString in class java.lang.Object
    Returns:
    A description of the filter (ending with a newline).