001/* 002 * Copyright (c) 2000-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.util.HashMap; 033import java.util.Iterator; 034import java.util.List; 035import java.util.Map; 036import java.util.Vector; 037 038import javax.wsdl.Binding; 039import javax.wsdl.Operation; 040import javax.wsdl.Port; 041import javax.wsdl.Service; 042import javax.wsdl.extensions.soap.SOAPAddress; 043import javax.xml.namespace.QName; 044import javax.xml.rpc.Call; 045import javax.xml.rpc.ServiceException; 046 047import org.apache.axis.wsdl.gen.Parser; 048import org.apache.axis.wsdl.symbolTable.BindingEntry; 049import org.apache.axis.wsdl.symbolTable.Parameters; 050import org.apache.axis.wsdl.symbolTable.ServiceEntry; 051import org.apache.axis.wsdl.symbolTable.SymTabEntry; 052import org.apache.axis.wsdl.symbolTable.SymbolTable; 053 054import ptolemy.actor.CompositeActor; 055import ptolemy.actor.IOPort; 056import ptolemy.actor.Manager; 057import ptolemy.actor.TypedAtomicActor; 058import ptolemy.actor.TypedIOPort; 059import ptolemy.data.ArrayToken; 060import ptolemy.data.BooleanToken; 061import ptolemy.data.DoubleToken; 062import ptolemy.data.IntToken; 063import ptolemy.data.LongToken; 064import ptolemy.data.StringToken; 065import ptolemy.data.Token; 066import ptolemy.data.expr.Parameter; 067import ptolemy.data.expr.StringParameter; 068import ptolemy.data.type.BaseType; 069import ptolemy.gui.GraphicalMessageHandler; 070import ptolemy.kernel.CompositeEntity; 071import ptolemy.kernel.util.Attribute; 072import ptolemy.kernel.util.IllegalActionException; 073import ptolemy.kernel.util.NameDuplicationException; 074import ptolemy.kernel.util.Nameable; 075 076////////////////////////////////////////////////////////////////////////// 077//// WebServiceStub 078/** 079 * This is a stub actor that executes a web service, given a wsdl url and 080 * operation name. This actor will act as the java stub for the specific 081 * operation of a web service. 082 * 083 * @author Ilkay Altintas 084 * @version $Id: WebServiceStub.java 30702 2012-09-18 18:40:51Z crawl $ 085 * @category.name web service 086 * @category.name distributed 087 * @category.name remote 088 * @deprecated Use org.sdm.spa.WebService or org.sdm.spa.WSWithComplexTypes instead 089 */ 090 091public class WebServiceStub extends TypedAtomicActor { 092 093 /** 094 * Construct a WebServiceStub actor with the given container and name. 095 * 096 * @param container 097 * The container. 098 * @param name 099 * The name of this actor. 100 * @exception IllegalActionException 101 * If the actor cannot be contained by the proposed 102 * container. 103 * @exception NameDuplicationException 104 * If the container already has an actor with this name. 105 */ 106 public WebServiceStub(CompositeEntity container, String name) 107 throws NameDuplicationException, IllegalActionException { 108 109 super(container, name); 110 111 wsdlUrl = new StringParameter(this, "wsdlUrl"); 112 methodName = new StringParameter(this, "methodName"); 113 userName = new StringParameter(this, "userName"); 114 password = new StringParameter(this, "password"); 115 116 startTrigger = new TypedIOPort(this, "startTrigger", true, false); 117 new Attribute(startTrigger, "_showName"); 118 startTrigger.setContainer(null); 119 // Set the trigger Flag. 120 hasTrigger = new Parameter(this, "hasTrigger", new BooleanToken(false)); 121 hasTrigger.setTypeEquals(BaseType.BOOLEAN); 122 123 _attachText("_iconDescription", "<svg>\n" + "<rect x=\"0\" y=\"0\" " 124 + "width=\"60\" height=\"30\" " + "style=\"fill:white\"/>\n" 125 + "</svg>\n"); 126 } // end-of-constructor 127 128 // ///////////////////////////////////////////////////////////////// 129 // // ports and parameters //// 130 131 // The parameter for the URL of the web service WSDL. 132 public StringParameter wsdlUrl; 133 // The parameter for the method name. 134 // FIX ME: I want to make the methodName parameter style as "choice style". 135 // The choices will be automatically updated when the wsdl changes. 136 // Right now it works but doesn't load them until you open and close the 137 // parameter configuration interface. 138 public StringParameter methodName; 139 // The userName and password to invoke the web service if necessary. 140 public StringParameter userName; 141 public StringParameter password; 142 143 public Parameter hasTrigger; 144 public TypedIOPort startTrigger; 145 146 // ///////////////////////////////////////////////////////////////// 147 // // public methods //// 148 149 /** 150 * Callback for changes in attribute values. This one is just used for the 151 * trigger port. 152 * 153 * @param a 154 * The attribute that changed. 155 * @exception IllegalActionException 156 */ 157 public void attributeChanged(Attribute at) throws IllegalActionException { 158 if (at == hasTrigger) { 159 _triggerFlag = ((BooleanToken) hasTrigger.getToken()) 160 .booleanValue(); 161 _debug("<TRIGGER_FLAG>" + _triggerFlag + "</TRIGGER_FLAG>"); 162 if (_triggerFlag) { 163 try { 164 startTrigger.setContainer(this); 165 } catch (NameDuplicationException ndex) { 166 _debug("111: " + ndex.getMessage()); 167 GraphicalMessageHandler.message(ndex.getMessage() 168 + "Could not create the trigger port in actor:" 169 + this.getName()); 170 } 171 } else { 172 List inPortList = this.inputPortList(); 173 Iterator ports = inPortList.iterator(); 174 while (ports.hasNext()) { 175 IOPort p = (IOPort) ports.next(); 176 if (p.isInput()) { 177 try { 178 if (p.getName().equals("startTrigger")) { 179 p.setContainer(null); 180 } 181 } catch (Exception e) { 182 GraphicalMessageHandler 183 .message(e.getMessage() 184 + "Could not delete the trigger port in the actor: " 185 + this.getName()); 186 } 187 } 188 } 189 } 190 } 191 } // end-of-attributeChanged 192 193 /** 194 * Given a WebServiceStub, outputs if that actor is same with the current 195 * one. 196 * 197 * @exception IllegalActionException 198 * If there is no director. 199 */ 200 public boolean equals(Object obj) { 201 if (!(obj instanceof WebServiceStub)) 202 return false; 203 try { 204 WebServiceStub in = (WebServiceStub) obj; 205 if ((this.wsdlUrl.stringValue().equals(in.wsdlUrl.stringValue())) 206 && (this.methodName.stringValue().equals(in.methodName 207 .stringValue()))) { 208 return true; 209 } 210 } catch (Exception ex) { 211 // Do nothing. It will go out if this. 212 // PRINT THIS LATER. 213 } 214 215 // System.out.println("IN OBJ WSDLURL: " + in.wsdlUrl.stringValue()); 216 // System.out.println("THIS WSDLURL: " + this.wsdlUrl.stringValue()); 217 218 // System.out.println("IN OBJ METHODNAME: " + 219 // in.methodName.stringValue()); 220 // System.out.println("THIS METHODNAME: " + 221 // this.methodName.stringValue()); 222 return false; 223 } 224 225 /** 226 * Get the URL address of the the location of the web service defined by the 227 * given WSDL. Get the the namespace and binding information of the web 228 * service using the given WSDL and methodName. Add a parameter to the call 229 * object for each input part.Fill these parameters with the input values on 230 * channels on the ports that correspond to them. Invoke the web service 231 * using all the gathered information. Send the response of the call to the 232 * result port. 233 * 234 * @exception IllegalActionException 235 * If there is no director. 236 */ 237 public void fire() throws IllegalActionException { 238 super.fire(); 239 _urlStr = wsdlUrl.getExpression(); 240 _methodNameStr = methodName.getExpression(); 241 try { 242 _wsdlParser.run(_urlStr); 243 } catch (Exception ex) { 244 _debug("<EXCEPTION> There was an error while parsing the WSDL in fire. " 245 + ex + ". </EXCEPTION>"); 246 GraphicalMessageHandler 247 .message(ex.getMessage() 248 + "Error in fire: There was an error while parsing the WSDL in the actor: " 249 + this.getName()); 250 } 251 getServiceBinding(); 252 try { 253 SymbolTable symbolTable = _wsdlParser.getSymbolTable(); 254 BindingEntry bEntry = symbolTable.getBindingEntry(_binding 255 .getQName()); 256 Operation operation = null; 257 Parameters parameters = null; 258 Iterator iter = bEntry.getParameters().keySet().iterator(); 259 for (; iter.hasNext();) { 260 Operation oper = (Operation) iter.next(); 261 if (oper.getName().equals(_methodNameStr)) { 262 operation = oper; 263 parameters = (Parameters) bEntry.getParameters().get(oper); 264 // Set output type 265 if (parameters.returnParam == null) { 266 _returnMode = 1; // Get outputs into a map object! 267 } else if (parameters.returnParam != null) { 268 _returnMode = 2; // Get the invoke result value as a 269 // single value. 270 } 271 // Break out of the loop 272 break; 273 } 274 } 275 } catch (Exception ex) { 276 _debug("<EXCEPTION>In fire when setting the return mode: " + ex 277 + ". </EXCEPTION>"); 278 GraphicalMessageHandler 279 .message(ex.getMessage() 280 + "There was an error when setting up the return mode of the web " 281 + "service at: " + this.getName()); 282 } 283 284 try { 285 org.apache.axis.client.Service myServiceClient = new org.apache.axis.client.Service( 286 _wsdlParser, _service.getQName()); 287 _debug("Method name in fire: " + _methodNameStr); 288 _call = myServiceClient.createCall(QName.valueOf(_portName), QName 289 .valueOf(_methodNameStr)); 290 _debug(_call.getClass().getName() + "Call implementation"); 291 292 ((org.apache.axis.client.Call) _call) 293 .setTimeout(new Integer(600000)); 294 295 // Add a parameter to the call object for each input part. 296 List inPortList = this.inputPortList(); 297 int numInPorts = inPortList.size(); 298 if (_triggerFlag) { 299 _objArr = new Object[numInPorts - 1]; 300 } else { 301 _objArr = new Object[numInPorts]; 302 } 303 Iterator ports = inPortList.iterator(); 304 int i = 0; 305 while (ports.hasNext()) { 306 // Fill these parameters with the input values on channels on 307 // the 308 // ports that correspond to them. 309 TypedIOPort p = (TypedIOPort) ports.next(); 310 _debug("<INPUT_PORT>" + p.getName() + "</INPUT_PORT>"); 311 if (p.getName().equals("startTrigger")) { 312 _debug("Skipped the value of the trigger port in fire."); 313 } else if (p.hasToken(0)) { 314 _setObjectArray(p, i); 315 i++; 316 } 317 } 318 for (int j = 0; j < i; j++) { 319 _debug("_objArr[" + j + "]=" + _objArr[j]); 320 } 321 322 _debug("<USERNAME> " + userName.stringValue() + " </USERNAME>"); 323 _call.setProperty(Call.USERNAME_PROPERTY, userName.stringValue()); 324 _debug("<PASSWORD> " + password.stringValue() + " </PASSWORD>"); 325 _call.setProperty(Call.PASSWORD_PROPERTY, password.stringValue()); 326 327 _debug("Starting the invoke!"); 328 // Element invokeResult = (Element) call.invoke(objArr); 329 Object invokeResult = _call.invoke(_objArr); 330 _debug("Got results from the invoke..."); 331 List outPortList = this.outputPortList(); 332 Iterator oports = outPortList.iterator(); 333 _debug("<RETURN_MODE> " + new Integer(_returnMode).toString() 334 + " </RETURN_MODE>"); 335 if (_returnMode == 2) { 336 TypedIOPort po = (TypedIOPort) oports.next(); 337 _sendOutput(po, invokeResult); 338 } else if (_returnMode == 1) { 339 Map outParams = _call.getOutputParams(); 340 while (oports.hasNext()) { 341 // Fill these parameters with the input values on 342 // channels on the ports that correspond to them. 343 TypedIOPort po = (TypedIOPort) oports.next(); 344 _debug("<OUTPUT_PORT>" + po.getName() + ", " 345 + po.getType().toString() + "</OUTPUT_PORT>"); 346 try { 347 _sendOutput(po, outParams.get(new QName("", po 348 .getName()))); 349 } catch (Exception ex) { 350 _debug("<EXCEPTION> There was an exception when sending the outputs." 351 + " OutValue: " 352 + (String) org.apache.axis.utils.JavaUtils 353 .convert(outParams.get(new QName("", po 354 .getName())), 355 java.lang.String.class) 356 + ". </EXCEPTION>"); 357 GraphicalMessageHandler 358 .message(ex.getMessage() 359 + "\nThe error occured in the actor: " 360 + this.getName() 361 + "\n Please look at the debugging details for this actor for " 362 + "more information."); 363 } 364 } 365 } 366 } catch (ServiceException se) { 367 _debug("<EXCEPTION> Service exception in fire() method: " 368 + se.getMessage() + ". </EXCEPTION>"); 369 GraphicalMessageHandler.message(se.getMessage() 370 + "\nThe service exception error occured in the actor: " 371 + this.getName()); 372 } catch (java.rmi.RemoteException rex) { 373 _debug("<EXCEPTION> Remote exception in fire() method: " 374 + rex.getMessage() + ". </EXCEPTION>"); 375 // get rmi.getCause() and print it here. 376 GraphicalMessageHandler.message(rex.getMessage() 377 + "\nThe remote exception error occured in the actor: " 378 + this.getName()); 379 380 // FIX ME: Don't stop the model here but pause and let the user 381 // refine it! 382 /* 383 * // NOTE: We need to consume data on all channels that have data. 384 * // If we don't then DE will go into an infinite loop. for (int i 385 * = 0; i < input.getWidth(); i++) { if (input.hasToken(i)) { if 386 * (((BooleanToken)input.get(i)).booleanValue()) { result = true; } 387 * } } 388 */ 389 Nameable container = getContainer(); 390 if (container instanceof CompositeActor) { 391 Manager manager = ((CompositeActor) container).getManager(); 392 if (manager != null) { 393 manager.finish(); 394 } else { 395 throw new IllegalActionException(this, 396 "Cannot stop without a Manager."); 397 } 398 } else { 399 throw new IllegalActionException(this, 400 "Cannot stop without a container that is a CompositeActor."); 401 } 402 } 403 } // end of fire 404 405 /** Configure the service, port and binding info. */ 406 public void getServiceBinding() { 407 try { 408 _service = null; 409 410 // Find the entry for the ServiceEntry class in the symbol table. 411 HashMap map = _wsdlParser.getSymbolTable().getHashMap(); 412 Iterator entrySetIter = map.entrySet().iterator(); 413 while (entrySetIter.hasNext()) { 414 Map.Entry currentEntry = (Map.Entry) entrySetIter.next(); 415 Vector valueVector = (Vector) currentEntry.getValue(); 416 int vecSize = valueVector.size(); 417 for (int index = 0; index < vecSize; ++index) { 418 SymTabEntry symTabEntryObj = (SymTabEntry) valueVector 419 .get(index); 420 if ((ServiceEntry.class).isInstance(symTabEntryObj)) { 421 _service = ((ServiceEntry) symTabEntryObj).getService(); 422 } 423 } 424 } 425 426 Port port = _getSOAPAddress(_service.getPorts()); 427 if (port == null) { 428 _debug("<ERROR> No port was returned by the _getSOAPAddress. </ERROR>"); 429 } 430 _portName = ""; 431 _portName = port.getName(); 432 _binding = port.getBinding(); 433 } catch (Exception ex) { 434 _debug("<EXCEPTION> There was an error when configuring the actor: " 435 + ex + ". </EXCEPTION>"); 436 GraphicalMessageHandler.message(ex.getMessage() 437 + "There was an error when configuring the actor:" 438 + this.getName()); 439 } 440 } // end-of-getServiceBinding 441 442 // //////////////////////////////////////////////////////////////////// 443 // //////////// private methods //////////////// 444 445 /** 446 * Returns a port with a SOAPAddress extensibility element. 447 */ 448 private Port _getSOAPAddress(Map ports) { 449 Iterator nameIter = ports.keySet().iterator(); 450 while (nameIter.hasNext()) { 451 String portName = (String) nameIter.next(); 452 Port port = (Port) ports.get(portName); 453 List extElemList = port.getExtensibilityElements(); 454 for (int i = 0; (extElemList != null) && (i < extElemList.size()); i++) { 455 Object extEl = extElemList.get(i); 456 if (extEl instanceof SOAPAddress) { 457 return port; 458 } 459 } 460 } 461 return null; 462 } // end-of-getSOAPAddress 463 464 /** 465 * _sendOutput Send the output ports from the given port with the right type 466 * casting. 467 * 468 * @param outPort 469 * @param res 470 */ 471 private void _sendOutput(TypedIOPort outPort, Object res) { 472 _debug("<RES_CLASS_NAME>" + res.getClass().getName() 473 + "</RES_CLASS_NAME>"); 474 try { 475 if (res instanceof String) { 476 if (outPort.getType().toString().equals("string")) { 477 outPort.broadcast(new StringToken((String) res)); 478 } else { 479 _debug("<ERROR> The outPort type (" 480 + outPort.getType().toString() 481 + ") and the res type(String) do not match in _sendOutput(). <ERROR>"); 482 } 483 } else if (res instanceof Integer) { 484 if (outPort.getType().toString().equals("int")) { 485 outPort.broadcast(new IntToken(((Integer) res).intValue())); 486 } else { 487 _debug("<ERROR> The outPort type (" 488 + outPort.getType().toString() 489 + ") and the res type(Integer) do not match in _sendOutput(). <ERROR>"); 490 } 491 } else if (res instanceof Double) { 492 if (outPort.getType().toString().equals("double")) { 493 outPort.broadcast(new DoubleToken(((Double) res) 494 .doubleValue())); 495 } else { 496 _debug("<ERROR> The outPort type (" 497 + outPort.getType().toString() 498 + ") and the res type(Double) do not match in _sendOutput(). <ERROR>"); 499 } 500 } else if (res instanceof Long) { 501 if (outPort.getType().toString().equals("long")) { 502 outPort.broadcast(new LongToken(((Long) res).longValue())); 503 } else { 504 _debug("<ERROR> The outPort type (" 505 + outPort.getType().toString() 506 + ") and the res type(Long) do not match in _sendOutput(). <ERROR>"); 507 } 508 } else if (res instanceof Boolean) { 509 if (outPort.getType().toString().equals("boolean")) { 510 outPort.broadcast(new BooleanToken(((Boolean) res) 511 .booleanValue())); 512 } else { 513 _debug("<ERROR> The outPort type (" 514 + outPort.getType().toString() 515 + ") and the res type(Boolean) do not match in _sendOutput(). <ERROR>"); 516 } 517 } else if (res instanceof String[]) { 518 if (outPort.getType().toString().equals("{string}")) { 519 String[] resultArr = (String[]) res; 520 int xxx = resultArr.length; 521 String resultArrStr = "{"; 522 for (int resCount = 0; resCount < xxx - 1; resCount++) { 523 _debug("resultArr[" + resCount + "] = " 524 + resultArr[resCount]); 525 resultArrStr += resultArr[resCount] + ", "; 526 } 527 resultArrStr += resultArr[xxx - 1] + "}"; 528 outPort.broadcast(new ArrayToken(resultArrStr)); 529 } else { 530 _debug("<ERROR> The outPort type (" 531 + outPort.getType().toString() 532 + ") and the res type(String[]) do not match in _sendOutput(). <ERROR>"); 533 } 534 } else if ((res instanceof Integer[])) { 535 _debug("IN Integer[]"); 536 if (outPort.getType().toString().equals("{int}")) { 537 Integer[] resultArr = (Integer[]) res; 538 int xxx = resultArr.length; 539 String resultArrStr = "{"; 540 for (int resCount = 0; resCount < xxx - 1; resCount++) { 541 _debug("resultArr[" + resCount + "] = " 542 + resultArr[resCount]); 543 resultArrStr += resultArr[resCount] + ", "; 544 } 545 resultArrStr += resultArr[xxx - 1] + "}"; 546 outPort.broadcast(new ArrayToken(resultArrStr)); 547 } else { 548 _debug("<ERROR> The outPort type (" 549 + outPort.getType().toString() 550 + ") and the res type(String[]) do not match in _sendOutput(). <ERROR>"); 551 } 552 } else if (res instanceof int[]) { 553 _debug("IN int[]"); 554 if (outPort.getType().toString().equals("{int}")) { 555 int[] resultArr = (int[]) res; 556 int xxx = resultArr.length; 557 String resultArrStr = "{"; 558 for (int resCount = 0; resCount < xxx - 1; resCount++) { 559 _debug("resultArr[" + resCount + "] = " 560 + resultArr[resCount]); 561 resultArrStr += resultArr[resCount] + ", "; 562 } 563 resultArrStr += resultArr[xxx - 1] + "}"; 564 _debug(resultArrStr); 565 outPort.broadcast(new ArrayToken(resultArrStr)); 566 } else { 567 _debug("<ERROR> The outPort type (" 568 + outPort.getType().toString() 569 + ") and the res type(String[]) do not match in _sendOutput(). <ERROR>"); 570 } 571 } else if (res instanceof Double[]) { 572 _debug("IN Double[]"); 573 if (outPort.getType().toString().equals("{double}")) { 574 Double[] resultArr = (Double[]) res; 575 int xxx = resultArr.length; 576 String resultArrStr = "{"; 577 for (int resCount = 0; resCount < xxx - 1; resCount++) { 578 _debug("resultArr[" + resCount + "] = " 579 + resultArr[resCount]); 580 resultArrStr += resultArr[resCount] + ", "; 581 } 582 resultArrStr += resultArr[xxx - 1] + "}"; 583 _debug(resultArrStr); 584 outPort.broadcast(new ArrayToken(resultArrStr)); 585 } else { 586 _debug("<ERROR> The outPort type (" 587 + outPort.getType().toString() 588 + ") and the res type(Double[]) do not match in _sendOutput(). <ERROR>"); 589 } 590 } else if (res instanceof double[]) { 591 _debug("IN double[]"); 592 if (outPort.getType().toString().equals("{double}")) { 593 double[] resultArr = (double[]) res; 594 int xxx = resultArr.length; 595 String resultArrStr = "{"; 596 for (int resCount = 0; resCount < xxx - 1; resCount++) { 597 _debug("resultArr[" + resCount + "] = " 598 + resultArr[resCount]); 599 resultArrStr += resultArr[resCount] + ", "; 600 } 601 resultArrStr += resultArr[xxx - 1] + "}"; 602 _debug(resultArrStr); 603 outPort.broadcast(new ArrayToken(resultArrStr)); 604 } else { 605 _debug("<ERROR> The outPort type (" 606 + outPort.getType().toString() 607 + ") and the res type(double[]) do not match in _sendOutput(). <ERROR>"); 608 } 609 } else if (res instanceof Float[]) { 610 _debug("IN Float[]"); 611 if (outPort.getType().toString().equals("{double}")) { 612 Float[] resultArr = (Float[]) res; 613 int xxx = resultArr.length; 614 String resultArrStr = "{"; 615 for (int resCount = 0; resCount < xxx - 1; resCount++) { 616 _debug("resultArr[" + resCount + "] = " 617 + resultArr[resCount]); 618 resultArrStr += resultArr[resCount] + ", "; 619 } 620 resultArrStr += resultArr[xxx - 1] + "}"; 621 _debug(resultArrStr); 622 outPort.broadcast(new ArrayToken(resultArrStr)); 623 } else { 624 _debug("<ERROR> The outPort type (" 625 + outPort.getType().toString() 626 + ") and the res type(Float[]) do not match in _sendOutput(). <ERROR>"); 627 } 628 } 629 630 else if (res instanceof float[]) { 631 _debug("IN float[]"); 632 if (outPort.getType().toString().equals("{double}")) { 633 float[] resultArr = (float[]) res; 634 int xxx = resultArr.length; 635 String resultArrStr = "{"; 636 for (int resCount = 0; resCount < xxx - 1; resCount++) { 637 _debug("resultArr[" + resCount + "] = " 638 + resultArr[resCount]); 639 resultArrStr += resultArr[resCount] + ", "; 640 } 641 resultArrStr += resultArr[xxx - 1] + "}"; 642 _debug(resultArrStr); 643 outPort.broadcast(new ArrayToken(resultArrStr)); 644 } else { 645 _debug("<ERROR> The outPort type (" 646 + outPort.getType().toString() 647 + ") and the res type(float[]) do not match in _sendOutput(). <ERROR>"); 648 } 649 } else if (res instanceof Boolean[]) { 650 _debug("IN Boolean[]"); 651 if (outPort.getType().toString().equals("{boolean}")) { 652 Boolean[] resultArr = (Boolean[]) res; 653 int xxx = resultArr.length; 654 String resultArrStr = "{"; 655 for (int resCount = 0; resCount < xxx - 1; resCount++) { 656 _debug("resultArr[" + resCount + "] = " 657 + resultArr[resCount]); 658 resultArrStr += resultArr[resCount] + ", "; 659 } 660 resultArrStr += resultArr[xxx - 1] + "}"; 661 _debug(resultArrStr); 662 outPort.broadcast(new ArrayToken(resultArrStr)); 663 } else { 664 _debug("<ERROR> The outPort type (" 665 + outPort.getType().toString() 666 + ") and the res type(Boolean[]) do not match in _sendOutput(). <ERROR>"); 667 } 668 } 669 670 else if (res instanceof boolean[]) { 671 _debug("IN boolean[]"); 672 if (outPort.getType().toString().equals("{boolean}")) { 673 boolean[] resultArr = (boolean[]) res; 674 int xxx = resultArr.length; 675 String resultArrStr = "{"; 676 for (int resCount = 0; resCount < xxx - 1; resCount++) { 677 _debug("resultArr[" + resCount + "] = " 678 + resultArr[resCount]); 679 resultArrStr += resultArr[resCount] + ", "; 680 } 681 resultArrStr += resultArr[xxx - 1] + "}"; 682 _debug(resultArrStr); 683 outPort.broadcast(new ArrayToken(resultArrStr)); 684 } else { 685 _debug("<ERROR> The outPort type (" 686 + outPort.getType().toString() 687 + ") and the res type(boolean[]) do not match in _sendOutput(). <ERROR>"); 688 } 689 } 690 691 else 692 outPort.broadcast(new StringToken( 693 "Cannot identify the type instance of the result!")); 694 } catch (IllegalActionException iae) { 695 _debug("<EXCEPTION> There was an exception in _sendOutput(): " 696 + iae.toString() + ". </EXCEPTION>"); 697 GraphicalMessageHandler 698 .message(iae.getMessage() 699 + "There was an exception when sending the outputs in actor: " 700 + this.getName() + iae.toString()); 701 } 702 } // end-of-sendOutput 703 704 /** 705 * _setObjectArray Set the values of the arguments (_objArr) to pass to 706 * call. 707 * 708 * @param portPtr 709 * @param index 710 */ 711 private void _setObjectArray(TypedIOPort portPtr, int index) { 712 try { 713 _debug("PORT TYPE in PTOLEMY ACTOR: " 714 + portPtr.getType().toString()); 715 if (portPtr.getType().toString().equals("int")) { 716 _objArr[index] = new Integer(((IntToken) (portPtr.get(0))) 717 .intValue()); 718 } else if (portPtr.getType().toString().equals("double")) { 719 _objArr[index] = new Double(((DoubleToken) (portPtr.get(0))) 720 .doubleValue()); 721 } else if (portPtr.getType().toString().equals("string")) { 722 _objArr[index] = new String(((StringToken) portPtr.get(0)) 723 .stringValue()); 724 } else if (portPtr.getType().toString().equals("long")) { 725 _objArr[index] = new Long(((LongToken) (portPtr.get(0))) 726 .longValue()); 727 } else if (portPtr.getType().toString().equals("boolean")) { 728 _objArr[index] = new Boolean(((BooleanToken) (portPtr.get(0))) 729 .booleanValue()); 730 } else if (portPtr.getType().toString().equals("{int}")) { 731 Token[] tempTokenArr = ((ArrayToken) (portPtr.get(0))) 732 .arrayValue(); 733 int numTokens = tempTokenArr.length; 734 Integer[] tempStrArr = new Integer[numTokens]; 735 for (int ind = 0; ind < numTokens; ind++) 736 tempStrArr[ind] = new Integer(tempTokenArr[ind].toString()); 737 _objArr[index] = tempStrArr; 738 } else if (portPtr.getType().toString().equals("{string}")) { 739 Token[] tempTokenArr = ((ArrayToken) (portPtr.get(0))) 740 .arrayValue(); 741 int numTokens = tempTokenArr.length; 742 String[] tempStrArr = new String[numTokens]; 743 for (int ind = 0; ind < numTokens; ind++) 744 tempStrArr[ind] = tempTokenArr[ind].toString(); 745 _objArr[index] = tempStrArr; 746 } else if (portPtr.getType().toString().equals("{long}")) { 747 Token[] tempTokenArr = ((ArrayToken) (portPtr.get(0))) 748 .arrayValue(); 749 int numTokens = tempTokenArr.length; 750 Long[] tempStrArr = new Long[numTokens]; 751 for (int ind = 0; ind < numTokens; ind++) 752 tempStrArr[ind] = new Long(tempTokenArr[ind].toString()); 753 _objArr[index] = tempStrArr; 754 } else if (portPtr.getType().toString().equals("{boolean}")) { 755 Token[] tempTokenArr = ((ArrayToken) (portPtr.get(0))) 756 .arrayValue(); 757 int numTokens = tempTokenArr.length; 758 Boolean[] tempStrArr = new Boolean[numTokens]; 759 for (int ind = 0; ind < numTokens; ind++) 760 tempStrArr[ind] = new Boolean(tempTokenArr[ind].toString()); 761 _objArr[index] = tempStrArr; 762 } else if (portPtr.getType().toString().equals("{double}")) { 763 Token[] tempTokenArr = ((ArrayToken) (portPtr.get(0))) 764 .arrayValue(); 765 int numTokens = tempTokenArr.length; 766 Double[] tempStrArr = new Double[numTokens]; 767 for (int ind = 0; ind < numTokens; ind++) 768 tempStrArr[ind] = new Double(tempTokenArr[ind].toString()); 769 _objArr[index] = tempStrArr; 770 } else { 771 _debug("Could not: specify the type of the port and set object arr."); 772 } 773 } catch (Exception ex) { 774 _debug("<EXCEPTION> There was an exception in setObjectArray method: " 775 + ex + ". </EXCEPTION>"); 776 GraphicalMessageHandler.message(ex.getMessage() 777 + "\nThe error occured in the actor: " + this.getName()); 778 779 } 780 } // end-of-setObjectArray 781 782 // //////////////////////////////////////////////////////////////////// 783 // // private variables //// 784 785 private Binding _binding = null; 786 // The main service call object 787 private Call _call = null; 788 // The name of the method that this web service actor binds to 789 private String _methodNameStr = ""; 790 // The input values to be sent when invoking the web service call. 791 private Object[] _objArr; 792 // The name of the port... 793 private String _portName = null; 794 private int _returnMode = 0; // 1--multiple output 2--single output param 795 private Service _service = null; 796 // The URL of the WSDL that describes the web service 797 private String _urlStr = ""; 798 private String _wsName = ""; 799 // The parser for the WSDL. Will be initiated by the _urlStr. 800 private Parser _wsdlParser = new Parser(); 801 802 private boolean _triggerFlag = false; 803 804} // end of WebServiceStub