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.sdm.spa;
031
032import ptolemy.actor.TypedAtomicActor;
033import ptolemy.actor.TypedIOPort;
034import ptolemy.data.ObjectToken;
035import ptolemy.data.expr.StringParameter;
036import ptolemy.data.type.BaseType;
037import ptolemy.gui.GraphicalMessageHandler;
038import ptolemy.kernel.CompositeEntity;
039import ptolemy.kernel.util.IllegalActionException;
040import ptolemy.kernel.util.NameDuplicationException;
041
042///////////////////////////////////////////////////////////////
043////SoaplabAnalysis
044/**
045 * The following actor is for exectuing the standard soaplab operations after
046 * creating soaplab clients and setting input operations in the former stages of
047 * the workflow.
048 * 
049 * @author Nandita Mangal
050 * @version $Id: SoaplabAnalysis.java, v 1.0 2005/19/07
051 * @category.name web
052 * @category.name external execution
053 */
054
055public class SoaplabAnalysis extends TypedAtomicActor {
056
057        /**
058         * Construct a SoaplabAnalysis actor with given container and name.
059         * 
060         * @param container
061         *            The container.
062         * @param name
063         *            The name of this actor.
064         * @exception NameDuplicationException
065         *                If the container already has an actor with this name
066         */
067
068        public SoaplabAnalysis(CompositeEntity container, String name)
069                        throws NameDuplicationException, IllegalActionException {
070
071                super(container, name);
072
073                soaplabMethod = new StringParameter(this, "soaplabMethodName");
074                _addMethodChoices(); // add the standard method choices for soaplab
075                                                                // services
076                soaplabEditMethod = new StringParameter(this,
077                                "OR Enter another Soaplab Method");
078
079                // NOTE inputClient = outputClient , can use multiport if director is
080                // not SDF
081                inputClient = new TypedIOPort(this, "clientInput", true, false);
082                inputClient.setTypeEquals(BaseType.OBJECT);
083
084                outputClient = new TypedIOPort(this, "clientOutput", false, true);
085                outputClient.setTypeEquals(BaseType.OBJECT);
086
087                _attachText("_iconDescription", "<svg>\n" + "<rect x=\"0\" y=\"0\" "
088                                + "width=\"60\" height=\"30\" " + "style=\"fill:white\"/>\n"
089                                + "</svg>\n");
090        }
091
092        // //////////////////////////////////////////////////////////////////////////
093        // // Ports and Parameters ////
094
095        /**
096         * The standard method choices for SoaplabServices
097         */
098        public StringParameter soaplabMethod = null;
099
100        /**
101         * Enter your own Soaplab Method.
102         */
103        public StringParameter soaplabEditMethod = null;
104
105        /**
106         * SoaplabServiceClient input from pervious soaplab actor
107         * operation.ServiceClient created in SoaplabService Starter Actor.
108         */
109        public TypedIOPort inputClient;
110
111        /**
112         * Modified SoaplabServiceClient after performing a Call with the client's
113         * jobID.
114         */
115        public TypedIOPort outputClient;
116
117        // //////////////////////////////////////////////////////////////////////////
118        // // public Methods ////
119
120        /**
121         * Gets the client as input and given the standard soaplab operation, calls
122         * that specific operation on the client.
123         * 
124         * @exception IllegalActionException
125         *                If there is no director.
126         */
127
128        public void fire() throws IllegalActionException {
129
130                super.fire();
131
132                String method = "";
133                if (soaplabEditMethod.getExpression().equals(""))
134                        method = soaplabMethod.getExpression();
135                else
136                        method = soaplabEditMethod.getExpression();
137
138                try {
139                        ObjectToken clientToken = (ObjectToken) (inputClient.get(0));
140                        SoaplabServiceClient client = (SoaplabServiceClient) (clientToken
141                                        .getValue());
142
143                        client.doCall(method, new Object[] { client.getJobId() });
144                        ObjectToken tokenClient = new ObjectToken(client);
145                        outputClient.broadcast(tokenClient);
146
147                } catch (Exception ex) {
148
149                        if (soaplabEditMethod.getExpression().equals("")
150                                        && soaplabMethod.getExpression().equals(""))
151                                GraphicalMessageHandler
152                                                .message("\nSoaplab Method not set in actor Soaplab Analysis!");
153
154                        _debug("<EXCEPTION> There was an error while executing the web service operation "
155                                        + ex + ". </EXCEPTION>");
156                        // GraphicalMessageHandler.message(
157                        _confErrorStr += "\n"
158                                        + ex.getMessage()
159                                        + "\nThere was an error while executing the web service operation in the actor: "
160                                        + this.getName();// );
161
162                }
163
164                if (!(_confErrorStr.equals(""))) {
165                        GraphicalMessageHandler.message(_confErrorStr);
166
167                }
168
169        }// end of fire
170
171        // //////////////////////////////////////////////////////////////////////////
172        // // private Methods ////
173
174        /**
175         * Simply add the known standard soaplab operations to the parameter
176         * soaplabMethod
177         */
178
179        private void _addMethodChoices() {
180
181                soaplabMethod.addChoice("run");
182                soaplabMethod.addChoice("destory");
183                soaplabMethod.addChoice("describe");
184                soaplabMethod.addChoice("getStatus");
185                soaplabMethod.addChoice("getInputSpec");
186                soaplabMethod.addChoice("getResultSpec");
187                soaplabMethod.addChoice("getAnalysisType");
188                soaplabMethod.addChoice("waitFor");
189                soaplabMethod.addChoice("runAndWaitFor");
190                soaplabMethod.addChoice("getResults");
191                soaplabMethod.addChoice("terminate");
192                soaplabMethod.addChoice("getLastEvent");
193                soaplabMethod.addChoice("getNotificationDescriptor");
194                soaplabMethod.addChoice("getCreted");
195                soaplabMethod.addChoice("getStarted");
196                soaplabMethod.addChoice("getEnded");
197                soaplabMethod.addChoice("getCharacteristics");
198                soaplabMethod.addChoice("getElapsed");
199                soaplabMethod.addChoice("getSomeResults");
200
201        }// end of __addMethodChoices
202
203        protected String _confErrorStr = "";
204}