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.expr.Parameter;
036import ptolemy.data.type.BaseType;
037import ptolemy.kernel.CompositeEntity;
038import ptolemy.kernel.util.IllegalActionException;
039import ptolemy.kernel.util.NameDuplicationException;
040
041//////////////////////////////////////////////////////////////////////////
042//// ConstOnce
043/**
044 * Produce a constant output once. The value of the output is that of the token
045 * contained by the <i>value</i> parameter, which by default is an IntToken with
046 * value 1. The type of the output is that of <i>value</i> parameter.
047 * 
048 * @author Efrat Jaeger
049 * @version $Id: TempActor.java 24234 2010-05-06 05:21:26Z welker $
050 * @since Ptolemy II 3.0.2
051 */
052
053public class TempActor extends TypedAtomicActor {
054
055        /**
056         * Construct an actor with the given container and name.
057         * 
058         * @param container
059         *            The container.
060         * @param name
061         *            The name of this actor.
062         * @exception IllegalActionException
063         *                If the actor cannot be contained by the proposed
064         *                container.
065         * @exception NameDuplicationException
066         *                If the container already has an actor with this name.
067         */
068        public TempActor(CompositeEntity container, String name)
069                        throws NameDuplicationException, IllegalActionException {
070                super(container, name);
071                input = new TypedIOPort(this, "input", true, false);
072                input.setTypeEquals(BaseType.STRING);
073                value = new Parameter(this, "value");
074                output = new TypedIOPort(this, "output", false, true);
075                output.setTypeEquals(BaseType.STRING);
076        }
077
078        Parameter value;
079        TypedIOPort input;
080        TypedIOPort output;
081
082        // /////////////////////////////////////////////////////////////////
083        // // public methods ////
084
085        /**
086         * Set postfire to false.
087         * 
088         * @exception IllegalActionException
089         *                If thrown by the super class.
090         */
091        public boolean postfire() throws IllegalActionException {
092
093                String xml = ((StringToken) input.get(0)).stringValue();
094                String modelURL = ((StringToken) value.getToken()).stringValue();
095                ModelService ms = new ModelService();
096                try {
097                        String res = ms.execute(modelURL, xml);
098                        output.broadcast(new StringToken(res));
099                } catch (Exception ex) {
100                        ex.printStackTrace();
101                }
102                /*
103                 * System.out.println(t.getType().toString());
104                 * System.out.println("========="); String[] labels = {"x","y","z"};
105                 * Token[] tArr = {new DoubleToken(2.3), new DoubleToken(4.6)}; Token[]
106                 * vals = {new StringToken("dfd"), new IntToken(12), new
107                 * ArrayToken(tArr)}; Token rt = new RecordToken(labels,vals);
108                 * System.out.println(rt.getType().toString());
109                 */
110                return false;
111        }
112}