001/* An actor that writes input tokens as expressions to the specified file. 002 003 @Copyright (c) 2002-2014 The Regents of the University of California. 004 All rights reserved. 005 006 Permission is hereby granted, without written agreement and without 007 license or royalty fees, to use, copy, modify, and distribute this 008 software and its documentation for any purpose, provided that the 009 above copyright notice and the following two paragraphs appear in all 010 copies of this software. 011 012 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 013 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 014 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 015 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 016 SUCH DAMAGE. 017 018 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 019 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 020 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 021 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 022 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 023 ENHANCEMENTS, OR MODIFICATIONS. 024 025 PT_COPYRIGHT_VERSION 2 026 COPYRIGHTENDKEY 027 */ 028package ptolemy.actor.lib.io; 029 030import ptolemy.data.Token; 031import ptolemy.data.type.BaseType; 032import ptolemy.kernel.CompositeEntity; 033import ptolemy.kernel.util.IllegalActionException; 034import ptolemy.kernel.util.NameDuplicationException; 035 036/////////////////////////////////////////////////////////////////// 037//// ExpressionWriter 038 039/** 040 This actor reads input tokens and writes them, one line at a time, 041 to a specified file. The format it uses is that generated by the 042 toString() method of the token, which for most tokens is an expression 043 that can be read back in using ExpressionReader. String tokens, for 044 example, include the enclosing quotation marks in the output. 045 If you do not want the enclosing quotation marks, use LineWriter. 046 <p> 047 The file is specified by the <i>fileName</i> attribute 048 using any form acceptable to FileParameter. 049 <p> 050 If the <i>append</i> attribute has value <i>true</i>, 051 then the file will be appended to. If it has value <i>false</i>, 052 then if the file exists, the user will be queried for permission 053 to overwrite, and if granted, the file will be overwritten. 054 <p> 055 If the <i>confirmOverwrite</i> parameter has value <i>false</i>, 056 then this actor will overwrite the specified file if it exists 057 without asking. If <i>true</i> (the default), then if the file 058 exists, then this actor will ask for confirmation before overwriting. 059 060 @see ExpressionReader 061 @see ptolemy.data.expr.FileParameter 062 @see LineWriter 063 @deprecated Use TokenToExpression followed by LineWriter. 064 065 @author Edward A. Lee 066 @version $Id$ 067 @since Ptolemy II 2.2 068 @Pt.ProposedRating Green (eal) 069 @Pt.AcceptedRating Yellow (cxh) 070 */ 071@Deprecated 072public class ExpressionWriter extends LineWriter { 073 /** Construct an actor with the given container and name. 074 * @param container The container. 075 * @param name The name of this actor. 076 * @exception IllegalActionException If the actor cannot be contained 077 * by the proposed container. 078 * @exception NameDuplicationException If the container already has an 079 * actor with this name. 080 */ 081 public ExpressionWriter(CompositeEntity container, String name) 082 throws IllegalActionException, NameDuplicationException { 083 super(container, name); 084 input.setTypeEquals(BaseType.GENERAL); 085 } 086 087 /////////////////////////////////////////////////////////////////// 088 //// protected methods //// 089 090 /** Write the specified token to the current writer using the toString() 091 * method of the token, which usually results in an expression that 092 * can be read back in using the expression parser. 093 * @param token The token to write. 094 */ 095 @Override 096 protected void _writeToken(Token token) { 097 _writer.println(token.toString()); 098 } 099}