EX03

Flexから、s2axis-examplesのEX03を呼び出してみる。

package
{
public class Book {
  private var _title: String;
  private var _author: String;
  private var _isbn: String;

  public function Book(aTitle: String, anAuthor: String, anIsbn: String) {
    _title = aTitle;
    _author = anAuthor;
    _isbn = anIsbn;
  }

  public function get title(): String {
    return _title;
  }

  public function set title(aTitle: String): void {
    _title = aTitle;
  }

  public function get author(): String {
    return _author;
  }

  public function set author(anAuthor: String): void {
    _author = anAuthor;
  }

  public function get isbn(): String {
    return _isbn;
  }

  public function set isbn(anIsbn: String): void {
    _isbn = anIsbn;
  }
}
}

非同期って面倒くさいね。もうちっと、なんとかならんものか。

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
  <mx:Button label="BookshelfTest" y="10" left="10" click="testClick()"/>

  <mx:WebService id="webService" wsdl="http://localhost:8080/s2axis-examples/services/Bookshelf?wsdl">
    <mx:operation name="getBooks" result="_nextFunction.apply(this, [event])" fault="Alert.show(event.toString())">
    </mx:operation>
    <mx:operation name="addBook" result="_nextFunction.apply(this, [event])" fault="Alert.show(event.toString())">
    </mx:operation>
    <mx:operation name="getBook" result="_nextFunction.apply(this, [event])" fault="Alert.show(event.toString())">
    </mx:operation>
  </mx:WebService>

  <mx:Script>
    <![CDATA[
      import mx.collections.ArrayCollection;
      import mx.controls.Alert;
      import mx.rpc.events.ResultEvent;
      
      private var _nextFunction: Function;

      public function testClick(): void {
        step1();
      }

      private function step1(): void {
        _nextFunction = step2;
        webService.getBooks();
      }

      private function step2(event: ResultEvent): void {
        if ((event.result as ArrayCollection).length != 0) {
          trace("assert: " + event);
        }

        _nextFunction = step3;
        webService.addBook(new Book("Building Web Services with Java",
          "Steve Graham, et al.", "ISBN0-672-32641-8"));
      }
      
      private function step3(event: ResultEvent): void {
        _nextFunction = step4;
        webService.addBook(new Book("Designing Web Services with the J2EE 1.4 Platform",
          "Inderjeet Singh, et al.", "ISBN0-321-20521-9"));
      }

      private function step4(event: ResultEvent): void {
        _nextFunction = step5;
        webService.getBook("ISBN0-672-32641-8");
      }

      private function step5(event: ResultEvent): void {
        _nextFunction = step5;
        var book: Book = new Book(event.result["title"], event.result["author"], event.result["isbn"]);

        if ("Building Web Services with Java" != book.title) {
          trace("assert: " + event);
        }
        if ("Steve Graham, et al." != book.author) {
          trace("assert: " + event);
        }
        if ("ISBN0-672-32641-8" != book.isbn) {
          trace("assert: " + event);
        }
        
        _nextFunction = step6;
        webService.getBook("ISBN0-321-20521-9");
      }

      private function step6(event: ResultEvent): void {
        var book: Book = new Book(event.result["title"], event.result["author"], event.result["isbn"]);

        if ("Designing Web Services with the J2EE 1.4 Platform" != book.title) {
          trace("assert: " + event);
        }
        if ("Inderjeet Singh, et al." != book.author) {
          trace("assert: " + event);
        }
        if ("ISBN0-321-20521-9" != book.isbn) {
          trace("assert: " + event);
        }
      }
    ]]>
  </mx:Script>
</mx:Application>
>|xml|
}