/* An actor that reads a string from a file or URL, parses it assuming it is defining a record, and outputs the record. Copyright (c) 2003-2014 The Regents of the University of California. All rights reserved. Permission is hereby granted, without written agreement and without license or royalty fees, to use, copy, modify, and distribute this software and its documentation for any purpose, provided that the above copyright notice and the following two paragraphs appear in all copies of this software. IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. PT_COPYRIGHT_VERSION_2 COPYRIGHTENDKEY */ package ptolemy.actor.lib.io; import java.util.Set; import ptolemy.data.Token; import ptolemy.data.expr.ASTPtRootNode; import ptolemy.data.expr.Parameter; import ptolemy.data.expr.ParseTreeEvaluator; import ptolemy.data.expr.PtParser; import ptolemy.data.expr.StringParameter; import ptolemy.data.type.BaseType; import ptolemy.graph.Inequality; import ptolemy.kernel.CompositeEntity; import ptolemy.kernel.util.IllegalActionException; import ptolemy.kernel.util.NameDuplicationException; /////////////////////////////////////////////////////////////////// //// TokenReader /** An actor that reads a string expression from a file or URL upon receiving a signal on its trigger input port, and outputs a token that is the result of evaluating the read string. The file or URL is specified by the FileOrURL parameter or set using the FileOrURL port. If the file or URL cannot be read, the expression cannot be parsed successfully, or the resulting token does not match the type constraint of the output port, the value of the errorHandlingStrategy parameter determines the behavior of this actor. TODO: describe automatic port constraint setting FIXME: More here. Particularly, document output type handling. @author Edward A. Lee, Marten Lohstroh @version $Id: TokenReader.java 70398 2014-10-22 23:44:32Z cxh $ @since Ptolemy II 10.0 @deprecated Use LineReader followed by ExpressionToToken. @Pt.ProposedRating Red (eal) @Pt.AcceptedRating Red (reviewmoderator) */ @Deprecated public class TokenReader extends FileReader { /** Construct an actor with a name and a container. * The container argument must not be null, or a NullPointerException * will be thrown. * @param container The container. * @param name The name of this actor. * @exception IllegalActionException If the container is incompatible * with this actor. * @exception NameDuplicationException If the name coincides with * an actor already in the container. */ public TokenReader(CompositeEntity container, String name) throws IllegalActionException, NameDuplicationException { super(container, name); outputType = new Parameter(this, "outputType"); // must reset the output type to unknown (base class sets it to string) output.setTypeEquals(BaseType.UNKNOWN); errorHandlingStrategy = new StringParameter(this, "errorHandlingStrategy"); errorHandlingStrategy.addChoice("Throw Exception"); errorHandlingStrategy.addChoice("Do Nothing"); // Show the firingCountLimit parameter last. firingCountLimit.moveToLast(); } /////////////////////////////////////////////////////////////////// //// public variables //// /** The error handled strategy. The strategy to use if: *