001/* Compute the composition of interface automata. 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 Compute the composition of interface automata. 040 This class reads the MoML description of a number of interface automata, 041 computes their composition, then writes the MoML description of the 042 composition to stdout. The usage is: 043 <pre> 044 java ptolemy.domains.modal.kernel.test.Compose <i>automaton1.xml</i> <i>automaton2.xml</i> ... 045 </pre> 046 047 @author Yuhong Xiong 048 @version $Id$ 049 @since Ptolemy II 8.0 050 @Pt.ProposedRating Red (yuhong) 051 @Pt.AcceptedRating Red (reviewmoderator) 052 */ 053public class Compose { 054 /** Compose the interface automata in the argument array and write 055 * the MoML description for the composition to stdout. 056 * @param momls An array of MoML file names for InterfaceAutomaton. 057 * @param considerTransient True to indicate to treat transient state 058 * differently. 059 * @exception Exception If the automata cannot be composed. 060 */ 061 public Compose(String[] momls, boolean considerTransient) throws Exception { 062 InterfaceAutomaton[] automata = new InterfaceAutomaton[momls.length]; 063 064 for (int i = 0; i < momls.length; i++) { 065 URL url = ConfigurationApplication.specToURL(momls[i]); 066 067 // following the comments in MoMLApplication, use the same URL for 068 // the two arguments (base and URL) to parse(). Also, a instance 069 // of MoMLParser must be used to parse each file, otherwise 070 // the same automaton will be returned the second time parse() is 071 // called. 072 MoMLParser parser = new MoMLParser(); 073 automata[i] = (InterfaceAutomaton) parser.parse(url, url); 074 automata[i].addPorts(); 075 } 076 077 InterfaceAutomaton composition = automata[0]; 078 079 for (int i = 1; i < momls.length; i++) { 080 composition = composition.compose(automata[i], considerTransient); 081 } 082 083 System.out.println(composition.exportMoML()); 084 } 085 086 /** Pass the command line arguments to the constructor. The command line 087 * argument is a list of MoML files for InterfaceAutomaton. 088 * @param args The command line arguments. 089 */ 090 public static void main(String[] args) { 091 try { 092 boolean considerTransient = false; 093 String[] momls = args; 094 095 if (args[0].equals("-transient")) { 096 considerTransient = true; 097 momls = new String[args.length - 1]; 098 099 for (int i = 1; i < args.length; i++) { 100 momls[i - 1] = args[i]; 101 } 102 } 103 104 new Compose(momls, considerTransient); 105 } catch (Exception exception) { 106 System.out.println(exception.getMessage()); 107 } 108 } 109 110 /////////////////////////////////////////////////////////////////// 111 //// public variables //// 112 /////////////////////////////////////////////////////////////////// 113 //// public methods //// 114 /////////////////////////////////////////////////////////////////// 115 //// protected variables //// 116 /////////////////////////////////////////////////////////////////// 117 //// protected methods //// 118 /////////////////////////////////////////////////////////////////// 119 //// private methods //// 120 /////////////////////////////////////////////////////////////////// 121 //// private variables //// 122}