biz.hammurapi.convert
Class Mixer

java.lang.Object
  extended by biz.hammurapi.convert.Mixer

public class Mixer
extends java.lang.Object

Mixes interfaces from multiple objects into one proxy.

Author:
Pavel

Constructor Summary
Mixer()
           
 
Method Summary
static java.lang.Object addInterceptors(java.lang.Object master, java.lang.Object[] interceptors)
          Creates a proxy which routes invocations to master unless one of interceptors has a method with matching signature.
static java.lang.Object combine(java.lang.Object[] objects, java.lang.Class[] interfaces)
          Creates a proxy which implements given interfaces and routes invocations to appropriate object.
static java.lang.Object mix(java.lang.Object[] objects)
          Mixes interfaces from multiple objects into one proxy.
static java.lang.Object mixIn(java.lang.Object object, java.lang.Class[] interfaces)
          Mixes-in implementation of interfaces into class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Mixer

public Mixer()
Method Detail

mixIn

public static java.lang.Object mixIn(java.lang.Object object,
                                     java.lang.Class[] interfaces)
Mixes-in implementation of interfaces into class. I.e. it creates a proxy which implements all classe's interfaces plus interfaces from parameters. E.g. class has methods compatible with interfaces, but doesn't implement the interface itself. This is very similar to duck typing. This method doesn't check for method compatibility, it simply routes interface methods to the object. It is useful when only a sub-set of interface methods is used by the calling code, so the code would work even if strict conversion failed.

Parameters:
object -
interfaces -
Returns:

addInterceptors

public static java.lang.Object addInterceptors(java.lang.Object master,
                                               java.lang.Object[] interceptors)
Creates a proxy which routes invocations to master unless one of interceptors has a method with matching signature. Only interface methods are routed to interceptors. Traditional approach to intercepting in Java is to create filters/wrappers. This approach might be problematic if the filter master instances might be of different subclasses of the base filtered type and if the subclassed functionality must be propagated through the filter. Returned proxy invokes only interceptor's method. It is responsiblity of the interceptor to call master's method if needed. Interceptor methods are matched to master methods based on name and parameter types equality (as in overriding). Return type and exception types are not taken in consideration.

Parameters:
master -
interceptors -
Returns:

combine

public static java.lang.Object combine(java.lang.Object[] objects,
                                       java.lang.Class[] interfaces)
Creates a proxy which implements given interfaces and routes invocations to appropriate object. If object is not found for a particular interface, then invocation is routed to the first object.

Parameters:
object -
interfaces -
Returns:

mix

public static java.lang.Object mix(java.lang.Object[] objects)
Mixes interfaces from multiple objects into one proxy. It can be used to "mix-in" interface into another interface, e.g. mix-in application-specific interfaces into HttpServletRequest. Different interfaces can be mixed-in depending on context, which is difficult to achieve with wrapping.

Parameters:
objects -
Returns:


Copyright © 2003 Hammurapi Group. All Rights Reserved.