001/* Combine internal transitions.
002
003 Copyright (c) 1999-2016 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 */
027package ptolemy.domains.modal.kernel.test;
028
029import java.net.URL;
030
031import ptolemy.actor.gui.ConfigurationApplication;
032import ptolemy.domains.modal.kernel.ia.InterfaceAutomaton;
033import ptolemy.moml.MoMLParser;
034
035///////////////////////////////////////////////////////////////////
036//// Compose
037
038/**
039 Combine the internal transitions using the combineInternalTransitions()
040 method.
041 This class reads the MoML description of an interface automata,
042 combine internal transitions, then writes the MoML description of the
043 new automata to stdout. The usage is:
044 <pre>
045 java ptolemy.domains.modal.kernel.test.CombineInternalTransitions <i>automaton1.xml</i>
046 </pre>
047
048 @author Yuhong Xiong
049 @version $Id$
050 @since Ptolemy II 8.0
051 @Pt.ProposedRating Red (yuhong)
052 @Pt.AcceptedRating Red (reviewmoderator)
053 */
054public class CombineInternalTransitions {
055    /** Combine the internal transitions for the argument automaton and write
056     *  the MoML description for the result to stdout.
057     *  @param moml The MoML file name for the InterfaceAutomaton.
058     *  @exception Exception If the operation failed.
059     */
060    public CombineInternalTransitions(String moml) throws Exception {
061        URL url = ConfigurationApplication.specToURL(moml);
062
063        // following the comments in MoMLApplication, use the same URL for
064        // the two arguments (base and URL) to parse(). Also, a instance
065        // of MoMLParser must be used to parse each file, otherwise
066        // the same automaton will be returned the second time parse() is
067        // called.
068        MoMLParser parser = new MoMLParser();
069        InterfaceAutomaton automaton = (InterfaceAutomaton) parser.parse(url,
070                url);
071        automaton.addPorts();
072
073        automaton.combineInternalTransitions();
074
075        System.out.println(automaton.exportMoML());
076    }
077
078    /** Pass the first command line argument to the constructor.
079     *  The command line argument is the name of a MoML file for
080     *  InterfaceAutomaton.
081     *  @param args The command line arguments.
082     */
083    public static void main(String[] args) {
084        try {
085            new CombineInternalTransitions(args[0]);
086        } catch (Exception exception) {
087            System.out.println(exception.getMessage());
088        }
089    }
090
091    ///////////////////////////////////////////////////////////////////
092    ////                         public variables                  ////
093    ///////////////////////////////////////////////////////////////////
094    ////                         public methods                    ////
095    ///////////////////////////////////////////////////////////////////
096    ////                         protected variables               ////
097    ///////////////////////////////////////////////////////////////////
098    ////                         protected methods                 ////
099    ///////////////////////////////////////////////////////////////////
100    ////                         private methods                   ////
101    ///////////////////////////////////////////////////////////////////
102    ////                         private variables                 ////
103}