001/* Display the deadlock states. 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; 030import java.util.Iterator; 031 032import ptolemy.actor.gui.ConfigurationApplication; 033import ptolemy.domains.modal.kernel.State; 034import ptolemy.domains.modal.kernel.ia.InterfaceAutomaton; 035import ptolemy.moml.MoMLParser; 036 037/////////////////////////////////////////////////////////////////// 038//// DeadlockStates 039 040/** 041 Display the deadlock states. 042 This class reads the MoML description of an interface automata, 043 and writes the names of the deadlock states to stdout. 044 The usage is: 045 <pre> 046 java ptolemy.domains.modal.kernel.test.DeadlockStates <i>automaton.xml</i> 047 </pre> 048 049 @author Yuhong Xiong 050 @version $Id$ 051 @since Ptolemy II 8.0 052 @Pt.ProposedRating Red (yuhong) 053 @Pt.AcceptedRating Red (reviewmoderator) 054 */ 055public class DeadlockStates { 056 /** Write the names of the deadlock states of the specified interface 057 * automaton to stdout. 058 * @param moml The MoML file name for an InterfaceAutomaton. 059 * @exception Exception If the MoML file is not valid or deadlock cannot 060 * be checked. 061 */ 062 public DeadlockStates(String moml) throws Exception { 063 URL url = ConfigurationApplication.specToURL(moml); 064 065 // following the comments in MoMLApplication, use the same URL for 066 // the two arguments (base and URL) to parse(). Also, a instance 067 // of MoMLParser must be used to parse each file, otherwise 068 // the same automaton will be returned the second time parse() is 069 // called. 070 MoMLParser parser = new MoMLParser(); 071 InterfaceAutomaton automaton = (InterfaceAutomaton) parser.parse(url, 072 url); 073 automaton.addPorts(); 074 075 System.out.println("Deadlock states:"); 076 077 Iterator deadlockStates = automaton.deadlockStates().iterator(); 078 079 while (deadlockStates.hasNext()) { 080 State state = (State) deadlockStates.next(); 081 System.out.println(" " + state.getFullName()); 082 } 083 } 084 085 /** Pass the command line argument to the constructor. The command line 086 * argument the name of a MoML file for an InterfaceAutomaton. 087 * @param args The command line arguments. 088 */ 089 public static void main(String[] args) { 090 try { 091 new DeadlockStates(args[0]); 092 } catch (Exception exception) { 093 System.out.println(exception.getMessage()); 094 } 095 } 096 097 /////////////////////////////////////////////////////////////////// 098 //// public variables //// 099 /////////////////////////////////////////////////////////////////// 100 //// public methods //// 101 /////////////////////////////////////////////////////////////////// 102 //// protected variables //// 103 /////////////////////////////////////////////////////////////////// 104 //// protected methods //// 105 /////////////////////////////////////////////////////////////////// 106 //// private methods //// 107 /////////////////////////////////////////////////////////////////// 108 //// private variables //// 109}