|
From: Cameron B. <ca...@da...> - 2003-11-03 11:28:20
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
<title></title>
</head>
<body text="#000000" bgcolor="#ffffff">
I was experimenting with generating AOP proxies.<br>
<br>
I want to create a proxy that is a superclass of an action, to allow me
to add transactional interceptors.<br>
<br>
I tried using <br>
<br>
Object action = createAction();<br>
ProxyFactory proxyFactory = new ProxyFactory(action);<br>
proxyFactory.addInterceptor(.. my interceptor ...);<br>
return proxyFactory.getProxy();<br>
<br>
though this uses a J2SE proxy, which only works on the defined
interfaces.<br>
<br>
I tried to get the aop proxy factory to use cblib by doing this :<br>
<br>
Object action = createAction();<br>
ProxyFactory proxyFactory = new ProxyFactory(action);<br>
proxyFactory.setInterfaces(new Class[]{});<br>
proxyFactory.addInterceptor(transactionInterceptor);<br>
proxyFactory.addInterceptor(new InvokerInterceptor(action));<br>
return proxyFactory.getProxy();<br>
<br>
to create a proxy that has a target, but I need to remove the
interfaces otherwise a J2SE proxy will be created.<br>
<br>
This works ok, except for the fact that I am using an instance of the
action for the target, and cglib creates a new instance from the call
to enhance<br>
<br>
Enhancer.enhance(config.getTarget().getClass(),
config.getProxiedInterfaces(), ...)<br>
<br>
Is there any way that the proxy factory can be rigged to allow
specification of a target class, without an instance, then instead of
me creating an instance, cglib can create it for me ?<br>
<br>
Something like<br>
<br>
Class actionClazz = getActionClass()<br>
ProxyFactory proxyFactory = new ProxyFactory(actionClazz); <br>
proxyFactory.addInterceptor(transactionInterceptor);<br>
proxyFactory.addInterceptor(new
ProxyTargetInvokerInterceptor());<br>
return proxyFactory.getProxy();<br>
<br>
Though I don't know how the invoker interceptor will work, since there
is no actual target external to the proxy.<br>
Maybe a new ProxyTargetInvokerInterceptor() could be added. Without
it, invocations on the proxy would be exhibit the same behaviour as if
an InvokerInterceptor didn't exist at all.<br>
<br>
I dunno if I have made this very clear.. I am new to the AOP
terminoligy .<br>
<br>
Cameron.
<style type="text/css"><!--code { font-family: Courier New, Courier; font-size: 10pt; margin: 0px; }-->
</style><!-- ======================================================== -->
<!-- = Java Sourcecode to HTML automatically converted code = --><!-- = Java to HTML Converter V3.2 2003 by Markus Gebhard ma...@ja... = -->
<!-- = Further information: http://www.java2html.de = -->
<center> </center>
<br>
<pre cols="72" class="moz-signature">--
Any damn fool can write code that a computer can understand...
The trick is to write code that humans can understand.
[Martin Fowler <a class="moz-txt-link-freetext" href="http://www.martinfowler.com/distributedComputing/refactoring.pdf">http://www.martinfowler.com/distributedComputing/refactoring.pdf</a>]</pre>
</body>
</html>
|