001/* An identity actor for testing. 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 */ 027package ptolemy.actor.test; 028 029import ptolemy.actor.AtomicActor; 030import ptolemy.actor.CompositeActor; 031import ptolemy.actor.IOPort; 032import ptolemy.actor.NoTokenException; 033import ptolemy.data.Token; 034import ptolemy.kernel.util.IllegalActionException; 035import ptolemy.kernel.util.NameDuplicationException; 036 037/////////////////////////////////////////////////////////////////// 038//// IdentityActor 039 040/** 041 An IdentityActor is a simple atomic actor that transfers the input token 042 to the output. This actor is used in tests that needs to emulate the 043 fire method. This actor has a single input port and a single output port, 044 with the name "input" and "output" respectively. 045 046 @author Jie Liu 047 @version $Id$ 048 @since Ptolemy II 0.2 049 @Pt.ProposedRating Yellow (liuj) 050 @Pt.AcceptedRating Red (cxh) 051 */ 052public class IdentityActor extends AtomicActor { 053 /** Create a new actor in the specified container with the specified 054 * name. The name must be unique within the container or an exception 055 * is thrown. The container argument must not be null, or a 056 * NullPointerException will be thrown. 057 * 058 * @param container The container. 059 * @param name The name of this actor within the container. 060 * @exception IllegalActionException If the entity cannot be contained 061 * by the proposed container (see the setContainer() method). 062 * @exception NameDuplicationException If the name coincides with 063 * an entity already in the container. 064 */ 065 public IdentityActor(CompositeActor container, String name) 066 throws IllegalActionException, NameDuplicationException { 067 super(container, name); 068 input = new IOPort(this, "input"); 069 input.setInput(true); 070 input.setOutput(false); 071 input.setMultiport(false); 072 output = new IOPort(this, "output"); 073 output.setInput(false); 074 output.setOutput(true); 075 output.setMultiport(false); 076 } 077 078 /////////////////////////////////////////////////////////////////// 079 //// public methods //// 080 081 /** Fire the actor; transfer the input to the output. 082 * @exception IllegalActionException If there's no token 083 * in the input port. 084 */ 085 @Override 086 public void fire() throws IllegalActionException { 087 super.fire(); 088 try { 089 Token in = input.get(0); 090 output.broadcast(in); 091 } catch (NoTokenException e) { 092 throw new IllegalActionException(this, 093 " No token available when firing."); 094 } 095 } 096 097 /////////////////////////////////////////////////////////////////// 098 //// public variables //// 099 public IOPort input; 100 101 public IOPort output; 102}