001/* Remove Graphical Classes Application. 002 003 Copyright (c) 1998-2018 The Regents of the University of California. 004 All rights reserved. 005 Permission is hereby granted, without written agreement and without 006 license or royalty fees, to use, copy, modify, and distribute this 007 software and its documentation for any purpose, provided that the above 008 copyright notice and the following two paragraphs appear in all copies 009 of this software. 010 011 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 012 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 013 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 014 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 015 SUCH DAMAGE. 016 017 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 018 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 019 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 020 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 021 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 022 ENHANCEMENTS, OR MODIFICATIONS. 023 024 PT_COPYRIGHT_VERSION_2 025 COPYRIGHTENDKEY 026 027 */ 028package ptolemy.moml.filter; 029 030import ptolemy.actor.injection.ActorModuleInitializer; 031import ptolemy.kernel.util.NamedObj; 032import ptolemy.moml.MoMLParser; 033import ptolemy.util.StringUtilities; 034 035/////////////////////////////////////////////////////////////////// 036//// RemoveGraphicalClasses Application 037 038/** An application that removes graphical classes. 039 040 @author Edward A. Lee, Christopher Hylands 041 @version $Id$ 042 @since Ptolemy II 11.0 043 @Pt.ProposedRating Red (cxh) 044 @Pt.AcceptedRating Red (cxh) 045 */ 046public class RemoveGraphicalClassesApplication { 047 048 // The main() method was moved from RemoveGraphicaClasses so 049 // that we could avoid a dependency on ActorModuleInitializer in 050 // Triquetrum. 051 052 /** Read in a MoML file, remove graphical classes and 053 * write the results to standard out. 054 * <p> For example, to remove the graphical classes from 055 * a file called <code>RemoveGraphicalClasses.xml</code> 056 * <pre> 057 * java -classpath "$PTII" ptolemy.moml.filter.RemoveGraphicalClassesApplication test/RemoveGraphicalClasses.xml > output.xml 058 * </pre> 059 * @param args An array of one string 060 * <br> The name of the MoML file to be cleaned. 061 * @exception Exception If there is a problem reading or writing 062 * a file. 063 */ 064 public static void main(String[] args) throws Exception { 065 try { 066 // The HandSimDroid work in $PTII/ptserver uses dependency 067 // injection to determine which implementation actors such as 068 // Const and Display to use. This method reads the 069 // ptolemy/actor/ActorModule.properties file.</p> 070 ActorModuleInitializer.initializeInjector(); 071 072 MoMLParser parser = new MoMLParser(); 073 074 // The list of filters is static, so we reset it in case there 075 // filters were already added. 076 MoMLParser.setMoMLFilters(null); 077 078 // Add the backward compatibility filters. 079 MoMLParser.setMoMLFilters(BackwardCompatibility.allFilters()); 080 081 MoMLParser.addMoMLFilter(new RemoveGraphicalClasses()); 082 MoMLParser.addMoMLFilter(new HideAnnotationNames()); 083 NamedObj topLevel = parser.parseFile(args[0]); 084 System.out.println(topLevel.exportMoML()); 085 } catch (Throwable throwable) { 086 System.err.println("Failed to filter \"" + args[0] + "\""); 087 throwable.printStackTrace(); 088 StringUtilities.exit(1); 089 } 090 } 091}