On 3/5/06, Sean Corfield <[EMAIL PROTECTED]> wrote:
> Question to Chris / Dave / Kurt: would you expect ColdSpring to be
> able to generate a proxy bean for beans that are actually created by
> non-ColdSpring bean factories, like those shown above? I.e., Can I
> apply AOP to beans that ColdSpring creates via external factory beans?
Having spent a little more time digging in the code, I think the root
problem is philosophical: ColdSpring uses getMetadata() to obtain the
list of functions that should be inspected and that's never going to
include injected methods and I don't believe it will include inherited
methods either (I'm too lazy to test).
Reactor uses an inheritance structure that is something like this:
base <- project <- user <- userdb
Methods are not declared in the user and userdb versions of objects -
hence my problems with md.functions just not existing.
In order to apply AOP to these sorts of objects (and to be able to
autowire stuff - since the autowiring all uses getMetadata() too), it
would need to either change to use the live public method list (which
is fine for code that just needs names of methods or to call simple
setters etc) or it needs to unravel the full metadata functions list.
The latter wouldn't be too bad to implement: each loop over functions
would need to be wrapped in a loop that walked up md = md.extends if
structKeyExists(md,"extends"). Since everything extends the base
component and we wouldn't want to proxy that, we can just do this:
<cfloop condition="structKeyExists(md,'extends')">
<cfif structKeyExists(md,"functions")>
<cfloop ... arraylen(md.functions) ... >
...
</cfloop>
</cfif>
<cfset md = md.extends />
</cfloop>
Note the condition to allow for classes with no declared methods.
The question is not whether ColdSpring could do this but *should* it do this?
BTW, I think this sort of change (below) may need to be made in a few
other places:
> <cfif beanFactory.containsBean(setterName)>
> <cfset beanName = setterName />
> <cfelse>
> <!--- moved from above the cfif to allow for untyped by-name ops --->
> <cfset setterType = method.parameters[1].type />
> <cfset beanName = beanFactory.findBeanNameByType(setterType) />
> </cfif>
Otherwise code that doesn't declare types for everything will fail the
by-name search (because an exception will be thrown before that first
if).
--
Sean A Corfield -- http://corfield.org/
Got frameworks?
"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood