Nicola Ken Barozzi wrote:
> Well, there is a way out, but I don't know if we want to do it. It's
> based on - ok, I'll say that word - an AOP interceptor mechanism(hehehe
> a big wording for a simple concept).
>
> Basically, we would have to use our own classloader in the
> ComponentManager, and make it load the class only after having it
> proxyed with the LogEnabled interface.
>
> Ok, down to simpler jargon. In JDK 1.3 there is java.lang.reflect.Proxy
> that can create a proxy.
>
> "
> A dynamic proxy class is a class that implements a list of interfaces
> specified at runtime when the class is created
>
> A proxy interface is such an interface that is implemented by a proxy
> class.
>
> A proxy instance is an instance of a proxy class.
>
> Each proxy instance has an associated invocation handler  object, which
> implements the interface InvocationHandler.
>
> A method invocation on a proxy instance through one of its proxy
> interfaces will be dispatched to the invoke method of the instance's
> invocation handler, passing the proxy instance, a
> java.lang.reflect.Method object identifying the method that was invoked,
> and an array of type Object  containing the arguments. The invocation
> handler processes the encoded method invocation as appropriate and the
> result that it returns will be returned as the result of the method
> invocation on the proxy instance.
> "
>
> So we can get
>
> LogEnabled f = (LogEnabled)
>                     Proxy.newProxyInstance
>                       (LogEnabled .class.getClassLoader(),
>                         new Class[] { LogEnabled .class },
>                         handler
>                        );
>
> Where handler has:
>
>   Object invoke(Object proxy, Method method, Object[] args)
>
> In this method we can recieve the LogEnabled call and make it go to the
> Loggable one.
>
> I'm not saying that Proxies are the way to go, this is just an example,
> but the concept remains. A cool way of doing it would be with CGLib for
> example (http://cglib.sourceforge.net/).
>
> Maybe a nice opportunity for Fortress to add interceptors, and for us to
> use Fortress? Or maybe Fortress already has it? ;-)
>
Interesting idea - but does it work? Both interfaces Loggable and LogEnabled
declare the same method getLogger() (with the same arguments) but with
a different return type. How do you know which version is queried in
your invokation handler? (I have not done too much with Proxies so I might
be simply too blind ...)

Carsten

Reply via email to