All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.codehaus.enunciate.modules.amf.as3-endpoint.fmt Maven / Gradle / Ivy

Go to download

The Enunciate AMF module generates the artifacts needed for mounting AMF endpoints.

There is a newer version: 1.31
Show newest version
[#ftl]
[#--template for the client-side endpoint interface.--]
[@file name=(simpleNameFor(endpointInterface) + ".as")  package=packageFor(endpointInterface) charset="utf-8"]
// Generated by Enunciate
package ${packageFor(endpointInterface)} {

  import flash.events.EventDispatcher;
  import mx.rpc.remoting.RemoteObject;
  import mx.rpc.events.ResultEvent;
  import mx.rpc.events.FaultEvent;
  import flash.net.registerClassAlias;
  [@forEachAS3Import declaration=endpointInterface]
  import ${as3Import};
  [/@forEachAS3Import]
  import ${packageFor(endpointInterface)}.events.${simpleNameFor(endpointInterface)}.*;

  [@forEachWebMethod endpointInterface=endpointInterface]
    [#if !webMethod.annotations["org.codehaus.enunciate.modules.amf.AMFTransient"]?exists]
      [#if webMethod.returnType.map?default(false)]
        [#if as3Aliases[amfClassnameFor(webMethod.returnType.keyType)]?exists]
  //register the type for the key type of the key-value pairs that are returned.
  registerClassAlias("${amfClassnameFor(webMethod.returnType.keyType)}", ${as3Aliases[amfClassnameFor(webMethod.returnType.keyType)]});
        [/#if]
        [#if as3Aliases[amfClassnameFor(webMethod.returnType.valueType)]?exists]
  //register the type for the value type of the key-value pairs that are returned.
  registerClassAlias("${amfClassnameFor(webMethod.returnType.valueType)}", ${as3Aliases[amfClassnameFor(webMethod.returnType.valueType)]});
        [/#if]
      [#elseif webMethod.returnType.collection || webMethod.returnType.array]
        [#if as3Aliases[amfComponentTypeFor(webMethod.returnType)]?exists]
  //register the item type of the collection that is returned.
  registerClassAlias("${amfComponentTypeFor(webMethod.returnType)}", ${as3Aliases[amfComponentTypeFor(webMethod.returnType)]});
        [/#if]
      [/#if]
    [/#if]
  [/@forEachWebMethod]

  /**
   * ${endpointInterface.docComment?default("(no documentation provided)")?chop_linebreak?replace("\n", "\n   * ")}
   */
  [@forEachWebMethod endpointInterface=endpointInterface]
    [#if !webMethod.annotations["org.codehaus.enunciate.modules.amf.AMFTransient"]?exists]
  [Event(name="${webMethod.operationName}", type="${packageFor(endpointInterface)}.events.${endpointInterface.clientSimpleName}.${webMethod.operationName?cap_first}ResultEvent")]
    [/#if]
  [/@forEachWebMethod]
  [Event(name="fault", type="mx.rpc.events.FaultEvent")]
  public class ${simpleNameFor(endpointInterface)} extends EventDispatcher {

    private var _requestTimeout:int = 0;
    [@forEachWebMethod endpointInterface=endpointInterface]
      [#if !webMethod.annotations["org.codehaus.enunciate.modules.amf.AMFTransient"]?exists]

    /**
     * ${webMethod.docComment?default("(no documentation provided)")?chop_linebreak?replace("\n", "\n     * ")}
     */
    public function ${webMethod.clientSimpleName}([#list webMethod.webParameters as param]${param.clientSimpleName}:${classnameFor(param)}[#if param_has_next], [/#if][/#list]):void {
      var ro:RemoteObject = new RemoteObject();
      ro.requestTimeout = _requestTimeout;
      ro.destination = "${endpointInterface.simpleName}";
      ro.addEventListener("result", handle${webMethod.clientSimpleName?cap_first}Result);
      ro.addEventListener("fault", handleFault);
      ro.${webMethod.clientSimpleName}([#list webMethod.webParameters as param]${param.clientSimpleName}[#if param_has_next], [/#if][/#list]);
    }

    private function handle${webMethod.clientSimpleName?cap_first}Result(event:ResultEvent):void {
      dispatchEvent(new ${webMethod.operationName?cap_first}ResultEvent([#if !webMethod.returnType.void]${classnameFor(webMethod.webResult)}(event.result)[/#if]));
    }
      [/#if]
    [/@forEachWebMethod]
    
    /**
     * The request timeout, in seconds.
     */
    public function get requestTimeout():int {
      return _requestTimeout;
    }

    /**
     * The request timeout.
     *
     * @param timeout The timeout, in seconds.
     */
    public function set requestTimeout(timeout:int):void {
      _requestTimeout = timeout;
    }

    /**
     * Delegates a fault event.
     *
     * @param event The fault event.
     */
    private function handleFault(event:FaultEvent):void {
      dispatchEvent(event);
    }
  }
}
[/@file]
[#--todo: generate the MXML remote object for Flex?--]
[@forEachWebMethod endpointInterface=endpointInterface]
  [#if !webMethod.annotations["org.codehaus.enunciate.modules.amf.AMFTransient"]?exists]
    [@file name="${webMethod.operationName?cap_first}ResultEvent.as"  package=(endpointInterface.package.qualifiedName + ".events." + endpointInterface.clientSimpleName) charset="utf-8"]
// Generated by Enunciate
package ${packageFor(endpointInterface)}.events.${simpleNameFor(endpointInterface)} {

  import flash.events.Event;
  [@forEachAS3Import declaration=webMethod includeComponentTypes=false]
  import ${as3Import};
  [/@forEachAS3Import]

  /**
   * Event triggered when a response is recieved.
   */
  public class ${webMethod.operationName?cap_first}ResultEvent extends Event {

      [#if !webMethod.returnType.void]
    private var _result:${classnameFor(webMethod.webResult)};

      [/#if]
    /**
     * Construct a result event.
     */
    public function ${webMethod.operationName?cap_first}ResultEvent([#if !webMethod.returnType.void]result:${classnameFor(webMethod.webResult)}[/#if]) {
      super("${webMethod.operationName}");
      [#if !webMethod.returnType.void]
      this._result = result;
      [/#if]
    }

      [#if !webMethod.returnType.void]
    /**
     * The result.
     */
    public function get result():${classnameFor(webMethod.webResult)} {
      return _result;
    }

      [/#if]
    override public function clone():Event {
      return new ${webMethod.operationName?cap_first}ResultEvent([#if !webMethod.returnType.void]this._result[/#if]);
    }
  }
}
    [/@file]
  [/#if]
[/@forEachWebMethod]




© 2015 - 2025 Weber Informatics LLC | Privacy Policy