Changeset 1974

Show
Ignore:
Timestamp:
11/23/2009 01:49:22 AM (4 months ago)
Author:
peterfarrell
Message:

Added override action in loadXml(). Still need to debug addPlugin(). refs[t:194]

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • framework/1-8-0/trunk/framework/PluginManager.cfc

    r1972 r1974  
    108108                <cfset var paramValue = "" /> 
    109109 
     110                <cfset var hasParent = IsObject(getParent()) /> 
    110111                <cfset var utils = getAppManager().getUtils() /> 
    111112                <cfset var baseProxy = "" /> 
     113                <cfset var mapping = "" /> 
    112114                <cfset var i = 0 /> 
    113115                <cfset var j = 0 /> 
    114116 
    115117                <!--- Set runParent attribute if this is a child PluginManager ---> 
    116                 <cfif IsObject(getParent())> 
     118                <cfif hasParent> 
    117119                        <cfset pluginNodes = XMLSearch(arguments.configXML, ".//plugins") /> 
    118120                        <cfif ArrayLen(pluginNodes) gt 0 AND StructKeyExists(pluginNodes[1].xmlAttributes, "runParent")> 
     
    133135                <cfloop index="i" from="1" to="#ArrayLen(pluginNodes)#"> 
    134136                        <cfset pluginName = pluginNodes[i].XmlAttributes["name"] /> 
    135                         <cfset pluginType = pluginNodes[i].XmlAttributes["type"] /> 
    136  
    137                         <!--- Set the Plugin's parameters. ---> 
    138                         <cfset pluginParams = StructNew() /> 
    139  
    140                         <!--- For each plugin, parse all the parameters ---> 
    141                         <cfif StructKeyExists(pluginNodes[i], "parameters")> 
    142                                 <cfset paramNodes = pluginNodes[i].parameters.xmlChildren /> 
    143                                 <cfloop from="1" to="#ArrayLen(paramNodes)#" index="j"> 
    144                                         <cfset paramName = paramNodes[j].XmlAttributes["name"] /> 
    145                                         <cftry> 
    146                                                 <cfset paramValue = utils.recurseComplexValues(paramNodes[j]) /> 
    147                                                 <cfcatch type="any"> 
    148                                                         <cfthrow type="MachII.framework.InvalidParameterXml" 
    149                                                                 message="Xml parsing error for the parameter named '#paramName#' for plugin '#pluginName#' in module '#getAppManager().getModuleName()#'." /> 
    150                                                 </cfcatch> 
    151                                         </cftry> 
    152                                         <cfset pluginParams[paramName] = paramValue /> 
    153                                 </cfloop> 
     137                         
     138                        <!--- Override XML for Modules ---> 
     139                        <cfif hasParent AND arguments.override AND StructKeyExists(pluginNodes[i].xmlAttributes, "overrideAction")> 
     140                                <!--- Check for a mapping ---> 
     141                                <cfif StructKeyExists(pluginNodes[i].xmlAttributes, "mapping")> 
     142                                        <cfset mapping = pluginNodes[i].xmlAttributes["mapping"] /> 
     143                                <cfelse> 
     144                                        <cfset mapping = pluginName /> 
     145                                </cfif> 
     146                                 
     147                                <!--- Check if parent has event handler with the mapping name ---> 
     148                                <cfif NOT getParent().isPluginDefined(mapping)> 
     149                                        <cfthrow type="MachII.framework.overridePluginNotDefined" 
     150                                                message="An plugin named '#mapping#' cannot be found in the parent plugin manager for the override named '#pluginName#' in module '#getAppManager().getModuleName()#'." /> 
     151                                </cfif> 
     152                                 
     153                                <cfset addPlugin(pluginName, getParent().getPlugin(mapping), arguments.override) />                      
     154                        <!--- General XML setup ---> 
     155                        <cfelse> 
     156                                <!--- Set the Plugin's type and parameters. ---> 
     157                                <cfset pluginType = pluginNodes[i].XmlAttributes["type"] /> 
     158                                <cfset pluginParams = StructNew() /> 
     159                                 
     160                                <!--- For each plugin, parse all the parameters ---> 
     161                                <cfif StructKeyExists(pluginNodes[i], "parameters")> 
     162                                        <cfset paramNodes = pluginNodes[i].parameters.xmlChildren /> 
     163                                        <cfloop from="1" to="#ArrayLen(paramNodes)#" index="j"> 
     164                                                <cfset paramName = paramNodes[j].XmlAttributes["name"] /> 
     165                                                <cftry> 
     166                                                        <cfset paramValue = utils.recurseComplexValues(paramNodes[j]) /> 
     167                                                        <cfcatch type="any"> 
     168                                                                <cfthrow type="MachII.framework.InvalidParameterXml" 
     169                                                                        message="Xml parsing error for the parameter named '#paramName#' for plugin '#pluginName#' in module '#getAppManager().getModuleName()#'." /> 
     170                                                        </cfcatch> 
     171                                                </cftry> 
     172                                                <cfset pluginParams[paramName] = paramValue /> 
     173                                        </cfloop> 
     174                                </cfif> 
     175         
     176                                <cftry> 
     177                                        <!--- Do not method chain the init() on the instantiation 
     178                                                or objects that have their init() overridden will 
     179                                                cause the variable the object is assigned to will  
     180                                                be deleted if init() returns void ---> 
     181                                        <cfset plugin = CreateObject("component", pluginType) /> 
     182                                        <cfset plugin.init(getAppManager(), pluginParams) /> 
     183         
     184                                        <cfcatch type="any"> 
     185                                                <cfif StructKeyExists(cfcatch, "missingFileName") AND cfcatch.missingFileName EQ pluginType> 
     186                                                        <cfthrow type="MachII.framework.CannotFindPlugin" 
     187                                                                message="Cannot find a CFC with the type of '#pluginType#' for the plugin named '#pluginName#' in module named '#getAppManager().getModuleName()#'." 
     188                                                                detail="Please check that a plugin exists and that there is not a misconfiguration in the XML configuration file." /> 
     189                                                <cfelse> 
     190                                                        <cfthrow type="MachII.framework.PluginSyntaxException" 
     191                                                                message="Mach-II could not register a plugin with type of '#pluginType#' for the plugin named '#pluginName#' in module named '#getAppManager().getModuleName()#'." 
     192                                                                detail="#getAppManager().getUtils().buildMessageFromCfCatch(cfcatch)#" /> 
     193                                                </cfif> 
     194                                        </cfcatch> 
     195                                </cftry> 
     196                                 
     197                                <cfset baseProxy = CreateObject("component",  "MachII.framework.BaseProxy").init(plugin, pluginType, pluginParams) /> 
     198                                <cfset plugin.setProxy(baseProxy) /> 
     199         
     200                                <cfset addPlugin(pluginName, plugin, arguments.override) /> 
    154201                        </cfif> 
    155  
    156                         <cftry> 
    157                                 <!--- Do not method chain the init() on the instantiation 
    158                                         or objects that have their init() overridden will 
    159                                         cause the variable the object is assigned to will  
    160                                         be deleted if init() returns void ---> 
    161                                 <cfset plugin = CreateObject("component", pluginType) /> 
    162                                 <cfset plugin.init(getAppManager(), pluginParams) /> 
    163  
    164                                 <cfcatch type="any"> 
    165                                         <cfif StructKeyExists(cfcatch, "missingFileName") AND cfcatch.missingFileName EQ pluginType> 
    166                                                 <cfthrow type="MachII.framework.CannotFindPlugin" 
    167                                                         message="Cannot find a CFC with the type of '#pluginType#' for the plugin named '#pluginName#' in module named '#getAppManager().getModuleName()#'." 
    168                                                         detail="Please check that a plugin exists and that there is not a misconfiguration in the XML configuration file." /> 
    169                                         <cfelse> 
    170                                                 <cfthrow type="MachII.framework.PluginSyntaxException" 
    171                                                         message="Mach-II could not register a plugin with type of '#pluginType#' for the plugin named '#pluginName#' in module named '#getAppManager().getModuleName()#'." 
    172                                                         detail="#getAppManager().getUtils().buildMessageFromCfCatch(cfcatch)#" /> 
    173                                         </cfif> 
    174                                 </cfcatch> 
    175                         </cftry> 
    176                          
    177                         <cfset baseProxy = CreateObject("component",  "MachII.framework.BaseProxy").init(plugin, pluginType, pluginParams) /> 
    178                         <cfset plugin.setProxy(baseProxy) /> 
    179  
    180                         <cfset addPlugin(pluginName, plugin, arguments.override) /> 
    181202                </cfloop> 
    182203        </cffunction>