001/*
002 * Copyright (c) 2004-2010 The Regents of the University of California.
003 * All rights reserved.
004 *
005 * '$Author: crawl $'
006 * '$Date: 2012-09-18 18:40:51 +0000 (Tue, 18 Sep 2012) $' 
007 * '$Revision: 30702 $'
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 java.io.ByteArrayInputStream;
033import java.util.HashMap;
034import java.util.Iterator;
035import java.util.List;
036import java.util.Map;
037import java.util.Vector;
038
039import javax.wsdl.Binding;
040import javax.wsdl.Operation;
041import javax.wsdl.Port;
042import javax.wsdl.Service;
043import javax.wsdl.extensions.soap.SOAPAddress;
044import javax.xml.namespace.QName;
045import javax.xml.rpc.Call;
046import javax.xml.rpc.ServiceException;
047
048import org.apache.axis.Message;
049import org.apache.axis.constants.Style;
050import org.apache.axis.message.SOAPBodyElement;
051import org.apache.axis.utils.XMLUtils;
052import org.apache.axis.wsdl.gen.Parser;
053import org.apache.axis.wsdl.symbolTable.BindingEntry;
054import org.apache.axis.wsdl.symbolTable.Parameters;
055import org.apache.axis.wsdl.symbolTable.ServiceEntry;
056import org.apache.axis.wsdl.symbolTable.SymTabEntry;
057import org.apache.axis.wsdl.symbolTable.SymbolTable;
058import org.w3c.dom.Document;
059import org.w3c.dom.Node;
060
061import ptolemy.actor.CompositeActor;
062import ptolemy.actor.IOPort;
063import ptolemy.actor.Manager;
064import ptolemy.actor.TypedAtomicActor;
065import ptolemy.actor.TypedIOPort;
066import ptolemy.data.ArrayToken;
067import ptolemy.data.BooleanToken;
068import ptolemy.data.DoubleToken;
069import ptolemy.data.IntToken;
070import ptolemy.data.LongToken;
071import ptolemy.data.StringToken;
072import ptolemy.data.Token;
073import ptolemy.data.XMLToken;
074import ptolemy.data.expr.Parameter;
075import ptolemy.data.expr.SingletonParameter;
076import ptolemy.data.expr.StringParameter;
077import ptolemy.data.type.BaseType;
078import ptolemy.gui.GraphicalMessageHandler;
079import ptolemy.kernel.CompositeEntity;
080import ptolemy.kernel.util.Attribute;
081import ptolemy.kernel.util.IllegalActionException;
082import ptolemy.kernel.util.NameDuplicationException;
083import ptolemy.kernel.util.Nameable;
084
085//////////////////////////////////////////////////////////////////////////
086////MessageBasedWebService
087/**
088 * The MessageWebService actor, provides the user with a plug-in interface to
089 * execute any WSDL-defined web service. Given a URL for the WSDL of a web
090 * service and an operation name that is included in the WSDL, this actor
091 * customizes itself to execute this web service operation.
092 * <P>
093 * WSDL is an XML format for describing network services as a set of endpoints
094 * operating on messages containing either document-oriented or procedure-
095 * oriented information. The operations and messages are described abstractly,
096 * and then bound to a concrete network protocol and message format to define an
097 * endpoint. Related concrete endpoints are combined into abstract endpoints
098 * (services). WSDL is extensible to allow description of endpoints and their
099 * messages regardless of what message formats or network protocols are used to
100 * communicate. More information on WSDL and realted standard can be found at:
101 * http://www.w3.org/TR/wsdl
102 * <P>
103 * The user can instantiate the generic web service actor by providing the WSDL
104 * URL and choosing the desired web service operation. The actor then a
105 * utomatically specializes itself and adds ports with the inputs and outputs as
106 * described by the WSDL. The so instantiated actor acts as a proxy for the web
107 * service being executed and links to the other actors through its ports.
108 * <P>
109 * The WSDL is parsed to get the input, output and binding information. It
110 * dynamically generates ports for each input and output of the operation. This
111 * customization happens at the configuration time of a model. When the actor is
112 * fired at run time, it gets the binding information and creates a call object
113 * to run the model. Using this call object, it invokes the web service and
114 * broadcasts the response to the output ports.
115 * 
116 * The above MessageBasedWebService actor expects XMLTokens as input and
117 * broadcasts XMLTokens as well.
118 * 
119 * <P>
120 * <I><B >Notices to users:</B>
121 * <ul>
122 * <li>Please double-click on the actor to start customization.
123 * <li>To enter a WSDL URL which is not in the given list of WSDL URLs, click on
124 * the "Preferences" button on the configuration interface and change the type
125 * of the parameter to "Text". Then you can type in the WSDL you would like to
126 * use.
127 * <li>After you select the WSDL, "Commit" and double-click on the actor again.
128 * This will reconfigure the list of available operations. Please do this
129 * everytime you change the WSDL URL.
130 * </ul>
131 * </i>
132 * 
133 * @author Ilkay Altintas, Nandita Mangal
134 * @version $Id: MessageBasedWebService.java 30702 2012-09-18 18:40:51Z crawl $
135 * @deprecated Use org.sdm.spa.WebService or org.sdm.spa.WSWithComplexTypes instead.
136 */
137
138public class MessageBasedWebService extends TypedAtomicActor {
139
140        /**
141         * Construct a WebService actor with the given container and name.
142         * 
143         * @param container
144         *            The container.
145         * @param name
146         *            The name of this actor.
147         * @exception IllegalActionException
148         *                If the actor cannot be contained by the proposed
149         *                container.
150         * @exception NameDuplicationException
151         *                If the container already has actor with this name.
152         */
153        public MessageBasedWebService(CompositeEntity container, String name)
154                        throws NameDuplicationException, IllegalActionException {
155
156                super(container, name);
157
158                // Parameters for the MessageBasedWebService Actor as
159                // wsdlURL/ws_endpoint and ws_methodName
160                // Username,Password for protected web services.
161
162                wsdlUrl = new StringParameter(this, "wsdlUrl");
163                methodName = new StringParameter(this, "methodName");
164                userName = new StringParameter(this, "userName");
165                password = new StringParameter(this, "password");
166
167                startTrigger = new TypedIOPort(this, "startTrigger", true, false);
168                hide = new SingletonParameter(startTrigger, "_hide");
169                hide.setToken(BooleanToken.TRUE);
170
171                // Set the trigger Flag.
172                hasTrigger = new Parameter(this, "hasTrigger", new BooleanToken(false));
173                hasTrigger.setTypeEquals(BaseType.BOOLEAN);
174
175                // this port is used for displaying the errors during execution of the
176                // actor
177                clientExecErrors = new TypedIOPort(this, "clientExecErrors", false,
178                                true);
179                clientExecErrors.setTypeEquals(BaseType.STRING);
180
181                _attachText("_iconDescription", "<svg>\n" + "<rect x=\"0\" y=\"0\" "
182                                + "width=\"60\" height=\"30\" " + "style=\"fill:white\"/>\n"
183                                + "</svg>\n");
184        }
185
186        // /////////////////////////////////////////////////////////////////
187        // // ports and parameters ////
188
189        /**
190         * The parameter for the URL of the web service WSDL.
191         */
192        public StringParameter wsdlUrl;
193        /**
194         * The parameter for the method name.
195         */
196        public StringParameter methodName;
197        /**
198         * The userName to invoke the web service if necessary.
199         */
200        public StringParameter userName;
201        /**
202         * The password to invoke the web service if necessary.
203         */
204        public StringParameter password;
205        /**
206         * This is an parameter to activate the optional startTrigger port.
207         * <I>Please activate it <i>ONLY</I> when the actor has no input and it is
208         * required for scheduling of the actor.
209         */
210        public Parameter hasTrigger;
211        /**
212         * This is an optional input port that can be used to help the scheduling of
213         * the actor.
214         * 
215         * <P>
216         * This port is activated by the hasTrigger parameter. Double-click on the
217         * actor to enable. <I>Please enable it <i>ONLY</I> when the actor has no
218         * input and it is required for scheduling of the actor.
219         */
220        public TypedIOPort startTrigger;
221        /**
222         * It outputs the errors if any occured when actor is executing. It outputs
223         * "NO ERRORS." if there are no exceptional cases.
224         * 
225         */
226        public TypedIOPort clientExecErrors;
227
228        public SingletonParameter hide;
229
230        // /////////////////////////////////////////////////////////////////
231        // // public methods ////
232
233        /**
234         * Callback for changes in attribute values Get the WSDL from the given URL.
235         * 
236         * @param at
237         *            The attribute that changed.
238         * @exception IllegalActionException
239         */
240        public void attributeChanged(Attribute at) throws IllegalActionException {
241
242                System.err.println("ATTRIBUTE CHANGED CALLED");
243                if (at == hasTrigger) {
244                        _triggerFlag = ((BooleanToken) hasTrigger.getToken())
245                                        .booleanValue();
246                        _debug("<TRIGGER_FLAG>" + _triggerFlag + "</TRIGGER_FLAG>");
247                        if (_triggerFlag) {
248                                try {
249                                        // startTrigger.setContainer(this);
250                                        hide.setToken(BooleanToken.FALSE);
251                                } catch (Exception ex) {
252                                        _debug("111: " + ex.getMessage());
253                                        GraphicalMessageHandler.message(this.getFullName()
254                                                        + ": Could not create the trigger port--'"
255                                                        + ex.getMessage() + "'.");
256                                }
257                        } else {
258                                List inPortList = this.inputPortList();
259                                Iterator ports = inPortList.iterator();
260                                while (ports.hasNext()) {
261                                        IOPort p = (IOPort) ports.next();
262                                        if (p.isInput()) {
263                                                try {
264                                                        if (p.getName().equals("startTrigger")) {
265                                                                // p.setContainer(null);
266                                                                hide.setToken(BooleanToken.TRUE);
267                                                        }
268                                                } catch (Exception e) {
269                                                        GraphicalMessageHandler.message(this.getFullName()
270                                                                        + ": Could not delete the trigger port--'"
271                                                                        + e.getMessage() + "'.");
272                                                }
273                                        }
274                                }
275                        }
276                } else if (at == wsdlUrl) {
277
278                        List inPortList = this.inputPortList();
279                        int numInPorts = inPortList.size();
280                        List outPortList = this.outputPortList();
281                        int numOutPorts = outPortList.size();
282
283                        if (wsdlUrl.getExpression().equals("")) {
284                                // System.out.println("WSD url is empty string");
285                                // do nothing
286                        } else if ((_urlStr.equals(""))
287                                        && (methodName.getExpression().equals(""))
288                                        && (numInPorts == 0) && (numOutPorts == 0)) {
289                                // System.out.println("WSDL url before getExpression: " +
290                                // _urlStr);
291                                _urlStr = wsdlUrl.getExpression();
292                                // System.out.println("Method name before removeAllChoice: " +
293                                // _methodNameStr);
294                                methodName.removeAllChoices();
295                                // System.out.println("Method name after removeAllChoice: " +
296                                // _methodNameStr);
297                                // System.out.println("WSDL url after getExpression: " +
298                                // _urlStr);
299                                _wsdlParser = new Parser();
300                                _confErrorStr = "";
301                                // Parse the wsdl for the web service.
302                                try {
303                                        _wsdlParser.run(_urlStr);
304                                        configureOperationNames();
305                                } catch (Exception ex) {
306                                        _debug("<EXCEPTION> There was an error while parsing the WSDL. "
307                                                        + ex + ". </EXCEPTION>");
308                                        _confErrorStr += "\n" + this.getFullName()
309                                                        + ": Could not parse WSDL--'" + ex.getMessage()
310                                                        + "'.";// );
311                                }
312                                if (!(_confErrorStr.equals(""))) {
313                                        GraphicalMessageHandler.message(_confErrorStr);
314                                }
315                        } else if ((_urlStr.equals(""))
316                                        && (!(methodName.getExpression().equals("")))
317                                        && ((numInPorts != 0) && (numOutPorts != 0))) // The actor
318                                                                                                                                        // has at
319                                                                                                                                        // least one
320                                                                                                                                        // port
321                        {
322                                // System.out.println("WSDL url before getExpression: " +
323                                // _urlStr);
324                                _urlStr = wsdlUrl.getExpression();
325                                // System.out.println("Method name before removeAllChoice: "
326                                // +_methodNameStr);
327                                // System.out.println("Method name after removeAllChoice: " +
328                                // _methodNameStr);
329                                // System.out.println("WSDL url after getExpression: " +
330                                // _urlStr);
331                        } else if (!(this._urlStr.equals(wsdlUrl.getExpression()))) { // If
332                                                                                                                                                        // the
333                                                                                                                                                        // value
334                                                                                                                                                        // has
335                                                                                                                                                        // really
336                                                                                                                                                        // changed.
337                                _confErrorStr = "";
338                                // System.out.println("WSDL url before getExpression: " +
339                                // _urlStr);
340                                _urlStr = wsdlUrl.getExpression();
341                                // System.out.println("Method name before removeAllChoice: " +
342                                // _methodNameStr);
343                                methodName.removeAllChoices();
344                                // System.out.println("Method name after removeAllChoice: "
345                                // +_methodNameStr);
346                                // System.out.println("WSDL url after getExpression: " +
347                                // _urlStr);
348                                deletePorts();
349                                _wsdlParser = new Parser();
350                                // Parse the wsdl for the web service.
351                                try {
352                                        _wsdlParser.run(_urlStr);
353                                        configureOperationNames();
354                                } catch (Exception ex) {
355                                        _debug("<EXCEPTION> There was an error while parsing the WSDL. "
356                                                        + ex + ". </EXCEPTION>");
357                                        // GraphicalMessageHandler.message(
358                                        _confErrorStr += "\n"
359                                                        + ex.getMessage()
360                                                        + "There was an error while parsing the WSDL in the actor: "
361                                                        + this.getName();// );
362                                }
363                        } else {
364                                _debug("The " + _urlStr
365                                                + " was the same. Ports left unchanged.");
366                        }
367                        if (!(_confErrorStr.equals(""))) {
368                                GraphicalMessageHandler.message(_confErrorStr);
369                        }
370                } else if (at == methodName) {
371
372                        List inPortList = this.inputPortList();
373                        int numInPorts = inPortList.size();
374                        List outPortList = this.outputPortList();
375                        int numOutPorts = outPortList.size();
376
377                        if (methodName.getExpression().equals("")) {
378                                // System.out.println("Method name is empty string.");
379                                // do nothing
380                        } else if ((_methodNameStr.equals("")) && (numInPorts == 0)
381                                        && (numOutPorts == 0)) {
382                                _confErrorStr = "";
383                                // System.out.println("Method name before get expression: "
384                                // +_methodNameStr);
385                                _methodNameStr = methodName.getExpression();
386                                _debug("<METHOD_NAME>" + _methodNameStr + "</METHOD_NAME>");
387                                // System.out.println("Method name after get expression: " +
388                                // _methodNameStr);
389                                int slashIndex = _urlStr.lastIndexOf('/');
390                                _wsName = _urlStr.substring(slashIndex + 1,
391                                                _urlStr.length() - 5);
392
393                                _attachText(
394                                                "_iconDescription",
395                                                "<svg>\n"
396                                                                + "<rect x=\"0\" y=\"0\" "
397                                                                + "width=\"160\" height=\"50\" "
398                                                                + "style=\"fill:white\"/>\n"
399                                                                + "<text x=\"20\" y=\"25\""
400                                                                + "style=\"font-size:11; fill:red; font-family:SansSerif\">"
401                                                                + _wsName + "_" + _methodNameStr + "</text>\n"
402                                                                + "</svg>\n");
403                                configureActor();
404                                if (!(_confErrorStr.equals(""))) {
405                                        GraphicalMessageHandler.message(_confErrorStr);
406                                }
407                        } else if ((_methodNameStr.equals(""))
408                                        && ((numInPorts != 0) && (numOutPorts != 0))) // The actor
409                                                                                                                                        // has at
410                                                                                                                                        // least one
411                                                                                                                                        // port
412                        {
413                                // System.out.println("Method name before get expression: "
414                                // +_methodNameStr);
415                                _methodNameStr = methodName.getExpression();
416                                _debug("<METHOD_NAME>" + _methodNameStr + "</METHOD_NAME>");
417                                // System.out.println("Method name after get expression: " +
418                                // _methodNameStr);
419                                int slashIndex = _urlStr.lastIndexOf('/');
420                                _wsName = _urlStr.substring(slashIndex + 1,
421                                                _urlStr.length() - 5);
422                                _attachText(
423                                                "_iconDescription",
424                                                "<svg>\n"
425                                                                + "<rect x=\"0\" y=\"0\" "
426                                                                + "width=\"160\" height=\"50\" "
427                                                                + "style=\"fill:white\"/>\n"
428                                                                + "<text x=\"20\" y=\"25\""
429                                                                + "style=\"font-size:11; fill:red; font-family:SansSerif\">"
430                                                                + _wsName + "_" + _methodNameStr + "</text>\n"
431                                                                + "</svg>\n");
432                        } else if (!(this._methodNameStr.equals(methodName.getExpression()))) { // if
433                                                                                                                                                                        // the
434                                                                                                                                                                        // methodName
435                                                                                                                                                                        // really
436                                                                                                                                                                        // changed.
437
438                                _confErrorStr = "";
439                                // System.out.println("Method name before get expression: "
440                                // +_methodNameStr);
441                                _methodNameStr = methodName.getExpression();
442                                _debug("<METHOD_NAME>" + _methodNameStr + "</METHOD_NAME>");
443                                // System.out.println("Method name after get expression: " +
444                                // _methodNameStr);
445                                int slashIndex = _urlStr.lastIndexOf('/');
446                                _wsName = _urlStr.substring(slashIndex + 1,
447                                                _urlStr.length() - 5);
448
449                                _attachText(
450                                                "_iconDescription",
451                                                "<svg>\n"
452                                                                + "<rect x=\"0\" y=\"0\" "
453                                                                + "width=\"160\" height=\"50\" "
454                                                                + "style=\"fill:white\"/>\n"
455                                                                + "<text x=\"20\" y=\"25\""
456                                                                + "style=\"font-size:11; fill:red; font-family:SansSerif\">"
457                                                                + _wsName + "_" + _methodNameStr + "</text>\n"
458                                                                + "</svg>\n");
459
460                                // Delete all the ports the actor has when the method name
461                                // changes.
462                                deletePorts();
463                                configureActor();
464                                if (!(_confErrorStr.equals(""))) {
465                                        GraphicalMessageHandler.message(_confErrorStr);
466                                }
467                        } else {
468                                _debug("The " + _methodNameStr + " was the same. "
469                                                + "Ports left unchanged.");
470                        }
471                }
472        } // end of attributeChanged
473
474        /**
475         * Configure the actor for the entered operation of the given web service.
476         */
477        public void configureOperationNames() {
478
479                System.err.println("CONFIGURE OPERATION NAMES callled");
480
481                try {
482                        _service = null;
483
484                        // Find the entry for the ServiceEntry class in the symbol table.
485                        HashMap map = _wsdlParser.getSymbolTable().getHashMap();
486                        Iterator entrySetIter = map.entrySet().iterator();
487                        while (entrySetIter.hasNext()) {
488                                Map.Entry currentEntry = (Map.Entry) entrySetIter.next();
489                                Vector valueVector = (Vector) currentEntry.getValue();
490                                int vecSize = valueVector.size();
491                                for (int index = 0; index < vecSize; ++index) {
492                                        SymTabEntry symTabEntryObj = (SymTabEntry) valueVector
493                                                        .get(index);
494                                        if ((ServiceEntry.class).isInstance(symTabEntryObj)) {
495                                                _service = ((ServiceEntry) symTabEntryObj).getService();
496                                        }
497                                }
498                        }
499
500                        Port port = _getSOAPAddress(_service.getPorts());
501                        if (port == null) {
502                                _debug("<ERROR> No port was returned by the _getSOAPAddress. </ERROR>");
503
504                        }
505                        _portName = "";
506                        _portName = port.getName();
507                        _binding = port.getBinding();
508                        SymbolTable symbolTable = _wsdlParser.getSymbolTable();
509                        BindingEntry bEntry = symbolTable.getBindingEntry(_binding
510                                        .getQName());
511
512                        Operation operation = null;
513                        Parameters parameters = null;
514                        Iterator iter = bEntry.getParameters().keySet().iterator();
515                        for (; iter.hasNext();) {
516                                Operation oper = (Operation) iter.next();
517                                methodName.addChoice(oper.getName());
518                        }
519                } catch (Exception ex) {
520                        _debug("<EXCEPTION> There was an error when configuring the actor: "
521                                        + ex + ". </EXCEPTION>");
522                        // GraphicalMessageHandler.message(
523                        _confErrorStr += "\n" + this.getFullName()
524                                        + ": Could not configure actor--'" + ex.getMessage() + "'.";// );
525                }
526        } // end-of-configureOperationNames
527
528        /**
529         * Configure the actor for the entered operation of the given web service.
530         */
531        public void configureActor() {
532
533                System.err.println("CONFIGURE ACTOR called:");
534                try {
535                        _service = null;
536
537                        // Find the entry for the ServiceEntry class in the symbol table.
538                        HashMap map = _wsdlParser.getSymbolTable().getHashMap();
539                        Iterator entrySetIter = map.entrySet().iterator();
540                        while (entrySetIter.hasNext()) {
541                                Map.Entry currentEntry = (Map.Entry) entrySetIter.next();
542                                Vector valueVector = (Vector) currentEntry.getValue();
543                                int vecSize = valueVector.size();
544                                for (int index = 0; index < vecSize; ++index) {
545                                        SymTabEntry symTabEntryObj = (SymTabEntry) valueVector
546                                                        .get(index);
547                                        if ((ServiceEntry.class).isInstance(symTabEntryObj)) {
548                                                _service = ((ServiceEntry) symTabEntryObj).getService();
549                                        }
550                                }
551                        }
552
553                        Port port = _getSOAPAddress(_service.getPorts());
554                        if (port == null) {
555                                _debug("<ERROR> No port was returned by the _getSOAPAddress. </ERROR>");
556                        }
557                        _portName = "";
558                        _portName = port.getName();
559                        _binding = port.getBinding();
560                        SymbolTable symbolTable = _wsdlParser.getSymbolTable();
561                        BindingEntry bEntry = symbolTable.getBindingEntry(_binding
562                                        .getQName());
563
564                        Operation operation = null;
565                        Parameters parameters = null;
566                        Iterator iter = bEntry.getParameters().keySet().iterator();
567                        for (; iter.hasNext();) {
568                                Operation oper = (Operation) iter.next();
569                                if (oper.getName().equals(_methodNameStr)) {
570                                        operation = oper;
571                                        parameters = (Parameters) bEntry.getParameters().get(oper);
572                                        createPorts(parameters);
573
574                                        // Set output type
575                                        if (parameters.returnParam == null) {
576                                                _returnMode = 1; // Get outputs into a map object!
577                                        } else if (parameters.returnParam != null) {
578                                                _returnMode = 2; // Get the invoke result value as a
579                                                                                        // single value.
580                                                // Get the QName for the return Type
581                                                QName returnQName = parameters.returnParam.getQName();
582                                                if (((org.apache.axis.wsdl.symbolTable.Parameter) parameters.returnParam)
583                                                                .getType().getDimensions().equals("[]")) {
584                                                        Node arrTypeNode = ((org.apache.axis.wsdl.symbolTable.Parameter) parameters.returnParam)
585                                                                        .getType().getNode();
586                                                        String baseTypeStr = _getArrayBaseType(arrTypeNode);
587                                                        _debug("ARRAY PARAM BASE TYPE: " + baseTypeStr);
588                                                        _createPort(
589                                                                        ((org.apache.axis.wsdl.symbolTable.Parameter) parameters.returnParam)
590                                                                                        .getMode(), baseTypeStr,
591                                                                        (String) returnQName.getLocalPart());
592                                                } else {
593                                                        _createPort(
594                                                                        ((org.apache.axis.wsdl.symbolTable.Parameter) parameters.returnParam)
595                                                                                        .getMode(),
596                                                                        ((org.apache.axis.wsdl.symbolTable.Parameter) parameters.returnParam)
597                                                                                        .getType().getQName()
598                                                                                        .getLocalPart(),
599                                                                        (String) returnQName.getLocalPart());
600                                                }
601                                                _debug("<RETURN_QNAME>" + returnQName.getLocalPart()
602                                                                + "</RETURN_QNAME>");
603                                        }
604                                        // Break out of the loop
605                                        break;
606                                }
607                        }
608                } catch (Exception ex) {
609                        _debug("<EXCEPTION> There was an error when configuring the actor: "
610                                        + ex + ". </EXCEPTION>");
611                        // GraphicalMessageHandler.message(
612                        _confErrorStr += "\n" + ex.getMessage()
613                                        + "There was an error when configuring the actor:"
614                                        + this.getName();// );
615                }
616        } // end-of-configureActor
617
618        /**
619         * Query the base type of the array type specified in the given dom node.
620         * 
621         * @param arrayTypeNode
622         *       */
623        private String _getArrayBaseType(Node arrayTypeNode) {
624                _debug("TYPE NAME: "
625                                + arrayTypeNode.getAttributes().getNamedItem("name"));
626                String baseTStr = arrayTypeNode.getFirstChild().getFirstChild()
627                                .getFirstChild().getAttributes().getNamedItem("wsdl:arrayType")
628                                .getNodeValue();
629                String[] result = baseTStr.split(":");
630                baseTStr = result[1];
631                return baseTStr;
632        } // end-of-getArrayBaseType
633
634        /** Creates ports for the web service operation */
635        public void createPorts(Parameters params) {
636                try {
637                        // Create ports using the input and output part descriptions
638                        for (int j = 0; j < params.list.size(); j++) {
639                                org.apache.axis.wsdl.symbolTable.Parameter param = (org.apache.axis.wsdl.symbolTable.Parameter) params.list
640                                                .get(j);
641                                _debug("PARAM DIMENSION: " + param.getType().getDimensions());
642                                _debug("PARAM TYPE: "
643                                                + param.getType().getQName().getLocalPart());
644                                if (param.getType().getDimensions().equals("[]")) {
645
646                                        Node arrTypeNode = param.getType().getNode();
647                                        _debug("TYPE NAME: "
648                                                        + arrTypeNode.getAttributes().getNamedItem("name"));
649                                        String baseTypeStr = arrTypeNode.getFirstChild()
650                                                        .getFirstChild().getFirstChild().getAttributes()
651                                                        .getNamedItem("wsdl:arrayType").getNodeValue();
652                                        String[] result = baseTypeStr.split(":");
653                                        baseTypeStr = result[1];
654                                        _debug("ARRAY PARAM BASE TYPE: " + baseTypeStr);
655                                        _createPort(param.getMode(), baseTypeStr, (String) param
656                                                        .getQName().getLocalPart());
657                                } else { // if (param.getType().getDimension() != null) {
658                                        _createPort(param.getMode(), param.getType().getQName()
659                                                        .getLocalPart(), (String) param.getQName()
660                                                        .getLocalPart());
661                                }
662                        }
663                } catch (Exception ex) {
664                        _debug("<EXCEPTION> There was an error when creating the TypedIOPorts: "
665                                        + ex + "</EXCEPTION>");
666                        // GraphicalMessageHandler.message(
667                        _errorsStr += "\n" + this.getFullName()
668                                        + ": Could not create ports--'" + ex.getMessage() + "'.";// );
669                }
670        }
671
672        private void _createPort(int mode, String portTypeStr, String portNameStr) {
673
674                System.err.println("CREATE PORT CALLED");
675                try {
676                        if (mode == 1) { // input
677                                TypedIOPort pin = new TypedIOPort(this, portNameStr, true,
678                                                false);
679                                new Attribute(pin, "_showName");
680                                _setPortType(pin, portTypeStr);
681                                _debug("<INPUT>" + portNameStr + "</INPUT>");
682                        } else if (mode == 2) { // output
683                                TypedIOPort pout = new TypedIOPort(this, portNameStr, false,
684                                                true);
685                                new Attribute(pout, "_showName");
686                                _setPortType(pout, portTypeStr);
687                                _debug("<OUTPUT>" + portNameStr + "</OUTPUT>");
688                        } else if (mode == 3) { // input/output
689                                TypedIOPort pin = new TypedIOPort(this, portNameStr, true,
690                                                false);
691                                new Attribute(pin, "_showName");
692                                _setPortType(pin, portTypeStr);
693                                _debug("<INPUT>" + portNameStr + "</INPUT>");
694                                TypedIOPort pout = new TypedIOPort(this, portNameStr, false,
695                                                true);
696                                new Attribute(pout, "_showName");
697                                _setPortType(pout, portTypeStr);
698                                _debug("<OUTPUT>" + portNameStr + "</OUTPUT>");
699                        }
700                } catch (ptolemy.kernel.util.IllegalActionException iae) {
701                        _debug("<EXCEPTION> There was an IllegalActionException when creating the TypedIOPorts in _createPort: "
702                                        + iae + "</EXCEPTION>");
703                        // GraphicalMessageHandler.message(
704                        _errorsStr += "\n"
705                                        + iae.getMessage()
706                                        + "There was an error when creating the TypedIOPorts in actor: "
707                                        + this.getName();// );
708                } catch (ptolemy.kernel.util.NameDuplicationException nde) {
709                        // GraphicalMessageHandler.message(
710                        _errorsStr += "\n"
711                                        + nde.getMessage()
712                                        + "\nThere was a NameDuplicationException when creating the "
713                                        + "TypedIOPorts in the actor: " + this.getName();// );
714                        _debug("<EXCEPTION> There was a NameDuplicationException when creating the TypedIOPorts in _createPort: "
715                                        + nde + "</EXCEPTION>");
716                }
717        } // end-of-createPort
718
719        /** Deletes all the ports of this actor. */
720        public void deletePorts() {
721                List inPortList = this.inputPortList();
722                Iterator ports = inPortList.iterator();
723                while (ports.hasNext()) {
724                        IOPort p = (IOPort) ports.next();
725                        if (p.isInput()) {
726                                try {
727                                        if (!(p.getName().equals("startTrigger"))) {
728                                                p.setContainer(null);
729                                        }
730                                } catch (Exception e) {
731                                        // GraphicalMessageHandler.message(
732                                        _confErrorStr += "\n" + e.getMessage()
733                                                        + "Could not delete the input port: " + p.getName()
734                                                        + " in the actor: " + this.getName();// );
735                                }
736                        }
737                }
738
739                List outPortList = this.outputPortList();
740                int numOutPorts = outPortList.size();
741                Iterator oports = outPortList.iterator();
742                while (oports.hasNext()) {
743                        IOPort outp = (IOPort) oports.next();
744                        if (outp.isOutput()) {
745                                try {
746                                        if (!(outp.getName().equals("clientExecErrors"))) {
747                                                outp.setContainer(null);
748                                        }
749                                } catch (Exception e) {
750                                        // GraphicalMessageHandler.message(
751                                        _confErrorStr += "\n" + e.getMessage()
752                                                        + "Could not delete the output port:"
753                                                        + outp.getName() + " in the actor: "
754                                                        + this.getName();// );
755                                }
756                        }
757                }
758        } // end of deletePorts
759
760        /**
761         * Get the URL address of the the location of the web service defined by the
762         * given WSDL. Get the the namespace and binding information ofthe web
763         * service using the given WSDL and methodName. Add a parameterto the call
764         * object for each input part.Fill these parameters with the input values on
765         * channels on the ports that correspond to them. Invoke the web service
766         * using all the gathered information. Send the response of the call to the
767         * result port.
768         * 
769         * @exception IllegalActionException
770         *                If there is no director.
771         */
772        public void fire() throws IllegalActionException {
773
774                super.fire();
775
776                // triggerring the actor..
777                if (startTrigger.getWidth() > 0) {
778                        for (int i = 0; i < startTrigger.getWidth(); i++)
779                                startTrigger.get(i);
780                }
781
782                _urlStr = wsdlUrl.getExpression();
783                _methodNameStr = methodName.getExpression();
784
785                _wsdlParser = new Parser();
786
787                try {
788                        _wsdlParser.run(_urlStr);
789                } catch (Exception ex) {
790                        _debug("<EXCEPTION> There was an error while parsing the WSDL in fire for URL: "
791                                        + _urlStr + " .\n" + ex + ". </EXCEPTION>");
792                        // GraphicalMessageHandler.message(
793                        _errorsStr += "\n"
794                                        + ex.getMessage()
795                                        + "Error in fire: There was an error while parsing the WSDL in the actor: "
796                                        + this.getName();// );
797                }
798                getServiceBinding();
799                try {
800                        SymbolTable symbolTable = _wsdlParser.getSymbolTable();
801                        BindingEntry bEntry = symbolTable.getBindingEntry(_binding
802                                        .getQName());
803                        Operation operation = null;
804                        Parameters parameters = null;
805                        Iterator iter = bEntry.getParameters().keySet().iterator();
806                        for (; iter.hasNext();) {
807                                Operation oper = (Operation) iter.next();
808                                if (oper.getName().equals(_methodNameStr)) {
809                                        operation = oper;
810                                        parameters = (Parameters) bEntry.getParameters().get(oper);
811                                        // Set output type
812                                        if (parameters.returnParam == null) {
813                                                _returnMode = 1; // Get outputs into a map object!
814                                        } else if (parameters.returnParam != null) {
815                                                _returnMode = 2; // Get the invoke result value as a
816                                                                                        // single value.
817                                        }
818                                        // Break out of the loop
819                                        break;
820                                }
821                        }
822                } catch (Exception ex) {
823                        _debug("<EXCEPTION>In fire when setting the return mode: " + ex
824                                        + ". </EXCEPTION>");
825                        // GraphicalMessageHandler.message(
826                        _errorsStr += "\n"
827                                        + ex.getMessage()
828                                        + "There was an error when setting up the return mode of the web "
829                                        + "service at: " + this.getName();// );
830                }
831
832                try {
833
834                        // prepare and make call
835
836                        org.apache.axis.client.Service myServiceClient = new org.apache.axis.client.Service();
837                        _call = (org.apache.axis.client.Call) myServiceClient.createCall();
838
839                        System.out.println("URL:" + _urlStr);
840                        _call.setTargetEndpointAddress(_urlStr);
841                        _call.setProperty(org.apache.axis.AxisEngine.PROP_DOMULTIREFS,
842                                        Boolean.FALSE);
843                        _call.setProperty(org.apache.axis.AxisEngine.PROP_SEND_XSI,
844                                        Boolean.FALSE);
845                        _call.setOperationName(new QName(_urlStr, _methodNameStr));
846                        // _call.addParameter("body", XMLType.SOAP_DOCUMENT,
847                        // ParameterMode.IN);
848                        // _call.setReturnType(XMLType.ESOAP_DOCUMENT);
849                        _call.setOperationStyle(Style.DOCUMENT);
850
851                        // _debug("<OBJ_ARR_LENGTH> " + (new
852                        // Integer(_objArr.length)).toString() + " </OBJ_ARR_LENGTH>");
853                        // _debug("<USERNAME> " + userName.stringValue() + "</USERNAME>");
854                        // _call.setProperty(Call.USERNAME_PROPERTY,userName.stringValue());
855                        _debug("<PASSWORD> " + password.stringValue() + " </PASSWORD>");
856                        _call.setProperty(Call.PASSWORD_PROPERTY, password.stringValue());
857
858                        Document request_doc = null;
859
860                        List inPortList = this.inputPortList();
861                        Iterator ports = inPortList.iterator();
862                        while (ports.hasNext()) {
863                                IOPort p = (IOPort) ports.next();
864                                System.out.println("Input = " + p.getName());
865                                if (p.isInput() && !p.getName().equals("startTrigger")) {
866                                        Object obj = p.get(0);
867                                        System.out.println("Input = " + obj);
868                                        if (obj instanceof XMLToken) {
869                                                XMLToken token = (XMLToken) obj;
870                                                System.out.println("INPUT is " + token);
871                                                try {
872                                                        ByteArrayInputStream bais = new ByteArrayInputStream(
873                                                                        token.toString().getBytes());
874                                                        request_doc = XMLUtils.newDocument(bais);
875                                                } catch (Exception ex) {
876                                                        ex.printStackTrace();
877                                                        _debug("<EXCEPTION>" + ex + "</EXCEPTION>");
878                                                }
879                                        }
880                                }
881                        }
882
883                        if (request_doc != null) {
884                                SOAPBodyElement inputEle = new SOAPBodyElement(request_doc
885                                                .getDocumentElement());
886                                // System.out.println(xml);
887                                System.out.println("Starting the invoke!");
888
889                                _call.invoke(new Object[] { inputEle });
890
891                                System.out.println("Got results from the invoke...");
892
893                                Message response = _call.getResponseMessage();
894                                SOAPBodyElement s1body = null;
895                                String tempOutput = null;
896                                try {
897                                        s1body = response.getSOAPEnvelope().getFirstBody();
898                                        tempOutput = XMLUtils.DocumentToString(s1body
899                                                        .getAsDocument());
900                                        System.out.println(tempOutput);
901                                        _debug("<TEMPOUTPUT>" + tempOutput + "</TEMPOUTPUT>");
902                                } catch (Exception ex) {
903                                        ex.printStackTrace();
904                                        _debug("<EXCEPTION>" + ex + "</EXCEPTION>");
905                                }
906                                // _sendOutput(output, tempOutput);
907
908                                // We would send the temp out to all the output ports
909                                List outPortList = this.outputPortList();
910                                Iterator oports = outPortList.iterator();
911                                // Now we are sending the Document (in String form) namely
912                                // tempOutput to the
913                                // respective port via the method _sendOutput.
914
915                                while (oports.hasNext()) {
916                                        TypedIOPort po = (TypedIOPort) oports.next();
917                                        System.out.println("Output port = " + po.getName());
918                                        if (!(po.getName().equals("clientExecErrors"))) {
919                                                po.broadcast(new XMLToken(tempOutput));
920                                                System.out.println("Output is" + tempOutput);
921                                        }
922                                }
923                        } else {
924                                System.out.println("No input found");
925
926                        }
927                } catch (ServiceException se) {
928                        se.printStackTrace();
929                        _debug("<EXCEPTION> Service exception in fire() method: "
930                                        + se.getMessage() + ". </EXCEPTION>");
931                        // GraphicalMessageHandler.message(
932                        _errorsStr += "\n" + se.getMessage()
933                                        + "\nThe service exception error occured in the actor: "
934                                        + this.getName();// );
935                } catch (Exception rex) {
936                        rex.printStackTrace();
937                        _debug("<EXCEPTION> Remote exception in fire() method: "
938                                        + rex.getMessage() + ". </EXCEPTION>");
939                        // get rmi.getCause() and print it here.
940                        // GraphicalMessageHandler.message(
941                        _errorsStr += "\n" + rex.getMessage()
942                                        + "\nThe remote exception error occured in the actor: "
943                                        + this.getName();// );
944
945                        // FIX ME: Don't stop the model here but pause and let the user
946                        // refine it!
947                        /*
948                         * // NOTE: We need to consume data on all channels that have data.
949                         * // If we don't then DE will go into an infinite loop. for (int i
950                         * = 0; i < input.getWidth(); i++) { if (input.hasToken(i)) { if
951                         * (((BooleanToken)input.get(i)).booleanValue()) { result = true; }
952                         * } }
953                         */
954                        Nameable container = getContainer();
955                        if (container instanceof CompositeActor) {
956                                Manager manager = ((CompositeActor) container).getManager();
957                                if (manager != null) {
958                                        manager.finish();
959                                } else {
960                                        throw new IllegalActionException(this,
961                                                        "Cannot stop without a Manager.");
962                                }
963                        } else {
964                                throw new IllegalActionException(this,
965                                                "Cannot stop without a container that is a CompositeActor.");
966                        }
967                }
968
969                System.out.println(_errorsStr);
970                if (!(_errorsStr.equals(""))) {
971                        clientExecErrors.broadcast(new StringToken(_errorsStr));
972                } else {
973                        clientExecErrors.broadcast(new StringToken("NO ERRORS."));
974                }
975        } // end of fire
976
977        /** Configure the service, port and binding info. */
978        public void getServiceBinding() {
979                try {
980                        _service = null;
981
982                        // Find the entry for the ServiceEntry class in the symbol table.
983                        HashMap map = _wsdlParser.getSymbolTable().getHashMap();
984                        Iterator entrySetIter = map.entrySet().iterator();
985                        while (entrySetIter.hasNext()) {
986                                Map.Entry currentEntry = (Map.Entry) entrySetIter.next();
987                                Vector valueVector = (Vector) currentEntry.getValue();
988                                int vecSize = valueVector.size();
989                                for (int index = 0; index < vecSize; ++index) {
990                                        SymTabEntry symTabEntryObj = (SymTabEntry) valueVector
991                                                        .get(index);
992                                        if ((ServiceEntry.class).isInstance(symTabEntryObj)) {
993                                                _service = ((ServiceEntry) symTabEntryObj).getService();
994                                        }
995                                }
996                        }
997
998                        Port port = _getSOAPAddress(_service.getPorts());
999                        if (port == null) {
1000                                _debug("<ERROR> No port was returned by the _getSOAPAddress.</ERROR>");
1001                        }
1002                        _portName = "";
1003                        _portName = port.getName();
1004                        _binding = port.getBinding();
1005                } catch (Exception ex) {
1006                        _debug("<EXCEPTION> There was an error when configuring the actor: "
1007                                        + ex + ". </EXCEPTION>");
1008                        // GraphicalMessageHandler.message(
1009                        _errorsStr += "\n" + ex.getMessage()
1010                                        + "There was an error when configuring the actor:"
1011                                        + this.getName();// );
1012                }
1013        } // end-of-getServiceBinding
1014
1015        /**
1016         * Pre fire the actor. Calls the super class's prefire in case something is
1017         * set there.
1018         */
1019        public boolean prefire() throws IllegalActionException {
1020                return super.prefire();
1021        } // end of prefire
1022
1023        // ////////////////////////////////////////////////////////////////////
1024        // // private methods
1025        // //
1026
1027        /**
1028         * Returns a port with a SOAPAddress extensibility element.
1029         */
1030        private Port _getSOAPAddress(Map ports) {
1031                Iterator nameIter = ports.keySet().iterator();
1032                while (nameIter.hasNext()) {
1033                        String portName = (String) nameIter.next();
1034                        Port port = (Port) ports.get(portName);
1035                        List extElemList = port.getExtensibilityElements();
1036                        for (int i = 0; (extElemList != null) && (i < extElemList.size()); i++) {
1037                                Object extEl = extElemList.get(i);
1038                                if (extEl instanceof SOAPAddress) {
1039                                        return port;
1040                                }
1041                        }
1042                }
1043                return null;
1044        } // end-of-getSOAPAddress
1045
1046        /**
1047         * _sendOutput Send the output ports from the given port with the right type
1048         * casting.
1049         * 
1050         * @param outPort
1051         * @param res
1052         */
1053        private void _sendOutput(TypedIOPort outPort, Object res) {
1054                _debug("<RES_CLASS_NAME>" + res.getClass().getName()
1055                                + "</RES_CLASS_NAME>");
1056                try {
1057                        if (res instanceof String) {
1058                                if (outPort.getType().toString().equals("string")) {
1059                                        outPort.broadcast(new StringToken((String) res));
1060                                } else {
1061                                        _debug("<ERROR> The outPort type ("
1062                                                        + outPort.getType().toString()
1063                                                        + ") and the res type(String) do not match in _sendOutput(). <ERROR>");
1064                                }
1065                        } else if (res instanceof Integer) {
1066                                if (outPort.getType().toString().equals("int")) {
1067                                        outPort.broadcast(new IntToken(((Integer) res).intValue()));
1068                                } else {
1069                                        _debug("<ERROR> The outPort type ("
1070                                                        + outPort.getType().toString()
1071                                                        + ") and the res type(Integer) do not match in_sendOutput(). <ERROR>");
1072                                }
1073                        } else if (res instanceof Double) {
1074                                if (outPort.getType().toString().equals("double")) {
1075                                        outPort.broadcast(new DoubleToken(((Double) res)
1076                                                        .doubleValue()));
1077                                } else {
1078                                        _debug("<ERROR> The outPort type ("
1079                                                        + outPort.getType().toString()
1080                                                        + ") and the res type(Double) do not match in sendOutput(). <ERROR>");
1081                                }
1082                        } else if (res instanceof Long) {
1083                                if (outPort.getType().toString().equals("long")) {
1084                                        outPort.broadcast(new LongToken(((Long) res).longValue()));
1085                                } else {
1086                                        _debug("<ERROR> The outPort type ("
1087                                                        + outPort.getType().toString()
1088                                                        + ") and the res type(Long) do not match in _sendOutput().<ERROR>");
1089                                }
1090                        } else if (res instanceof Boolean) {
1091                                if (outPort.getType().toString().equals("boolean")) {
1092                                        outPort.broadcast(new BooleanToken(((Boolean) res)
1093                                                        .booleanValue()));
1094                                } else {
1095                                        _debug("<ERROR> The outPort type ("
1096                                                        + outPort.getType().toString()
1097                                                        + ") and the res type(Boolean) do not match in _sendOutput(). <ERROR>");
1098                                }
1099                        } else if (res instanceof String[]) {
1100                                if (outPort.getType().toString().equals("{string}")) {
1101                                        String[] resultArr = (String[]) res;
1102                                        int xxx = resultArr.length;
1103                                        String resultArrStr = "{";
1104                                        for (int resCount = 0; resCount < xxx - 1; resCount++) {
1105                                                _debug("resultArr[" + resCount + "] = "
1106                                                                + resultArr[resCount]);
1107                                                resultArrStr += resultArr[resCount] + ", ";
1108                                        }
1109                                        resultArrStr += resultArr[xxx - 1] + "}";
1110                                        outPort.broadcast(new ArrayToken(resultArrStr));
1111                                } else {
1112                                        _debug("<ERROR> The outPort type ("
1113                                                        + outPort.getType().toString()
1114                                                        + ") and the res type(String[]) do not match in_sendOutput(). <ERROR>");
1115                                }
1116                        } else if ((res instanceof Integer[])) {
1117                                _debug("IN Integer[]");
1118                                if (outPort.getType().toString().equals("{int}")) {
1119                                        Integer[] resultArr = (Integer[]) res;
1120                                        int xxx = resultArr.length;
1121                                        String resultArrStr = "{";
1122                                        for (int resCount = 0; resCount < xxx - 1; resCount++) {
1123                                                _debug("resultArr[" + resCount + "] = "
1124                                                                + resultArr[resCount]);
1125                                                resultArrStr += resultArr[resCount] + ", ";
1126                                        }
1127                                        resultArrStr += resultArr[xxx - 1] + "}";
1128                                        outPort.broadcast(new ArrayToken(resultArrStr));
1129                                } else {
1130                                        _debug("<ERROR> The outPort type ("
1131                                                        + outPort.getType().toString()
1132                                                        + ") and the res type(String[]) do not match in_sendOutput(). <ERROR>");
1133                                }
1134                        } else if (res instanceof int[]) {
1135                                _debug("IN int[]");
1136                                if (outPort.getType().toString().equals("{int}")) {
1137                                        int[] resultArr = (int[]) res;
1138                                        int xxx = resultArr.length;
1139                                        String resultArrStr = "{";
1140                                        for (int resCount = 0; resCount < xxx - 1; resCount++) {
1141                                                _debug("resultArr[" + resCount + "] = "
1142                                                                + resultArr[resCount]);
1143                                                resultArrStr += resultArr[resCount] + ", ";
1144                                        }
1145                                        resultArrStr += resultArr[xxx - 1] + "}";
1146                                        _debug(resultArrStr);
1147                                        outPort.broadcast(new ArrayToken(resultArrStr));
1148                                } else {
1149                                        _debug("<ERROR> The outPort type ("
1150                                                        + outPort.getType().toString()
1151                                                        + ") and the res type(String[]) do not match in_sendOutput(). <ERROR>");
1152                                }
1153                        } else if (res instanceof Double[]) {
1154                                _debug("IN Double[]");
1155                                if (outPort.getType().toString().equals("{double}")) {
1156                                        Double[] resultArr = (Double[]) res;
1157                                        int xxx = resultArr.length;
1158                                        String resultArrStr = "{";
1159                                        for (int resCount = 0; resCount < xxx - 1; resCount++) {
1160                                                _debug("resultArr[" + resCount + "] = "
1161                                                                + resultArr[resCount]);
1162                                                resultArrStr += resultArr[resCount] + ", ";
1163                                        }
1164                                        resultArrStr += resultArr[xxx - 1] + "}";
1165                                        _debug(resultArrStr);
1166                                        outPort.broadcast(new ArrayToken(resultArrStr));
1167                                } else {
1168                                        _debug("<ERROR> The outPort type ("
1169                                                        + outPort.getType().toString()
1170                                                        + ") and the res type(Double[]) do not match in_sendOutput(). <ERROR>");
1171                                }
1172                        } else if (res instanceof double[]) {
1173                                _debug("IN double[]");
1174                                if (outPort.getType().toString().equals("{double}")) {
1175                                        double[] resultArr = (double[]) res;
1176                                        int xxx = resultArr.length;
1177                                        String resultArrStr = "{";
1178                                        for (int resCount = 0; resCount < xxx - 1; resCount++) {
1179                                                _debug("resultArr[" + resCount + "] = "
1180                                                                + resultArr[resCount]);
1181                                                resultArrStr += resultArr[resCount] + ", ";
1182                                        }
1183                                        resultArrStr += resultArr[xxx - 1] + "}";
1184                                        _debug(resultArrStr);
1185                                        outPort.broadcast(new ArrayToken(resultArrStr));
1186                                } else {
1187                                        _debug("<ERROR> The outPort type ("
1188                                                        + outPort.getType().toString()
1189                                                        + ") and the res type(double[]) do not match in_sendOutput(). <ERROR>");
1190                                }
1191                        } else if (res instanceof Float[]) {
1192                                _debug("IN Float[]");
1193                                if (outPort.getType().toString().equals("{double}")) {
1194                                        Float[] resultArr = (Float[]) res;
1195                                        int xxx = resultArr.length;
1196                                        String resultArrStr = "{";
1197                                        for (int resCount = 0; resCount < xxx - 1; resCount++) {
1198                                                _debug("resultArr[" + resCount + "] = "
1199                                                                + resultArr[resCount]);
1200                                                resultArrStr += resultArr[resCount] + ", ";
1201                                        }
1202                                        resultArrStr += resultArr[xxx - 1] + "}";
1203                                        _debug(resultArrStr);
1204                                        outPort.broadcast(new ArrayToken(resultArrStr));
1205                                } else {
1206                                        _debug("<ERROR> The outPort type ("
1207                                                        + outPort.getType().toString()
1208                                                        + ") and the res type(Float[]) do not match in _sendOutput(). <ERROR>");
1209                                }
1210                        }
1211
1212                        else if (res instanceof float[]) {
1213                                _debug("IN float[]");
1214                                if (outPort.getType().toString().equals("{double}")) {
1215                                        float[] resultArr = (float[]) res;
1216                                        int xxx = resultArr.length;
1217                                        String resultArrStr = "{";
1218                                        for (int resCount = 0; resCount < xxx - 1; resCount++) {
1219                                                _debug("resultArr[" + resCount + "] = "
1220                                                                + resultArr[resCount]);
1221                                                resultArrStr += resultArr[resCount] + ", ";
1222                                        }
1223                                        resultArrStr += resultArr[xxx - 1] + "}";
1224                                        _debug(resultArrStr);
1225                                        outPort.broadcast(new ArrayToken(resultArrStr));
1226                                } else {
1227                                        _debug("<ERROR> The outPort type ("
1228                                                        + outPort.getType().toString()
1229                                                        + ") and the res type(float[]) do not match in _sendOutput(). <ERROR>");
1230                                }
1231                        } else if (res instanceof Boolean[]) {
1232                                _debug("IN Boolean[]");
1233                                if (outPort.getType().toString().equals("{boolean}")) {
1234                                        Boolean[] resultArr = (Boolean[]) res;
1235                                        int xxx = resultArr.length;
1236                                        String resultArrStr = "{";
1237                                        for (int resCount = 0; resCount < xxx - 1; resCount++) {
1238                                                _debug("resultArr[" + resCount + "] = "
1239                                                                + resultArr[resCount]);
1240                                                resultArrStr += resultArr[resCount] + ", ";
1241                                        }
1242                                        resultArrStr += resultArr[xxx - 1] + "}";
1243                                        _debug(resultArrStr);
1244                                        outPort.broadcast(new ArrayToken(resultArrStr));
1245                                } else {
1246                                        _debug("<ERROR> The outPort type ("
1247                                                        + outPort.getType().toString()
1248                                                        + ") and the res type(Boolean[]) do not match in _sendOutput(). <ERROR>");
1249                                }
1250                        }
1251
1252                        else if (res instanceof boolean[]) {
1253                                _debug("IN boolean[]");
1254                                if (outPort.getType().toString().equals("{boolean}")) {
1255                                        boolean[] resultArr = (boolean[]) res;
1256                                        int xxx = resultArr.length;
1257                                        String resultArrStr = "{";
1258                                        for (int resCount = 0; resCount < xxx - 1; resCount++) {
1259                                                _debug("resultArr[" + resCount + "] = "
1260                                                                + resultArr[resCount]);
1261                                                resultArrStr += resultArr[resCount] + ", ";
1262                                        }
1263                                        resultArrStr += resultArr[xxx - 1] + "}";
1264                                        _debug(resultArrStr);
1265                                        outPort.broadcast(new ArrayToken(resultArrStr));
1266                                } else {
1267                                        _debug("<ERROR> The outPort type ("
1268                                                        + outPort.getType().toString()
1269                                                        + ") and the res type(boolean[]) do not match in _sendOutput(). <ERROR>");
1270                                }
1271                        }
1272
1273                        else
1274                                outPort.broadcast(new StringToken(
1275                                                "Cannot identify the type instance of the result!"));
1276                } catch (IllegalActionException iae) {
1277                        _debug("<EXCEPTION> There was an exception in _sendOutput(): "
1278                                        + iae.toString() + ". </EXCEPTION>");
1279                        // GraphicalMessageHandler.message(
1280                        _errorsStr += "\n"
1281                                        + iae.getMessage()
1282                                        + "There was an exception when sending the outputs in actor: "
1283                                        + this.getName() + iae.toString();// );
1284                }
1285        } // end-of-sendOutput
1286
1287        /**
1288         * _setObjectArray Set the values of the arguments (_objArr) to pass to
1289         * call.
1290         * 
1291         * @param portPtr
1292         * @param index
1293         */
1294        private void _setObjectArray(TypedIOPort portPtr, int index) {
1295                try {
1296                        _debug("PORT TYPE in PTOLEMY ACTOR: "
1297                                        + portPtr.getType().toString());
1298                        if (portPtr.getType().toString().equals("int")) {
1299                                _objArr[index] = new Integer(((IntToken) (portPtr.get(0)))
1300                                                .intValue());
1301                        } else if (portPtr.getType().toString().equals("double")) {
1302                                _objArr[index] = new Double(((DoubleToken) (portPtr.get(0)))
1303                                                .doubleValue());
1304                        } else if (portPtr.getType().toString().equals("string")) {
1305                                _objArr[index] = new String(((StringToken) portPtr.get(0))
1306                                                .stringValue());
1307                        } else if (portPtr.getType().toString().equals("long")) {
1308                                _objArr[index] = new Long(((LongToken) (portPtr.get(0)))
1309                                                .longValue());
1310                        } else if (portPtr.getType().toString().equals("boolean")) {
1311                                _objArr[index] = new Boolean(((BooleanToken) (portPtr.get(0)))
1312                                                .booleanValue());
1313                        } else if (portPtr.getType().toString().equals("{int}")) {
1314                                Token[] tempTokenArr = ((ArrayToken) (portPtr.get(0)))
1315                                                .arrayValue();
1316                                int numTokens = tempTokenArr.length;
1317                                Integer[] tempStrArr = new Integer[numTokens];
1318                                for (int ind = 0; ind < numTokens; ind++)
1319                                        tempStrArr[ind] = new Integer(tempTokenArr[ind].toString());
1320                                _objArr[index] = tempStrArr;
1321                        } else if (portPtr.getType().toString().equals("{string}")) {
1322                                Token[] tempTokenArr = ((ArrayToken) (portPtr.get(0)))
1323                                                .arrayValue();
1324                                int numTokens = tempTokenArr.length;
1325                                String[] tempStrArr = new String[numTokens];
1326                                for (int ind = 0; ind < numTokens; ind++)
1327                                        tempStrArr[ind] = tempTokenArr[ind].toString();
1328                                _objArr[index] = tempStrArr;
1329                        } else if (portPtr.getType().toString().equals("{long}")) {
1330                                Token[] tempTokenArr = ((ArrayToken) (portPtr.get(0)))
1331                                                .arrayValue();
1332                                int numTokens = tempTokenArr.length;
1333                                Long[] tempStrArr = new Long[numTokens];
1334                                for (int ind = 0; ind < numTokens; ind++)
1335                                        tempStrArr[ind] = new Long(tempTokenArr[ind].toString());
1336                                _objArr[index] = tempStrArr;
1337                        } else if (portPtr.getType().toString().equals("{boolean}")) {
1338                                Token[] tempTokenArr = ((ArrayToken) (portPtr.get(0)))
1339                                                .arrayValue();
1340                                int numTokens = tempTokenArr.length;
1341                                Boolean[] tempStrArr = new Boolean[numTokens];
1342                                for (int ind = 0; ind < numTokens; ind++)
1343                                        tempStrArr[ind] = new Boolean(tempTokenArr[ind].toString());
1344                                _objArr[index] = tempStrArr;
1345                        } else if (portPtr.getType().toString().equals("{double}")) {
1346                                Token[] tempTokenArr = ((ArrayToken) (portPtr.get(0)))
1347                                                .arrayValue();
1348                                int numTokens = tempTokenArr.length;
1349                                Double[] tempStrArr = new Double[numTokens];
1350                                for (int ind = 0; ind < numTokens; ind++)
1351                                        tempStrArr[ind] = new Double(tempTokenArr[ind].toString());
1352                                _objArr[index] = tempStrArr;
1353                        } else {
1354                                _debug("Could not: specify the type of the port and set object arr.");
1355                        }
1356                } catch (Exception ex) {
1357                        _debug("<EXCEPTION> There was an exception in setObjectArray method: "
1358                                        + ex + ". </EXCEPTION>");
1359                        // GraphicalMessageHandler.message(
1360                        _errorsStr += "\n" + ex.getMessage()
1361                                        + "\nThe error occured in the actor: " + this.getName();// );
1362
1363                }
1364        } // end-of-setObjectArray
1365
1366        /**
1367         * Set the type of a port based on a string representation of that type that
1368         * was extracted from the WSDL description.
1369         * 
1370         * @param arrayTypes
1371         *            a hash of defined array types by name
1372         * @param port
1373         *            the port whose type is to be set
1374         * @param typeStr
1375         *            the string representation of the type to be set
1376         */
1377        private void _setPortType(TypedIOPort port, String typeStr) {
1378                port.setTypeEquals(BaseType.XMLTOKEN);
1379        }
1380
1381        // ////////////////////////////////////////////////////////////////////
1382        // // private variables
1383        // //
1384
1385        private Binding _binding = null;
1386        // The main service call object
1387        private org.apache.axis.client.Call _call = null;
1388        // The name of the method that this web service actor binds to
1389        // static private String _methodNameStr = "";
1390        private String _methodNameStr = "";
1391        // The input values to be sent when invoking the web service call.
1392        private Object[] _objArr;
1393        // The name of the port...
1394        private String _portName = null;
1395        private int _returnMode = 0; // 1--multiple output 2--single outputparam
1396        private Service _service = null;
1397        // The URL of the WSDL that describes the web service
1398        // static private String _urlStr = new String();
1399        private String _urlStr = new String();
1400        private String _wsName = "";
1401        // The parser for the WSDL. Will be initiated by the _urlStr.
1402        private Parser _wsdlParser = null;
1403        private String _errorsStr = "";
1404        private String _confErrorStr = "";
1405        private boolean _triggerFlag = false;
1406
1407        private String _WSEndpoint = null;
1408
1409        private String _WSMethodName = null;
1410
1411        private Document _RequestDoc = null;
1412
1413} // end of WebService