Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix for parent Coldspring factories not working at all #135

Closed
wants to merge 2 commits into from

2 participants

@DominicWatson

Fixes two issues:

  1. Coldspring2 IOC adapter using the wrong method names for its SetParentFactory() method - meaning that the parent was never set.
  2. IOC plugin throwing an error when attempting to set parent bean factory due to the buildAdapter() method not actually returning the adapter but instead setting the local adapter instance (which does not appear to be the design).

Apologies for the large amount of whitespace changes. I have my editor set to trim trailing white spaces on save :s

DominicWatson added some commits
@DominicWatson DominicWatson Update IOC.cfc
Fix for error thrown when using configured parent factories. Logic seemed to be incorrect and not in keeping with the hint on the buildAdapter() method.
aab177e
@DominicWatson DominicWatson Update ColdSpring2Adapter.cfc
Fix for parent bean factory not actually being set when using the Coldspring2 adapter. Method names getParentFactory() and getParentBeanFactory() were defined the wrong way around (it is getParentBeanFactory() in Coldspring and should have been GetParentFactory() in the coldbox adapter.
9a55126
@lmajano
Owner

Thanks, added manualy as I needed to add several tests. You can find them in the development branch.

@lmajano lmajano closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 25, 2013
  1. @DominicWatson

    Update IOC.cfc

    DominicWatson authored
    Fix for error thrown when using configured parent factories. Logic seemed to be incorrect and not in keeping with the hint on the buildAdapter() method.
  2. @DominicWatson

    Update ColdSpring2Adapter.cfc

    DominicWatson authored
    Fix for parent bean factory not actually being set when using the Coldspring2 adapter. Method names getParentFactory() and getParentBeanFactory() were defined the wrong way around (it is getParentBeanFactory() in Coldspring and should have been GetParentFactory() in the coldbox adapter.
This page is out of date. Refresh to see the latest.
Showing with 64 additions and 61 deletions.
  1. +17 −17 system/ioc/adapters/ColdSpring2Adapter.cfc
  2. +47 −44 system/plugins/IOC.cfc
View
34 system/ioc/adapters/ColdSpring2Adapter.cfc
@@ -1,4 +1,4 @@
-<!-----------------------------------------------------------------------
+<!-----------------------------------------------------------------------
********************************************************************************
Copyright Since 2005 ColdBox Framework by Luis Majano and Ortus Solutions, Corp
www.coldbox.org | www.luismajano.com | www.ortussolutions.com
@@ -11,11 +11,11 @@ Description :
----------------------------------------------------------------------->
<cfcomponent hint="The ColdBox ColdSpring2 IOC factory adapter"
- extends="coldbox.system.ioc.AbstractIOCAdapter"
+ extends="coldbox.system.ioc.AbstractIOCAdapter"
output="false">
-<!----------------------------------------- CONSTRUCTOR ------------------------------------->
-
+<!----------------------------------------- CONSTRUCTOR ------------------------------------->
+
<!--- Constructor --->
<cffunction name="init" access="public" returntype="ColdSpring2Adapter" hint="Constructor" output="false" >
<cfargument name="definitionFile" type="string" required="false" default="" hint="The definition file to load a factory with"/>
@@ -23,21 +23,21 @@ Description :
<cfargument name="coldbox" type="any" required="false" default="" hint="A coldbox application that this instance of logbox can be linked to, not used if not using within a ColdBox Application."/>
<cfscript>
super.init(argumentCollection=arguments);
-
+
// ColdSpring Factory Path
instance.COLDSPRING2_FACTORY_PATH = "coldspring.beans.xml.XmlBeanFactory";
-
+
return this;
</cfscript>
</cffunction>
-<!----------------------------------------- PUBLIC ------------------------------------->
+<!----------------------------------------- PUBLIC ------------------------------------->
<!--- createFactory --->
<cffunction name="createFactory" access="public" returntype="void" hint="Create the ColdSpring Factory" output="false" >
<cfscript>
var properties = getProperties();
-
+
//Create the Coldspring Factory
instance.factory = createObject("component", instance.COLDSPRING2_FACTORY_PATH ).init( getDefinitionFile() , properties);
</cfscript>
@@ -50,26 +50,26 @@ Description :
return getFactory().getBean(arguments.beanName);
</cfscript>
</cffunction>
-
+
<!--- containsBean --->
<cffunction name="containsBean" access="public" returntype="boolean" hint="Check if the bean factory contains a bean" output="false" >
- <cfargument name="beanName" type="string" required="true" hint="The bean name to retrieve from the object factory">
+ <cfargument name="beanName" type="string" required="true" hint="The bean name to retrieve from the object factory">
<cfscript>
return getFactory().containsBean(arguments.beanName);
</cfscript>
</cffunction>
-
+
<!--- setParentFactory --->
- <cffunction name="setParentBeanFactory" output="false" access="public" returntype="void" hint="Set a parent factory on the adapted factory">
+ <cffunction name="setParentFactory" output="false" access="public" returntype="void" hint="Set a parent factory on the adapted factory">
<cfargument name="parent" type="any" required="true" hint="The parent factory to add"/>
- <cfset getFactory().setParentFactory( arguments.parent )>
+ <cfset getFactory().setParentBeanFactory( arguments.parent )>
</cffunction>
-
+
<!--- getParentFactory --->
<cffunction name="getParentFactory" output="false" access="public" returntype="any" hint="Get the parent factory">
<cfreturn getFactory().getParentBeanFactory()>
</cffunction>
-<!----------------------------------------- PRIVATE ------------------------------------->
-
-</cfcomponent>
+<!----------------------------------------- PRIVATE ------------------------------------->
+
+</cfcomponent>
View
91 system/plugins/IOC.cfc
@@ -1,4 +1,4 @@
-<!-----------------------------------------------------------------------
+<!-----------------------------------------------------------------------
********************************************************************************
Copyright Since 2005 ColdBox Framework by Luis Majano and Ortus Solutions, Corp
www.coldbox.org | www.luismajano.com | www.ortussolutions.com
@@ -22,22 +22,22 @@ Description :
<!--- ************************************************************* --->
<cfscript>
super.init(arguments.controller);
-
+
// Plugin Properties
setpluginName("IOC");
setpluginVersion("3.0");
setpluginDescription("This is an inversion of control plugin.");
setpluginAuthor("Luis Majano");
setpluginAuthorURL("http://www.coldbox.org");
-
+
// The adapter used by this ioc plugin
instance.adapter = "";
-
+
// Setup depenedencies
instance.objCaching = getSetting("IOCObjectCaching");
instance.beanFactory = getPlugin("BeanFactory");
instance.IOCFramework = getSetting("IOCFramework");
-
+
return this;
</cfscript>
</cffunction>
@@ -51,25 +51,25 @@ Description :
var parentFramework = getSetting("IOCParentFactory");
var paretDefinitionFile = getSetting("IOCParentFactoryDefinitionFile");
var parentAdapter = "";
-
+
if( log.canInfo() ){
log.info("IOC integration detected, beginning configuration of IOC Factory");
}
-
+
// build adapter using application chosen properties
- buildAdapter(instance.IOCFramework, definitionFile);
-
+ instance.adapter = buildAdapter(instance.IOCFramework, definitionFile);
+
// Do we have a parent to build?
if( len(parentFramework) ){
-
+
if( log.canDebug() ){
log.debug("Parent Factory detected: #parentFramework#:#paretDefinitionFile# and loading...");
}
-
+
// Build parent adapter and set it on original adapter factory.
parentAdapter = buildAdapter(parentFramework, paretDefinitionFile);
instance.adapter.setParentFactory( parentAdapter.getFactory() );
- }
+ }
</cfscript>
</cffunction>
@@ -89,40 +89,40 @@ Description :
<cfscript>
var refLocal = structnew();
var beanKey = "ioc_" & arguments.beanName;
-
+
// Check if Ioc Caching
if( instance.objCaching ){
// get bean and verify its existence
refLocal.oBean = getColdBoxOCM().get( beanKey );
if( structKeyExists(refLocal,"oBean") and isObject(refLocal.oBean) ){
return refLocal.oBean;
- }
+ }
}
-
+
// get object from adapter factory
refLocal.oBean = instance.adapter.getBean( arguments.beanName );
-
+
// process WireBox autowires only if not wireBox.
instance.beanFactory.autowire(target=refLocal.oBean,annotationCheck=true);
-
+
// processObjectCaching?
if( instance.objCaching ){
processObjectCaching( refLocal.oBean, beanKey);
}
-
- return refLocal.oBean;
+
+ return refLocal.oBean;
</cfscript>
</cffunction>
-
+
<!--- containsBean --->
<cffunction name="containsBean" access="public" returntype="any" hint="Check if the bean factory contains a bean" output="false" colddoc:generic="boolean">
- <cfargument name="beanName" required="true" hint="The bean name to retrieve from the object factory">
+ <cfargument name="beanName" required="true" hint="The bean name to retrieve from the object factory">
<cfreturn instance.adapter.containsBean( arguments.beanName )>
</cffunction>
- <!--- getAdapter --->
- <cffunction name="getAdapter" output="false" access="public" returntype="any" hint="Get the IoC Factory Adapter in use by this plugin">
- <cfreturn instance.adapter>
+ <!--- getAdapter --->
+ <cffunction name="getAdapter" output="false" access="public" returntype="any" hint="Get the IoC Factory Adapter in use by this plugin">
+ <cfreturn instance.adapter>
</cffunction>
<!--- get the IoC Factory in use --->
@@ -148,7 +148,7 @@ Description :
<cfargument name="cacheKey" required="true" hint="CacheKey to use if necessary"/>
<!--- Get Object's MetaData --->
<cfset var metaData = getMetaData(arguments.target)>
-
+
<!--- Caching & Autowire only for CFC's Not Java objects --->
<cfif isStruct( metadata )>
<cflock name="IOC.objectCaching.#metaData.name#" type="exclusive" timeout="30" throwontimeout="true">
@@ -165,38 +165,39 @@ Description :
if( not structKeyExists(MetaData,"cacheLastAccessTimeout") or not isNumeric(metadata.cacheLastAccessTimeout) ){
metaData.cacheLastAccessTimeout = "";
}
-
+
if( log.canDebug() ){
log.debug("Bean: #metadata.name# ioc caching detected, saving on buffer cache");
}
-
+
getColdboxOCM().set(arguments.cacheKey,target,metadata.cacheTimeout,metadata.cacheLastAccessTimeout);
}
</cfscript>
</cflock>
</cfif>
</cffunction>
-
+
<!--- buildAdapter --->
<cffunction name="buildAdapter" output="false" access="private" returntype="any" hint="Build an IoC framework adapter and return it">
<cfargument name="framework" required="true" hint="The framework adapter to build"/>
<cfargument name="definitionFile" required="true" hint="The framework definition file to load"/>
- <cfscript>
+ <cfscript>
var adapterPath = "";
-
+ var adapter = "";
+
switch( arguments.framework ){
case "coldspring" : { adapterPath = "coldbox.system.ioc.adapters.ColdSpringAdapter"; break; }
case "coldspring2" : { adapterPath = "coldbox.system.ioc.adapters.ColdSpring2Adapter"; break; }
case "lightwire" : { adapterPath = "coldbox.system.ioc.adapters.LightWireAdapter"; break; }
case "wirebox" : { adapterPath = "coldbox.system.ioc.adapters.WireBoxAdapter"; break; }
// Default as custom object class
- default : { adapterPath = arguments.framework; break;}
+ default : { adapterPath = arguments.framework; break;}
}
-
+
// Create Adapter
try{
- instance.adapter = createObject("component",adapterPath).init(validateDefinitionFile(arguments.definitionFile),controller.getConfigSettings(),controller);
-
+ adapter = createObject("component",adapterPath).init(validateDefinitionFile(arguments.definitionFile),controller.getConfigSettings(),controller);
+
if( log.canDebug() ){
log.debug("ioc factory adapter: #adapterPath# built successfully");
}
@@ -205,10 +206,10 @@ Description :
log.error("Error creating ioc factory adapter (#adapterPath#). Arguments: #arguments.toString()#, Message: #e.message# #e.detail# #e.stacktrace#");
$throw(message="Error Creating ioc factory adapter (#adapterPath#) : #e.message#",detail="#e.detail# #e.stacktrace#",type="IOC.AdapterCreationException");
}
-
+
// Create Adapter Factory
try{
- instance.adapter.createFactory();
+ adapter.createFactory();
if( log.canDebug() ){
log.debug("ioc framework: #getMetadata(instance.adapter.getFactory()).name# loaded successfully and ready for operation.");
}
@@ -217,34 +218,36 @@ Description :
log.error("Error creating ioc factory from adapter. Arguments: #arguments.toString()#, Message: #e.message# #e.detail# #e.stacktrace#");
$throw(message="Error Creating ioc factory: #e.message#",detail="#e.detail# #e.stacktrace#",type="IOC.AdapterFactoryCreationException");
}
-
+
if( log.canInfo() ){
log.info("IoC factory: #arguments.framework#:#arguments.definitionFile# loaded and configured for operation");
}
+
+ return adapter;
</cfscript>
</cffunction>
-
+
<!--- Validate the definition file --->
<cffunction name="validateDefinitionFile" access="private" output="false" returntype="any" hint="Validate the IoC Definition File. Called internally to verify the file location and get the correct path to it.">
<cfargument name="definitionFile" required="true" hint="The definition file to verify for loading"/>
<cfscript>
var foundFilePath = "";
-
+
// Is this an xml or cfm file or a CFC path?
if( NOT listFindNoCase("xml,cfm", listLast(arguments.definitionFile,".")) ){
return arguments.definitionFile;
}
-
+
// Try to locate the path
foundFilePath = locateFilePath( arguments.definitionFile );
-
+
// Validate it
if( len(foundFilePath) eq 0 ){
$throw("The definition file: #arguments.definitionFile# does not exist. Please check your path","","IOC.InvalidDefitinionFile");
}
-
+
return foundFilePath;
</cfscript>
</cffunction>
-
-</cfcomponent>
+
+</cfcomponent>
Something went wrong with that request. Please try again.