001/* A change listener that describes changes on the standard output. 002 003 Copyright (c) 1998-2014 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.kernel.util; 029 030import java.io.OutputStream; 031import java.io.PrintStream; 032 033/////////////////////////////////////////////////////////////////// 034//// StreamChangeListener 035 036/** 037 A change listener that describes the changes on the standard output. 038 It simply prints the description of the change once it executes (or 039 throws an exception). 040 041 @author Edward A. Lee 042 @version $Id$ 043 @since Ptolemy II 1.0 044 @Pt.ProposedRating Green (eal) 045 @Pt.AcceptedRating Green (neuendor) 046 */ 047public class StreamChangeListener implements ChangeListener { 048 /** Create a change listener that sends messages to the standard output. 049 */ 050 public StreamChangeListener() { 051 _output = System.out; 052 } 053 054 /** Create a change listener that sends messages to the specified stream. 055 * @param out The stream to send messages to. 056 */ 057 public StreamChangeListener(OutputStream out) { 058 _output = new PrintStream(out); 059 } 060 061 /////////////////////////////////////////////////////////////////// 062 //// public methods //// 063 064 /** Print the description of the change to the stream output. 065 * @param change The change that has been executed. 066 */ 067 @Override 068 public void changeExecuted(ChangeRequest change) { 069 String description = ""; 070 071 if (change != null) { 072 description = change.getDescription(); 073 } 074 075 _output.println("StreamChangeRequest.changeExecuted(): " + description 076 + " succeeded"); 077 } 078 079 /** Print the description of the failure to the stream output. 080 * @param change The change that has been executed. 081 * @param exception The exception that occurred. 082 */ 083 @Override 084 public void changeFailed(ChangeRequest change, Exception exception) { 085 String description = ""; 086 087 if (change != null) { 088 description = change.getDescription(); 089 } 090 091 _output.println("StreamChangeRequest.changeFailed(): " + description 092 + " failed: " + exception.toString()); 093 } 094 095 /////////////////////////////////////////////////////////////////// 096 //// protected variables //// 097 098 /** The PrintStream that we direct the output to. */ 099 protected PrintStream _output; 100}