001/* An application for testing the component domain. 002 Copyright (c) 1998-2014 The Regents of the University of California. 003 All rights reserved. 004 Permission is hereby granted, without written agreement and without 005 license or royalty fees, to use, copy, modify, and distribute this 006 software and its documentation for any purpose, provided that the above 007 copyright notice and the following two paragraphs appear in all copies 008 of this software. 009 010 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 011 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 012 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 013 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 014 SUCH DAMAGE. 015 016 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 017 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 018 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 019 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 020 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 021 ENHANCEMENTS, OR MODIFICATIONS. 022 023 PT_COPYRIGHT_VERSION_2 024 COPYRIGHTENDKEY 025 026 @ProposedRating Red 027 @AcceptedRating Red (cxh) 028 */ 029package ptolemy.component.test; 030 031import java.io.FileOutputStream; 032import java.io.PrintStream; 033import java.io.StringWriter; 034 035import ptolemy.data.IntToken; 036import ptolemy.data.TupleToken; 037import ptolemy.kernel.CompositeEntity; 038import ptolemy.kernel.util.Workspace; 039 040/////////////////////////////////////////////////////////////////// 041//// MCApplication 042 043/** 044 * An application for testing the component domain. 045 * <p>To run this, do 046 * cd $PTII/ptolemy/component/test 047 * java -classpath $PTII ptolemy.component.test.MCApplication 048 * 049 * @author Yang Zhao 050 * @version $Id$ 051 * @since Ptolemy II 11.0 052 * @version $Id$ 053 */ 054public class MCApplication { 055 /////////////////////////////////////////////////////////////////// 056 //// public methods //// 057 058 /** Build the model. 059 * <p>Read the model "NCApplication.xml" from the current directory. 060 * @param args Ignored 061 * @exception Exception If there is a problem reading the model. 062 */ 063 public static void main(String[] args) throws Exception { 064 CompositeEntity _toplevel; 065 066 try { 067 Workspace workspace = new Workspace("NC"); 068 _toplevel = new CompositeEntity(workspace); 069 _toplevel.setName("NCTest"); 070 071 Counter counter = new Counter(_toplevel, "Couter"); 072 Leds leds = new Leds(_toplevel, "Leds"); 073 _toplevel.connect(counter.output, leds.display, "R1"); 074 075 // Generate moml file to be tested in vergil. 076 StringWriter buffer = new StringWriter(); 077 _toplevel.exportMoML(buffer); 078 079 String fileName = "NCApplication.xml"; 080 FileOutputStream file = null; 081 PrintStream out = null; 082 try { 083 file = new FileOutputStream(fileName); 084 085 out = new PrintStream(file); 086 out.println(buffer); 087 out.flush(); 088 } finally { 089 if (out != null) { 090 try { 091 out.close(); 092 } catch (Throwable throwable) { 093 System.out.println("Ignoring failure to close stream " 094 + "on " + fileName); 095 throwable.printStackTrace(); 096 } 097 } 098 } 099 100 // Execute the model. 101 counter.initialize(); 102 103 IntToken[] t = new IntToken[1]; 104 t[0] = new IntToken(2); 105 106 TupleToken arg = new TupleToken(t); 107 108 for (int i = 0; i < 10; i++) { 109 counter.increment.call(arg); 110 } 111 } catch (Exception ex) { 112 ex.printStackTrace(); 113 throw ex; 114 } 115 } 116}