001/*
002 * Copyright (c) 1998-2010 The Regents of the University of California.
003 * All rights reserved.
004 *
005 * '$Author: welker $'
006 * '$Date: 2010-05-06 05:21:26 +0000 (Thu, 06 May 2010) $' 
007 * '$Revision: 24234 $'
008 * 
009 * Permission is hereby granted, without written agreement and without
010 * license or royalty fees, to use, copy, modify, and distribute this
011 * software and its documentation for any purpose, provided that the above
012 * copyright notice and the following two paragraphs appear in all copies
013 * of this software.
014 *
015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
019 * SUCH DAMAGE.
020 *
021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
026 * ENHANCEMENTS, OR MODIFICATIONS.
027 *
028 */
029
030package org.geon;
031
032import ptolemy.actor.TypedAtomicActor;
033import ptolemy.actor.TypedIOPort;
034import ptolemy.data.StringToken;
035import ptolemy.data.Token;
036import ptolemy.data.expr.Parameter;
037import ptolemy.data.type.BaseType;
038import ptolemy.kernel.CompositeEntity;
039import ptolemy.kernel.util.IllegalActionException;
040import ptolemy.kernel.util.NameDuplicationException;
041
042//////////////////////////////////////////////////////////////////////////
043////TokenToString
044/**
045 * Return the string representation of the input token.
046 * 
047 * @author Efrat Jaeger
048 * @version $Id: TokenToString.java 24234 2010-05-06 05:21:26Z welker $
049 * @since Ptolemy II 3.0.2
050 */
051
052public class TokenToString extends TypedAtomicActor {
053
054        /**
055         * Construct an actor with the given container and name.
056         * 
057         * @param container
058         *            The container.
059         * @param name
060         *            The name of this actor.
061         * @exception IllegalActionException
062         *                If the actor cannot be contained by the proposed
063         *                container.
064         * @exception NameDuplicationException
065         *                If the container already has an actor with this name.
066         */
067        public TokenToString(CompositeEntity container, String name)
068                        throws NameDuplicationException, IllegalActionException {
069                super(container, name);
070                input = new TypedIOPort(this, "input", true, false);
071                input.setTypeEquals(BaseType.GENERAL);
072                value = new Parameter(this, "value");
073                output = new TypedIOPort(this, "output", false, true);
074                output.setTypeEquals(BaseType.STRING);
075        }
076
077        Parameter value;
078        TypedIOPort input;
079        TypedIOPort output;
080
081        // /////////////////////////////////////////////////////////////////
082        // // public methods ////
083
084        /**
085         * Set postfire to false.
086         * 
087         * @exception IllegalActionException
088         *                If thrown by the super class.
089         */
090        public void fire() throws IllegalActionException {
091
092                Token in = input.get(0);
093                output.broadcast(new StringToken(in.toString()));
094
095        }
096}