Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for parent Coldspring factories not working at all #135

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 17 additions & 17 deletions 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
Expand All @@ -11,33 +11,33 @@ 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"/>
<cfargument name="properties" type="struct" required="false" default="#structNew()#" hint="Properties to pass to the factory to create"/>
<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>
Expand All @@ -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>
91 changes: 47 additions & 44 deletions 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
Expand All @@ -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>
Expand All @@ -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>

Expand All @@ -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 --->
Expand All @@ -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">
Expand All @@ -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");
}
Expand All @@ -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.");
}
Expand All @@ -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>