001/*
002Below is the copyright agreement for the Ptolemy II system.
003
004Copyright (c) 2009-2014 The Regents of the University of California.
005All rights reserved.
006
007Permission is hereby granted, without written agreement and without
008license or royalty fees, to use, copy, modify, and distribute this
009software and its documentation for any purpose, provided that the above
010copyright notice and the following two paragraphs appear in all copies
011of this software.
012
013IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
014FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
015ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
016THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
017SUCH DAMAGE.
018
019THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
020INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
021MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
022PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
023CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
024ENHANCEMENTS, OR MODIFICATIONS.
025 */
026//package gov.nasa.gsfc.giovanni;
027package ptolemy.actor.lib.test;
028
029import ptolemy.actor.TypedAtomicActor;
030import ptolemy.actor.TypedIOPort;
031import ptolemy.data.StringToken;
032import ptolemy.data.type.BaseType;
033import ptolemy.kernel.CompositeEntity;
034import ptolemy.kernel.util.IllegalActionException;
035import ptolemy.kernel.util.NameDuplicationException;
036
037/**
038 * Name: SearchTest.java Purpose: The purpose of this actor is
039 * to prove that we can use it's output as input for the Loop Actor
040 *
041 * input :  String "Search #Loop Number"
042 * output : "No Data" or "Results Found"
043 *
044 * @author Jim Amrhein/Mark Ruebens Giovannii/GSFC Greenbelt
045 * @version $Id$
046 * @since Ptolemy II 8.0
047 * @Pt.ProposedRating Red (cxh)
048 * @Pt.AcceptedRating Red (cxh)
049 */
050public class SearchTest extends TypedAtomicActor {
051
052    /**
053     * The Point (Lat,Long) the user selected from the map
054     */
055    public TypedIOPort search = new TypedIOPort(this, "search", true, false);
056
057    /* // Once we get this working, allow the user to change the
058    // match value.
059    public TypedIOPort searchMatch = new TypedIOPort(this,
060    "search Match", true, false);
061     */
062
063    /**
064     *  Output whether the download failed or passed.
065     * ; acts as an output trigger
066     */
067
068    public TypedIOPort resultsOutput = new TypedIOPort(this, "results Output",
069            false, true);
070
071    public SearchTest(CompositeEntity container, String name)
072            throws NameDuplicationException, IllegalActionException {
073        super(container, name);
074
075        search.setTypeEquals(BaseType.STRING);
076        // searchMatch.setTypeEquals(BaseType.STRING);
077        resultsOutput.setTypeEquals(BaseType.STRING);
078    }
079
080    /**
081     *
082     */
083    @Override
084    public boolean prefire() throws IllegalActionException {
085        return super.prefire();
086
087    }
088
089    /**
090     * Read the search parameter, if it matches "Search 50" then
091     * we've "got" data. Let the Loop Actor know it can stop searching
092     */
093    @Override
094    public void fire() throws IllegalActionException {
095        super.fire();
096
097        if (search.getWidth() > 0 && search.hasToken(0)) {
098            String searchStr = ((StringToken) search.get(0)).stringValue();
099            if (searchStr.equals("Search 50")) {
100                System.out.println("Found DATA!");
101                resultsOutput.broadcast(new StringToken("Results Found"));
102
103            } else {
104                System.out.println("Didn't Match! " + searchStr);
105                resultsOutput.broadcast(new StringToken("No Data"));
106            }
107        }
108    }
109
110    /**
111     * Post fire the actor. Return false to indicate that the process has
112     * finished. If it returns true, the process will continue indefinitely.
113     *
114     *@return The value returned by the parent method.
115     */
116    @Override
117    public boolean postfire() throws IllegalActionException {
118        return super.postfire();
119    }
120
121}