Thanks for the patch Barney... one issue off the bat is the question of autowiring... do we autowire inherited init() methods? If so, we would need to modify BeanDefinition.cfc as well to search for the init()'s method signature for the superclass we are going to call it in.
On 5/10/06, Barney Boisvert <[EMAIL PROTECTED]> wrote:
On 5/10/06, Brian Kotek <[EMAIL PROTECTED]> wrote:
> The general consensus was that all
> concrete CFCs should have an init() method by convention, even if it is just
> to call the superclass's init() method. Sean and some others weighed in and
> agreed.
Damn them all!!!!! ;)
Coupling is evil. If I have a subclass that doesn't need custom
initialization, why couple the signature of the init method to the
superclass's? I'm going to need to change the superclass's behaviour
at some point, and then I'm going to have to COPY AND PASTE the change
into all my subclasses (or sacrifice documentability using my code
snippet from before). Horrible, satan, evil, death, ugly, nasty,
satan. ;)
> Since I
> don't think (emphasis on think) it would be too difficult to have ColdSpring
> look up the inheritance tree for an init() method, maybe this is something
> the framework authors would adopt.
You think correctly: it's really easy. Here's a patch that implements it:
Index: /home/barneyb/public_html/sorter/web/cfcs/coldspring/beans/DefaultXmlBeanFactory.cfc
===================================================================
--- /home/barneyb/public_html/sorter/web/cfcs/coldspring/beans/DefaultXmlBeanFactory.cfc (revision
1209)
+++ /home/barneyb/public_html/sorter/web/cfcs/coldspring/beans/DefaultXmlBeanFactory.cfc (working
copy)
@@ -280,6 +280,25 @@
</cffunction>
+ <cffunction name="beanMetadataIncludesInitMethod" access="private"
output="false" returntype="boolean">
+ <cfargument name="md" type="struct" required="true" />
+ <cfset var i = "" />
+ <cfloop condition="true">
+ <cfif structKeyExists(md, "functions")>
+ <cfloop from="1" to="#arrayLen(md.functions)#" index="i">
+ <cfif md.functions[i].name EQ "init">
+ <cfreturn true />
+ </cfif>
+ </cfloop>
+ </cfif>
+ <cfif structKeyExists(md, "extends")>
+ <cfset md = md.extends />
+ <cfelse>
+ <cfbreak />
+ </cfif>
+ </cfloop>
+ </cffunction>
+
<cffunction name="constructBean" access="private" returntype="any">
<cfargument name="beanName" type="string" required="true"/>
<cfargument name="returnInstance" type="boolean" required="false"
default="false"
@@ -332,8 +351,7 @@
<cfset md = getMetaData(beanInstance)/>
<!--- we need to call init method if it exists --->
- <cfloop from="1" to="#arraylen(md.functions)#" index="functionIndex">
- <cfif md.functions[functionIndex].name eq "init">
+ <cfif beanMetadataIncludesInitMethod(md)>
<cfinvoke component="#beanInstance#" method="init">
<!--- loop over any bean constructor-args and pass them into
the init() --->
<cfloop collection="#argDefs#" item="arg">
@@ -370,8 +388,7 @@
</cfloop>
</cfinvoke>
<!--- <cfbreak /> --->
- </cfif>
- </cfloop>
+ </cfif>
<!--- if this is a bean that extends the factory bean, set is factory --->
<cfif ArrayLen(StructFindValue(md,"coldspring.beans.factory.FactoryBean","ALL"))>
--
Barney Boisvert
[EMAIL PROTECTED]
360.319.6145
http://www.barneyb.com/
Got Gmail? I have 100 invites.
