/* Remove classes not compatible with Ptiny Copyright (c) 2009-2014 The Regents of the University of California. All rights reserved. Permission is hereby granted, without written agreement and without license or royalty fees, to use, copy, modify, and distribute this software and its documentation for any purpose, provided that the above copyright notice and the following two paragraphs appear in all copies of this software. IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. PT_COPYRIGHT_VERSION_2 COPYRIGHTENDKEY */ package ptolemy.moml.filter; import java.util.HashMap; import java.util.Iterator; import ptolemy.kernel.util.NamedObj; import ptolemy.moml.MoMLParser; import ptolemy.util.StringUtilities; /////////////////////////////////////////////////////////////////// //// RemoveNonPtinyClasses /** Remove classes such as code generators that are not present in Ptiny.
When this class is registered with the MoMLParser.setMoMLFilter() method, it will cause MoMLParser to filter out classes that are not present in the Ptiny configuration. @author Christopher Hylands @version $Id: RemoveNonPtinyClasses.java 70398 2014-10-22 23:44:32Z cxh $ @since Ptolemy II 8.0 @Pt.ProposedRating Red (cxh) @Pt.AcceptedRating Red (cxh) */ public class RemoveNonPtinyClasses extends MoMLFilterSimple { /** Clear the map of graphical classes to be removed. */ public static void clear() { _nonPtinyClasses = new HashMap(); } /** 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. * * @param container The container for this attribute, ignored * in this method. * @param element The XML element name. * @param attributeName The name of the attribute, ignored * in this method. * @param attributeValue The value of the attribute. * @param xmlFile The file currently being parsed. * @return the filtered attributeValue. */ @Override public String filterAttributeValue(NamedObj container, String element, String attributeName, String attributeValue, String xmlFile) { // If the nightly build is failing with messages like: // " X connection to foo:0 broken (explicit kill or server shutdown)." // Try uncommenting the next lines to see what is being // expanding before the error: //System.out.println("filterAttributeValue: " + container + "\t" // + attributeName + "\t" + attributeValue); if (attributeValue == null) { return null; } else if (_nonPtinyClasses.containsKey(attributeValue)) { return (String) _nonPtinyClasses.get(attributeValue); } return attributeValue; } /** In this class, do nothing. * @param container The object created by this element. * @param elementName The element name. * @param currentCharData The character data, which appears * only in the doc and configure elements * @param xmlFile The file currently being parsed. * @exception Exception Not thrown in this base class. */ @Override public void filterEndElement(NamedObj container, String elementName, StringBuffer currentCharData, String xmlFile) throws Exception { } /** Read in a MoML file, remove graphical classes and * write the results to standard out. *
For example, to remove the graphical classes from
* a file called RemoveGraphicalClasses.xml
*
* java -classpath "$PTII" ptolemy.moml.filter.RemoveGraphicalClasses test/RemoveGraphicalClasses.xml > output.xml ** @param args An array of one string *