1  /*
     2   * Copyright the original author or authors.
     3   * 
     4   * Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   * 
     8   *      http://www.mozilla.org/MPL/MPL-1.1.html
     9   * 
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16   
    17  import org.as2lib.core.BasicClass;
    18  import org.as2lib.env.overload.Overload;
    19  import org.as2lib.io.conn.core.event.MethodInvocationCallback;
    20  
    21  /**
    22   * {@code AbstractClientServiceProxy} offers default implementations of some methods
    23   * needed when implemnting the {@link ClientServiceProxy} interface.
    24   * 
    25   * @author Simon Wacker
    26   */
    27  class org.as2lib.io.conn.core.client.AbstractClientServiceProxy extends BasicClass {
    28  	
    29  	/**
    30  	 * Private constructor.
    31  	 */
    32  	private function AbstractClientServiceProxy(Void) {
    33  	}
    34  	
    35  	/**
    36  	 * @overload #invokeByName
    37  	 * @overload #invokeByNameAndArguments
    38  	 * @overload #invokeByNameAndCallback
    39  	 * @overload invokeByNameAndArgumentsAndCallback
    40  	 * @see ClientServiceProxy#invoke
    41  	 */
    42  	public function invoke():MethodInvocationCallback {
    43  		var o:Overload = new Overload(this);
    44  		o.addHandler([String], invokeByName);
    45  		o.addHandler([String, Array], invokeByNameAndArguments);
    46  		o.addHandler([String, MethodInvocationCallback], invokeByNameAndCallback);
    47  		o.addHandler([String, Array, MethodInvocationCallback], this["invokeByNameAndArgumentsAndCallback"]);
    48  		return o.forward(arguments);
    49  	}
    50  	
    51  	/**
    52  	 * Invokes the method with passed-in {@code methodName} on the service.
    53  	 * 
    54  	 * <p>The invocation is done by forwardning to the {@code #invokeByNameAndArgumentsAndCallback}
    55  	 * method passing an empty arguments array.
    56  	 *
    57  	 * @param methodName the name of the method to invoke
    58  	 * @return a callback that can be used to get informed of the response
    59  	 * @see ClientServiceProxy#invokeByName
    60  	 */
    61  	public function invokeByName(methodName:String):MethodInvocationCallback {
    62  		return this["invokeByNameAndArgumentsAndCallback"](methodName, [], null);
    63  	}
    64  	
    65  	/**
    66  	 * Invokes the method with passed-in {@code methodName} and {@code args} on the
    67  	 * service.
    68  	 * 
    69  	 * <p>The response of the method invocation is delegated to the appropriate method
    70  	 * on the returned callback. This is either the {@code onReturn} method when no
    71  	 * error occured. Or the {@code onError} method in case something went wrong.
    72  	 *
    73  	 * <p>The invocation is done by forwardning to the {@code #invokeByNameAndArgumentsAndCallback}
    74  	 * method passing an empty arguments array.
    75  	 *
    76  	 * @param methodName the name of the method to invoke on the service
    77  	 * @param args the arguments that are passed to the method as parameters
    78  	 * @return the callback that handles the response
    79  	 * @see ClientServiceProxy#invokeByNameAndArguments
    80  	 */
    81  	public function invokeByNameAndArguments(methodName:String, args:Array):MethodInvocationCallback {
    82  		return this["invokeByNameAndArgumentsAndCallback"](methodName, args, null);
    83  	}
    84  	
    85  	/**
    86  	 * Invokes the the method with passed-in {@code method} on the service.
    87  	 *
    88  	 * <p>When the response arrives the appropriate callback method is invoked.
    89  	 * 
    90  	 * <p>If the passed-in {@code callback} is not {@code null}, the returned callback
    91  	 * is the same instance.
    92  	 *
    93  	 * <p>The invocation is done by forwardning to the {@code #invokeByNameAndArgumentsAndCallback}
    94  	 * method passing an empty arguments array.
    95  	 * 
    96  	 * @param methodName the name of the method to invoke
    97  	 * @param callback the callback that receives the return value or errors
    98  	 * @return a callback that can be used to get informed of the response
    99  	 * @see ClientServiceProxy#invokeByNameAndCallback
   100  	 */
   101  	public function invokeByNameAndCallback(methodName:String, callback:MethodInvocationCallback):MethodInvocationCallback {
   102  		return this["invokeByNameAndArgumentsAndCallback"](methodName, [], callback);
   103  	}
   104  	
   105  }