Looking at the machii plugin, for ColdSpring, it overwrites the
ColdSpring that is currently in the application scope, if one already
exists and placeFactoryInApplicationScope is set to true.
I would have thought that it should check to see if the CS already
exists in the application scope, and therefore only creates it if it
is not there.
Here is a patch to implement this, if you agree with the way I think
it should work.
Mark
--
E: [EMAIL PROTECTED]
W: www.compoundtheory.com
Index: ColdspringPlugin.cfc
===================================================================
RCS file: /coldspring/coldspring/machii/ColdspringPlugin.cfc,v
retrieving revision 1.10
diff -u -r1.10 ColdspringPlugin.cfc
--- ColdspringPlugin.cfc 11 Dec 2006 02:23:30 -0000 1.10
+++ ColdspringPlugin.cfc 15 Jun 2007 05:36:31 -0000
@@ -7,13 +7,13 @@
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
-
+
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-
+
$Id: ColdspringPlugin.cfc,v 1.10 2006/12/11 02:23:30 wiersma Exp $
Description:
@@ -26,50 +26,50 @@
Default: 'beanFactory' -->
<parameter name="beanFactoryPropertyName"
value="serviceFactory"/>
- <!-- Name of a Mach-II property name that holds the path to the
ColdSpring config file
+ <!-- Name of a Mach-II property name that holds the path to the
ColdSpring config file
default: 'ColdSpringComponentsLocation' -->
<parameter name="configFilePropertyName"
value="ColdspringComponentRelativePath"/>
-
- <!-- Flag to indicate whether supplied config path is relative
(mapped) or absolute
+
+ <!-- Flag to indicate whether supplied config path is relative
(mapped) or absolute
Default: FALSE (absolute path) -->
<parameter name="configFilePathIsRelative" value="true"/>
-
- <!-- Flag to indicate whether to resolve dependencies for
listeners/filters/plugins
+
+ <!-- Flag to indicate whether to resolve dependencies for
listeners/filters/plugins
Default: FALSE -->
<parameter name="resolveMachIIDependencies" value="false"/>
-
- <!-- indicate a scope to pull in a parent bean factory from
+
+ <!-- indicate a scope to pull in a parent bean factory from
default: application -->
<parameter name="parentBeanFactoryScope" value="application"/>
-
+
<!-- Indicate a key to pull in a parent bean factory from the
application scope
Default: FALSE -->
<parameter name="parentBeanFactoryKey" value="serviceFactory"/>
-
- <!-- Indicate whether or not to place the bean factory in the
application scope
+
+ <!-- Indicate whether or not to place the bean factory in the
application scope
Default: FALSE -->
<parameter name="placeFactoryInApplicationScope" value="false"
/>
- <!-- Indicate whether or not to place the bean factory in the
server scope
+ <!-- Indicate whether or not to place the bean factory in the
server scope
Default: FALSE -->
<parameter name="placeFactoryInServerScope" value="false" />
-
+
<!--- List of bean names and coresponding Mach-II property
names for injecting back into Mach-II
Default: '' --->
<parameter name="beansToMachIIProperties"
value="beanName1=machIIpropertyName1,beanName2=machIIpropertyName2" />
-
+
</parameters>
</plugin>
-The [beanFactoryPropertyName] parameter value is the name of the Mach-II
property name
-that will hold a reference to the ColdSpring beanFactory. This parameter
+The [beanFactoryPropertyName] parameter value is the name of the Mach-II
property name
+that will hold a reference to the ColdSpring beanFactory. This parameter
defaults to "beanFactory" if not defined.
The [configFilePropertyName] paramater value is the name of Mach-II property
name that
-hold the path of the ColdSpring configuration file. The value of the Mach-II
property can
+hold the path of the ColdSpring configuration file. The value of the Mach-II
property can
be an relative, ColdFusion mapped or absolute path. If you are using a
relative or mapped
path, be sure to set the [configFilePathIsRelative] parameter to TRUE or the
plugin will
-not find your configuration file. This parameter defaults to
"ColdSpringComponentsLocation"
+not find your configuration file. This parameter defaults to
"ColdSpringComponentsLocation"
if not defined.
The [configGilePathIsRelative] parameter value defines if the configure file
is an relative
@@ -89,12 +89,12 @@
The [beansToMachIIProperties] parameter holds a special list of bean names and
coresponding
Mach-II property names. This parameter will inject the specified beans in the
Mach-II property
-manager as the bean factory has been loaded. In the past, a seperate plugin
has to be written
-to accomplish this task. This should be used for framework required "utility"
objects that you
-want to be managed by ColdSpring such as UDF, i18n or session facade objects.
Do not use this
+manager as the bean factory has been loaded. In the past, a seperate plugin
has to be written
+to accomplish this task. This should be used for framework required "utility"
objects that you
+want to be managed by ColdSpring such as UDF, i18n or session facade objects.
Do not use this
feature to inject your model objects into the Mach-II property manager.
-The format of this list should be a comma delimited list name/value pairs
consisting of the bean
+The format of this list should be a comma delimited list name/value pairs
consisting of the bean
name and corresponding Mach-II property name. Example:
beanName1=machIIpropertyName1,beanName2=machIIpropertyName2
@@ -110,73 +110,77 @@
--->
<cffunction name="configure" access="public" returntype="void"
output="false"
hint="I initialize this plugin during framework startup.">
-
+
<!--- Default vars --->
<cfset var appContext = 0 />
<cfset var bf = 0 />
<cfset var p = 0 />
-
+
<!--- Get the Mach-II property manaager --->
<cfset var pm = getAppManager().getPropertyManager() />
-
+
<!--- Determine the location of the bean def xml file --->
<cfset var serviceDefXmlLocation =
pm.getProperty(getParameter("configFilePropertyName",
"ColdSpringComponentsLocation")) />
-
+
<!--- Get all properties to pass to bean factory --->
<cfset var props = pm.getProperties() />
-
+
<!--- todo: Defaults set via mach-ii params --->
<cfset var defaults = StructNew() />
-
+
<!--- Locating and storing bean factory (from
properties/params) --->
<cfset var bfUtils = CreateObject("component",
"coldspring.beans.util.BeanFactoryUtils").init() />
<cfset var parentBeanFactoryKey =
getParameter("parentBeanFactoryKey", "") />
-
+
<cfset var localBeanFactoryKey =
getParameter("beanFactoryPropertyName", bfUtils.DEFAULT_FACTORY_KEY) />
<cfset var placeFactoryInApplicationScope =
getParameter("placeFactoryInApplicationScope", FALSE) />
-
+
<cfset var placeFactoryInServerScope =
getParameter('placeFactoryInServerScope','false') />
<cfset var parentBeanFactoryScope =
getParameter('parentBeanFactoryScope', 'application')>
-
-
+
+
<!--- Evaluate any dynamic properties --->
<cfloop collection="#props#" item="p">
<cfif IsSimpleValue(props[p]) AND Left(props[p], 2) EQ
"${" AND Right(props[p], 1) EQ "}">
<cfset props[p] = Evaluate(Mid(props[p], 3,
Len(props[p]) -3)) />
</cfif>
</cfloop>
-
- <!--- Create a new bean factory and appContext --->
- <cfset bf = CreateObject("component",
"coldspring.beans.DefaultXmlBeanFactory").init(defaults, props)/>
-
- <!--- if we're using an application scoped factory, retrieve
the appContext from app scope
- <cfif placeFactoryInApplicationScope and
bfUtils.namedContextExists('application', localBeanFactoryKey)>
- <cfset appContext =
bfUtils.getNamedApplicationContext('application', localBeanFactoryKey)>
- <cfset appContext.setBeanFactory(bf) />
+
+ <cfif placeFactoryInApplicationScope AND
bfUtils.namedFactoryExists( 'application', localBeanFactoryKey ) >
+ <cfset bf = bfUtils.getNamedFactory( 'application',
localBeanFactoryKey ) />
<cfelse>
- <cfset appContext =
createObject("component","coldspring.context.DefaultApplicationContext").init(bf)/>
- </cfif> --->
- <!--- <cfset appContext = createObject("component",
"coldspring.context.DefaultApplicationContext").init(bf)/> --->
-
- <!--- If necessary setup the parent bean factory --->
- <cfif len(parentBeanFactoryKey) and
bfUtils.namedFactoryExists(parentBeanFactoryScope, parentBeanFactoryKey)>
- <!--- OK, this time we're gonna try to use the new
ApplicationContextUtils --->
- <cfset
bf.setParent(bfUtils.getNamedFactory(parentBeanFactoryScope,
parentBeanFactoryKey))/>
- <!--- <cfset
bf.setParent(application[getParameter("parentBeanFactoryKey")].getBeanFactory())/>
--->
- </cfif>
-
- <!--- Expand path for relative and mapped config file paths --->
- <cfif getParameter("configFilePathIsRelative", FALSE)>
- <cfset serviceDefXmlLocation =
ExpandPath(serviceDefXmlLocation) />
+ <!--- Create a new bean factory and appContext --->
+ <cfset bf = CreateObject("component",
"coldspring.beans.DefaultXmlBeanFactory").init(defaults, props)/>
+
+ <!--- if we're using an application scoped factory,
retrieve the appContext from app scope
+ <cfif placeFactoryInApplicationScope and
bfUtils.namedContextExists('application', localBeanFactoryKey)>
+ <cfset appContext =
bfUtils.getNamedApplicationContext('application', localBeanFactoryKey)>
+ <cfset appContext.setBeanFactory(bf) />
+ <cfelse>
+ <cfset appContext =
createObject("component","coldspring.context.DefaultApplicationContext").init(bf)/>
+ </cfif> --->
+ <!--- <cfset appContext = createObject("component",
"coldspring.context.DefaultApplicationContext").init(bf)/> --->
+
+ <!--- If necessary setup the parent bean factory --->
+ <cfif len(parentBeanFactoryKey) and
bfUtils.namedFactoryExists(parentBeanFactoryScope, parentBeanFactoryKey)>
+ <!--- OK, this time we're gonna try to use the
new ApplicationContextUtils --->
+ <cfset
bf.setParent(bfUtils.getNamedFactory(parentBeanFactoryScope,
parentBeanFactoryKey))/>
+ <!--- <cfset
bf.setParent(application[getParameter("parentBeanFactoryKey")].getBeanFactory())/>
--->
+ </cfif>
+
+ <!--- Expand path for relative and mapped config file
paths --->
+ <cfif getParameter("configFilePathIsRelative", FALSE)>
+ <cfset serviceDefXmlLocation =
ExpandPath(serviceDefXmlLocation) />
+ </cfif>
+
+ <!--- Load the bean defs --->
+ <cfset bf.loadBeansFromXmlFile(serviceDefXmlLocation,
TRUE)/>
</cfif>
-
- <!--- Load the bean defs --->
- <cfset bf.loadBeansFromXmlFile(serviceDefXmlLocation, TRUE)/>
<!--- Put a bean factory reference into Mach-II property
manager --->
<cfset setProperty("beanFactoryName", localBeanFactoryKey) />
<cfset setProperty(localBeanFactoryKey, bf) />
-
+
<!--- Put a bean factory reference into the application if
required --->
<cfif placeFactoryInApplicationScope>
<cfset bfUtils.setNamedFactory("application",
localBeanFactoryKey, bf) />
@@ -184,50 +188,50 @@
<cfif placeFactoryInServerScope>
<cfset bfUtils.setNamedFactory('server',
localBeanFactoryKey, bf)>
</cfif>
-
+
<!--- Resolve Mach-II dependences if required --->
<cfif getParameter("resolveMachiiDependencies", FALSE)>
<cfset resolveDependencies() />
</cfif>
-
+
<!--- Place bean references into the Mach-II properties if
required --->
<cfif Len(getParameter("beansToMachIIProperties", ""))>
<cfset
referenceBeansToMachIIProperties(getParameter("beansToMachIIProperties")) />
- </cfif>
+ </cfif>
</cffunction>
-
+
<!---
PROTECTED FUNCTIONS
--->
<cffunction name="resolveDependencies" access="private"
returntype="void" output="false"
hint="Resolves Mach-II dependencies.">
-
+
<cfset var beanFactory =
getProperty(getProperty("beanFactoryName")) />
<cfset var targets = StructNew() />
-
+
<cfset var targetObj = 0 />
<cfset var targetIx = 0 />
-
+
<cfset var md = "" />
<cfset var functionIndex = 0 />
-
+
<cfset var setterName = "" />
<cfset var beanName = "" />
<cfset var access = "" />
-
+
<!--- Get listeners/filters/plugin targets --->
<cfset targets.data = ArrayNew(1) />
<cfset getListeners(targets) />
<cfset getFilters(targets) />
<cfset getPlugins(targets) />
-
+
<cfloop from="1" to="#ArrayLen(targets.data)#" index="targetIx">
<!--- Get this iteration target object for easy use --->
<cfset targetObj = targets.data[targetIx] />
-
+
<!--- Look for autowirable collaborators for any
SETTERS --->
<cfset md = GetMetaData(targetObj) />
-
+
<cfif StructKeyExists(md, "functions")>
<cfloop from="1" to="#arraylen(md.functions)#"
index="functionIndex">
<!--- first get the access type --->
@@ -236,45 +240,45 @@
<cfelse>
<cfset access = "public" />
</cfif>
-
+
<!--- if this is a 'real' setter --->
- <cfif
Left(md.functions[functionIndex].name, 3) EQ "set"
- AND
Arraylen(md.functions[functionIndex].parameters) EQ 1
+ <cfif
Left(md.functions[functionIndex].name, 3) EQ "set"
+ AND
Arraylen(md.functions[functionIndex].parameters) EQ 1
AND (access IS NOT
"private")>
-
- <!--- look for a bean in the
factory of the params's type --->
+
+ <!--- look for a bean in the
factory of the params's type --->
<cfset setterName =
Mid(md.functions[functionIndex].name, 4,
Len(md.functions[functionIndex].name)-3) />
-
+
<!--- Get bean by setter name
and if not found then get by type --->
<cfif
beanFactory.containsBean(setterName)>
<cfset beanName =
setterName />
<cfelse>
<cfset beanName =
beanFactory.findBeanNameByType(md.functions[functionIndex].parameters[1].type)
/>
</cfif>
-
+
<!--- If we found a bean, put
the bean by calling the target object's setter --->
<cfif Len(beanName)>
<cfinvoke
component="#targetObj#"
method="set#setterName#">
<cfinvokeargument name="#md.functions[functionIndex].parameters[1].name#"
value="#beanFactory.getBean(beanName)#"/>
- </cfinvoke>
- </cfif>
+ </cfinvoke>
+ </cfif>
</cfif>
- </cfloop>
+ </cfloop>
</cfif>
</cfloop>
-
+
</cffunction>
-
+
<cffunction name="getListeners" access="private" returntype="void"
output="false"
hint="Gets the listener targets.">
<cfargument name="targets" type="struct" required="true" />
-
+
<cfset var listenerManager =
getAppManager().getListenerManager() />
<cfset var listenerNames = ArrayNew(1) />
<cfset var i = 0 />
-
+
<!--- Get the listener names (inject a method for Mach-II 1.1.0
or lower) --->
<cfif StructKeyExists(listenerManager,"getListenerNames")>
<cfset listenerNames =
listenerManager.getListenerNames() />
@@ -283,24 +287,24 @@
<cfset listenerManager["getListenerNamesForColdSpring"]
= variables["getListenerNamesForColdSpring"] />
<cfset listenerNames =
listenerManager.getListenerNamesForColdSpring() />
<!--- Cleanup the mayhem --->
- <cfset StructDelete(listenerManager,
"getListenerNamesForColdSpring") />
+ <cfset StructDelete(listenerManager,
"getListenerNamesForColdSpring") />
</cfif>
-
+
<!--- Append each retrieved listener to the targets array (in
struct) --->
<cfloop from="1" to="#ArrayLen(listenerNames)#" index="i">
<cfset ArrayAppend(targets.data,
listenerManager.getListener(listenerNames[i])) />
</cfloop>
-
+
</cffunction>
-
+
<cffunction name="getFilters" access="private" returntype="void"
output="false"
hint="Get the filter targets.">
<cfargument name="targets" type="struct" required="true" />
-
+
<cfset var filterManager = getAppManager().getFilterManager() />
<cfset var filterNames = ArrayNew(1) />
<cfset var i = 0 />
-
+
<!--- Get the filter names (inject a method for Mach-II 1.1.0
or lower) --->
<cfif StructKeyExists(filterManager, "getFilterNames")>
<cfset filterNames = filterManager.getFilterNames() />
@@ -309,23 +313,23 @@
<cfset filterManager["getFilterNamesForColdSpring"] =
variables["getFilterNamesForColdSpring"] />
<cfset filterNames =
filterManager.getFilterNamesForColdSpring() />
<!--- Cleanup the mayhem --->
- <cfset StructDelete(filterManager,
"getFilterNamesForColdSpring") />
+ <cfset StructDelete(filterManager,
"getFilterNamesForColdSpring") />
</cfif>
-
+
<!--- Append each retrieved filter to the targets array (in
struct) --->
<cfloop from="1" to="#ArrayLen(filterNames)#" index="i">
<cfset ArrayAppend(targets.data,
filterManager.getFilter(filterNames[i])) />
</cfloop>
</cffunction>
-
+
<cffunction name="getPlugins" returntype="void" access="private"
output="false"
hint="Get the plugin targets.">
<cfargument name="targets" type="struct" required="true" />
-
+
<cfset var pluginManager = getAppManager().getPluginManager() />
<cfset var pluginNames = ArrayNew(1) />
<cfset var i = 0 />
-
+
<!--- Get the plugin names (inject a method for Mach-II 1.1.0
or lower) --->
<cfif StructKeyExists(pluginManager, "getPluginNames")>
<cfset pluginNames = pluginManager.getPluginNames() />
@@ -334,33 +338,33 @@
<cfset pluginManager["getPluginNamesForColdSpring"] =
variables["getPluginNamesForColdSpring"] />
<cfset pluginNames =
pluginManager.getPluginNamesForColdSpring() />
<!--- Cleanup the mayhem --->
- <cfset StructDelete(pluginManager,
"getPluginNamesForColdSpring") />
+ <cfset StructDelete(pluginManager,
"getPluginNamesForColdSpring") />
</cfif>
-
+
<!--- Append each retrieved plugin to the targets array (in
struct) --->
<cfloop from="1" to="#ArrayLen(pluginNames)#" index="i">
<cfset ArrayAppend(targets.data,
pluginManager.getPlugin(pluginNames[i])) />
</cfloop>
</cffunction>
-
+
<cffunction name="referenceBeansToMachIIProperties" access="private"
returntype="void" output="false"
hint="Places references to ColdSpring managed beans into the
Mach-II properties.">
<cfargument name="beanToPropertyList" type="string"
required="true" />
-
+
<cfset var beanFactory =
getProperty(getProperty("beanFactoryName")) />
<cfset var beanName = "" />
<cfset var i = "" />
-
+
<!--- Build references struct --->
<cfloop list="#arguments.beanToPropertyList#" index="i">
<cfset beanName = ListGetAt(i, 1, "=") />
-
+
<cfif beanFactory.containsBean(beanName)>
<cfset setProperty(ListGetAt(i, 2, "="),
beanFactory.getBean(beanName)) />
</cfif>
</cfloop>
</cffunction>
-
+
<!---
PUBLIC FUNCTIONS - INJECTABLE UTILITY METHODS
--->
@@ -368,12 +372,12 @@
hint="Injectable method for getting plugin names (for Mach-II
versions 1.1.0 and lower)">
<cfreturn StructKeyArray(variables.plugins) />
</cffunction>
-
+
<cffunction name="getFilterNamesForColdSpring" access="public"
returntype="array" output="false"
hint="Injectable method for getting filter names (for Mach-II
versions 1.1.0 and lower)">
<cfreturn StructKeyArray(variables.filters) />
</cffunction>
-
+
<cffunction name="getListenerNamesForColdSpring" access="public"
returntype="array" output="false"
hint="Injectable method for getting listener names (for Mach-II
versions 1.1.0 and lower)">
<cfreturn StructKeyArray(variables.listeners) />