mrcode.duckprxy
Interface DuckPrxy

All Known Implementing Classes:
DuckPrxyImpl, DuckPrxyPreCompImpl, JavassistDuckPrxy

public interface DuckPrxy

An interface for a duck typing proxy creator service.

A duck proxy delegates to its delegate by using the looking for a method, using the first strategy that yields a result:

  1. Search for a method with the same name and signature.
  2. Search for a method with the same name, ignoring the signature.
  3. Looking through the defined name patterns, checking whether a method has a matching pattern definition (more on that later).
If no method yields a method, the duck proxy checks for a subdelegate (defined via DuckMethod). If such a subdelegate is found, the invocation will be forwarded to the subdelegate.

Once a method is found, the arguments are constructed to call this method. Let arg_1,...,arg_n be the arguments for the call and par_1,...,par_k the parameters of the duck delegate method. A par_i is filled with a value according to its DuckArg definition if such a definition exists. Parameter with no such definition are filled up with the arguments of the call. I.e., if k parameters par_j with j < i and par_j duck arg definition exists, that par_i is filled with arg_(i-k).

To give a more practical example: If we want to map call foo(String s, String t) to a call bar("foo", s, t), we can do this with the following definition: @DuckMethod("foo") public void bar( @DuckArg(DuckArgType.NAME) String name, String s, String t) { ...}

Author:
Christian Haselbach

Method Summary
<T> T
makeProxy(java.lang.Class<T> mainInterface, java.lang.Object delegate, java.lang.Class<?>... interfaces)
          Creates an object that implements the defined interfaces delegating to a given object, mainly using duck typing.
 

Method Detail

makeProxy

<T> T makeProxy(java.lang.Class<T> mainInterface,
                java.lang.Object delegate,
                java.lang.Class<?>... interfaces)
Creates an object that implements the defined interfaces delegating to a given object, mainly using duck typing.

Type Parameters:
T - The class of the main interface.
Parameters:
mainInterface - The main interface that the resulting object shall implement.
delegate - The object to delegate the calls to.
interfaces - Secondary interfaces to implement.
Returns:
An object implementing the main interface and secondary interfaces, delegating to the delegate object.


Copyright © 2008. All Rights Reserved.