001/* A parameter that is in string mode by default.
002
003 Copyright (c) 2003-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
028 */
029package ptolemy.data.expr;
030
031import ptolemy.data.StringToken;
032import ptolemy.kernel.util.IllegalActionException;
033import ptolemy.kernel.util.NameDuplicationException;
034import ptolemy.kernel.util.NamedObj;
035
036///////////////////////////////////////////////////////////////////
037//// StringParameter
038
039/**
040 <p>This subclass of Parameter is almost identical to Parameter except that it
041 sets itself to string mode in the constructor.
042 In addition, there is a convenience method, stringValue(), that
043 is equivalent to the following expression:</p>
044 <pre>
045 ((StringToken)this.getToken()).stringValue()
046 </pre>
047 <p>
048 This subclass is provided mainly
049 so that string-mode parameters can be specified in MoML.  Consequently,
050 the only constructor provided is the one needed by MoML.</p>
051
052 @author Edward A. Lee
053 @version $Id$
054 @since Ptolemy II 4.0
055 @Pt.ProposedRating Yellow (eal)
056 @Pt.AcceptedRating Red (cxh)
057 */
058public class StringParameter extends Parameter {
059    /** Construct a parameter with the given name contained by the specified
060     *  entity. The container argument must not be null, or a
061     *  NullPointerException will be thrown.  This parameter will use the
062     *  workspace of the container for synchronization and version counts.
063     *  If the name argument is null, then the name is set to the empty string.
064     *  The object is not added to the list of objects in the workspace
065     *  unless the container is null.
066     *  Increment the version of the workspace.
067     *  @param container The container.
068     *  @param name The name of the parameter.
069     *  @exception IllegalActionException If the parameter is not of an
070     *   acceptable class for the container.
071     *  @exception NameDuplicationException If the name coincides with
072     *   a parameter already in the container.
073     */
074    public StringParameter(NamedObj container, String name)
075            throws IllegalActionException, NameDuplicationException {
076        super(container, name);
077        setStringMode(true);
078    }
079
080    ///////////////////////////////////////////////////////////////////
081    ////                         public methods                    ////
082
083    /** Return the string value of this parameter.  This is
084     *  equivalent to
085     *  <pre>
086     *     ((StringToken)this.getToken()).stringValue()
087     *  </pre>
088     *  @return The string value of this parameter.
089     *  @exception IllegalActionException If the expression cannot
090     *   be parsed or cannot be evaluated, or if the result of evaluation
091     *   violates type constraints, or if the result of evaluation is null
092     *   and there are variables that depend on this one.
093     */
094    public String stringValue() throws IllegalActionException {
095        return ((StringToken) getToken()).stringValue();
096    }
097}