ptolemy.moml.filter
Class RemoveGraphicalClasses

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

public class RemoveGraphicalClasses
extends java.lang.Object
implements MoMLFilter

When this class is registered with the MoMLParser.setMoMLFilter() method, it will cause MoMLParser to filter out graphical classes.

This is very useful for running applets with out requiring files like diva.jar to be downloaded. It is also used by the nightly build to run tests when there is no graphical display present.

Since:
Ptolemy II 2.0
Version:
$Id: RemoveGraphicalClasses.java 57857 2010-05-13 19:48:57Z cxh $
Author:
Edward A. Lee, Christopher Hylands
Accepted Rating:
Red (cxh)
Proposed Rating:
Red (cxh)

Field Summary
private static java.util.HashMap _graphicalClasses
          Map of actor names a HashMap of graphical classes to their non-graphical counterparts, usually either ptolemy.kernel.util.Attribute or null.
private  boolean _removeGR
          True if we should remove the GR domain.
 
Constructor Summary
RemoveGraphicalClasses()
           
 
Method Summary
static void clear()
          Clear the map of graphical classes to be removed.
 java.lang.String filterAttributeValue(NamedObj container, java.lang.String element, java.lang.String attributeName, java.lang.String attributeValue, java.lang.String xmlFile)
          Filter for graphical classes and return new values if a graphical class is found.
 void filterEndElement(NamedObj container, java.lang.String elementName, java.lang.StringBuffer currentCharData, java.lang.String xmlFile)
          In this class, do nothing.
static void main(java.lang.String[] args)
          Read in a MoML file, remove graphical classes and write the results to standard out.
 void put(java.lang.String className, java.lang.String replacement)
          Add a class to be filtered for and its replacement if the class is found.
 void remove(java.lang.String className)
          Remove a class to be filtered.
 void setRemoveGR(boolean removeGR)
          Set to true if we should removed classes that start with ptolemy.domains.gr.
 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

_graphicalClasses

private static java.util.HashMap _graphicalClasses
Map of actor names a HashMap of graphical classes to their non-graphical counterparts, usually either ptolemy.kernel.util.Attribute or null.


_removeGR

private boolean _removeGR
True if we should remove the GR domain.

Constructor Detail

RemoveGraphicalClasses

public RemoveGraphicalClasses()
Method Detail

clear

public static void clear()
Clear the map of graphical classes to be removed.


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 for graphical classes and return new values if a graphical class is found. An internal HashMap maps names of graphical entities to new names. The HashMap can also map a graphical entity to null, which means the entity is removed from the model. All class attributeValues that start with "ptolemy.domains.gr" are deemed to be graphical elements and null is always returned. For example, if the attributeValue is "ptolemy.vergil.icon.ValueIcon", or "ptolemy.vergil.basic.NodeControllerFactory" then return "ptolemy.kernel.util.Attribute"; if the attributeValue is "ptolemy.vergil.icon.AttributeValueIcon" or "ptolemy.vergil.icon.BoxedValueIcon" then return null, which will cause the MoMLParser to skip the rest of the element; otherwise return the original value of the attributeValue.

Specified by:
filterAttributeValue in interface MoMLFilter
Parameters:
container - The container for this attribute, ignored in this method.
element - The XML element name.
attributeName - The name of the attribute, ignored in this method.
attributeValue - The value of the attribute.
xmlFile - The file currently being parsed.
Returns:
the filtered attributeValue.

filterEndElement

public void filterEndElement(NamedObj container,
                             java.lang.String elementName,
                             java.lang.StringBuffer currentCharData,
                             java.lang.String xmlFile)
                      throws java.lang.Exception
In this class, do nothing.

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 - Not thrown in this base class.

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Read in a MoML file, remove graphical classes and write the results to standard out.

For example, to remove the graphica classes from a file called RemoveGraphicalClasses.xml

  java -classpath "$PTII" ptolemy.moml.filter.RemoveGraphicalClasses test/RemoveGraphicalClasses.xml > output.xml
  

Parameters:
args - An array of one string
The name of the MoML file to be cleaned.
Throws:
java.lang.Exception - If there is a problem reading or writing a file.

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, String)

put

public void put(java.lang.String className,
                java.lang.String replacement)
Add a class to be filtered for and its replacement if the class is found. If the replacement is null, then the rest of the attribute is skipped. Note that if you add a class with this method, then you must remove it with remove(String), calling 'new RemoveGraphicalClasses' 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".
replacement - The name of the class to be used if className is found. If this argument is null then the rest of the attribute is skipped.
See Also:
remove(String)

setRemoveGR

public void setRemoveGR(boolean removeGR)
Set to true if we should removed classes that start with ptolemy.domains.gr.

Parameters:
removeGR - True if we should remove classes that start with ptolemy.domains.gr.

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.