Changeset 1893
- Timestamp:
- 11/24/08 03:52:51 (4 years ago)
- Location:
- coldbox/trunk
- Files:
-
- 2 added
- 1 removed
- 4 modified
-
ApplicationTemplate/config/modelMappings.cfm (added)
-
system/config/readme.txt (modified) (1 diff)
-
system/frameworkSupertype.cfc (modified) (1 diff)
-
system/plugins/ClusterStorage.cfc (deleted)
-
system/plugins/beanFactory.cfc (modified) (15 diffs)
-
testharness/config/modelMappings.cfm (added)
-
testharness/handlers/ehGeneral.cfc (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
coldbox/trunk/system/config/readme.txt
r1891 r1893 223 223 * #640 New Application Template and Code Generators 224 224 * #641 New component metadata attributes for autowiring control: autowire_stoprecursion (classname), autowire_setterinjection (boolean) 225 225 * #642 New Model Integration using new model conventions and methods: getModel() and populateModel() and more. 226 226 227 == Version 2.6.1 (August 2008) CODENAME: FAITH == 227 228 -
coldbox/trunk/system/frameworkSupertype.cfc
r1818 r1893 100 100 <!------------------------------------------- FRAMEWORK FACADES -------------------------------------------> 101 101 102 <!--- Get Model ---> 103 <cffunction name="getModel" access="public" returntype="any" hint="Create or retrieve model objects by convention" output="false" > 104 <!--- ************************************************************* ---> 105 <cfargument name="name" required="true" type="string" hint="The name of the model to retrieve"> 106 <cfargument name="useSetterInjection" required="false" type="boolean" default="false" hint="Whether to use setter injection alongside the annotations property injection. cfproperty injection takes precedence."> 107 <cfargument name="onDICompleteUDF" required="false" type="string" default="onDIComplete" hint="After Dependencies are injected, this method will look for this UDF and call it if it exists. The default value is onDIComplete"> 108 <cfargument name="debugMode" required="false" type="boolean" default="false" hint="Debugging Mode or not"> 109 <!--- ************************************************************* ---> 110 <cfreturn getPlugin("beanFactory").getModel(argumentCollection=arguments)> 111 </cffunction> 112 113 <!--- Populate a model object from the request Collection ---> 114 <cffunction name="populateModel" access="public" output="false" returntype="Any" hint="Populate a named or instantiated model (java/cfc) from the request collection items"> 115 <!--- ************************************************************* ---> 116 <cfargument name="model" required="true" type="any" hint="The name of the model to get and populate or the acutal model object. If you already have an instance of a model, then use the populateBean() method"> 117 <cfargument name="scope" required="false" type="string" default="" hint="Use scope injection instead of setters population. Ex: scope=variables.instance."/> 118 <cfargument name="trustedSetter" required="false" type="boolean" default="false" hint="If set to true, the setter method will be called even if it does not exist in the bean"/> 119 <!--- ************************************************************* ---> 120 <cfreturn getPlugin("beanFactory").populateModel(argumentCollection=arguments)> 121 </cffunction> 122 102 123 <!--- View Rendering Facades ---> 103 124 <cffunction name="renderView" access="private" hint="Facade to plugin's render view." output="false" returntype="Any"> -
coldbox/trunk/system/plugins/beanFactory.cfc
r1891 r1893 23 23 <!--- ************************************************************* ---> 24 24 <cfscript> 25 var modelMappingsFile = "/"; 26 27 /* Super Init */ 25 28 super.Init(arguments.controller); 26 29 … … 33 36 setDICacheDictionary(CreateObject("component","coldbox.system.util.BaseDictionary").init('DIMetadata')); 34 37 38 /* Model Mappings */ 39 instance.modelMappings = structnew(); 40 41 /* Run Model Mappings */ 42 if( fileExists(getSetting("ApplicationPath") & "config/modelMappings.cfm") ){ 43 try{ 44 /* If AppMapping is not Blank check */ 45 if( getSetting('AppMapping') neq "" ){ 46 modelMappingsFile = modelMappingsFile & getSetting('AppMapping'); 47 } 48 modelMappingsFile = modelMappingsFile & "/config/modelMappings.cfm"; 49 /* Include it */ 50 include(modelMappingsFile); 51 } 52 catch(Any e){ 53 throw("Error including model mappings file: #e.message#",e.detail,"plugin.beanFactory.ModelMappingsIncludeException"); 54 } 55 } 35 56 36 57 /* Return instance */ … … 40 61 41 62 <!------------------------------------------- PUBLIC -------------------------------------------> 63 64 <!--- Get Model Mappings ---> 65 <cffunction name="getModelMappings" access="public" returntype="struct" hint="Get the model mappings structure" output="false" > 66 <cfreturn instance.modelMappings> 67 </cffunction> 68 69 <!--- Add Model Mapping ---> 70 <cffunction name="addModelMapping" access="public" returntype="void" hint="Add a new model mapping. Ex: addModelMapping('myBean','security.test.FormBean')" output="false" > 71 <!--- ************************************************************* ---> 72 <cfargument name="alias" required="true" type="string" hint="The model alias"> 73 <cfargument name="model" required="true" type="string" hint="The model class path (From the model conventions downward)"> 74 <!--- ************************************************************* ---> 75 <cfset var mappings = getModelMappings()> 76 <cfset mappings[arguments.alias] = arguments.model> 77 </cffunction> 42 78 43 79 <!--- Just create and call init, simple ---> … … 79 115 var ModelsPath = getSetting("ModelsPath"); 80 116 var ModelsInvocationPath = getSetting("ModelsInvocationPath"); 81 var checkPath = ModelsPath & "/" & replace(arguments.name,".","/","all") & ".cfc";82 var modelClassPath = ModelsInvocationPath & "." & arguments.name;117 var checkPath = 0; 118 var modelClassPath = 0; 83 119 var md = 0; 84 </cfscript> 85 120 var modelMappings = getModelMappings(); 121 122 /* Resolve name in Alias Checks */ 123 if( structKeyExists(modelMappings,arguments.name) ){ 124 arguments.name = modelMappings[arguments.name]; 125 } 126 /* Setup Paths */ 127 checkPath = ModelsPath & "/" & replace(arguments.name,".","/","all") & ".cfc"; 128 modelClassPath = ModelsInvocationPath & "." & arguments.name; 129 </cfscript> 86 130 87 131 <!--- Verify if model exists in cache ---> 88 132 <cfif ( getColdboxOCM().lookup(arguments.name) )> 89 133 <cfset oModel = getColdBoxOCM().get(arguments.name)> 90 <!--- Else Create It --->134 <!--- Else Create It if it exists ---> 91 135 <cfelseif ( fileExists(checkPath) )> 92 136 <cflock name="beanfactory.createmodel.#arguments.name#" type="exclusive" timeout="20" throwontimeout="true"> … … 132 176 <cfreturn oModel> 133 177 </cffunction> 178 179 <!--- Populate a model object from the request Collection ---> 180 <cffunction name="populateModel" access="public" output="false" returntype="Any" hint="Populate a named or instantiated model (java/cfc) from the request collection items"> 181 <!--- ************************************************************* ---> 182 <cfargument name="model" required="true" type="any" hint="The name of the model to get and populate or the acutal model object. If you already have an instance of a model, then use the populateBean() method"> 183 <cfargument name="scope" required="false" type="string" default="" hint="Use scope injection instead of setters population. Ex: scope=variables.instance."/> 184 <cfargument name="trustedSetter" required="false" type="boolean" default="false" hint="If set to true, the setter method will be called even if it does not exist in the bean"/> 185 <!--- ************************************************************* ---> 186 <cfscript> 187 var rc = controller.getRequestService().getContext().getCollection(); 188 var oModel = 0; 189 190 /* Do we have a model or name */ 191 if( isSimpleValue(arguments.model) ){ 192 oModel = getModel(model); 193 } 194 else{ 195 oModel = arguments.model; 196 } 197 198 /* Inflate from Request Collection */ 199 return populateFromStruct(oModel,rc,arguments.scope,arguments.trustedSetter); 200 </cfscript> 201 </cffunction> 134 202 135 203 <!--- Populate a bean from the request Collection ---> 136 204 <cffunction name="populateBean" access="public" output="false" returntype="Any" hint="Populate a named or instantiated bean (java/cfc) from the request collection items"> 137 205 <!--- ************************************************************* ---> 138 <cfargument name="formBean" required="true" type="any" hint="This can be an instantiated bean object or a bean instantitation path as a string. If you pass an instantiation path and the bean has an 'init' method. It will be executed.This method follows the bean contract (set{property_name}). Example: setUsername(), setfname()">206 <cfargument name="formBean" required="true" type="any" hint="This can be an instantiated bean object or a bean instantitation path as a string. This method follows the bean contract (set{property_name}). Example: setUsername(), setfname()"> 139 207 <cfargument name="scope" required="false" type="string" default="" hint="Use scope injection instead of setters population. Ex: scope=variables.instance."/> 140 208 <cfargument name="trustedSetter" required="false" type="boolean" default="false" hint="If set to true, the setter method will be called even if it does not exist in the bean"/> … … 144 212 145 213 /* Inflate from Request Collection */ 146 return populateFromStruct(arguments.formBean,rc,arguments.scope );214 return populateFromStruct(arguments.formBean,rc,arguments.scope,arguments.trustedSetter); 147 215 </cfscript> 148 216 </cffunction> … … 163 231 164 232 /* populate and return */ 165 return populateFromStruct(arguments.formBean,inflatedStruct,arguments.scope );233 return populateFromStruct(arguments.formBean,inflatedStruct,arguments.scope,arguments.trustedSetter); 166 234 </cfscript> 167 235 </cffunction> … … 316 384 /* We are now assured that the DI cache has data. */ 317 385 targetDIEntry = getDICacheDictionary().getKey(targetCacheKey); 386 318 387 /* Do we Inject Dependencies, are we AutoWiring */ 319 388 if ( targetDIEntry.autowire ){ … … 329 398 thisDependency = targetDIEntry.dependencies[x]; 330 399 331 /* Determine Type of Injection */400 /* Determine Type of Injection according to Type */ 332 401 if( thisDependency.type eq "ioc" ){ 333 402 injectIOC(thisDependency,targetObject,arguments.debugMode); … … 336 405 injectOCM(thisDependency,targetObject,arguments.debugMode); 337 406 } 338 else {407 else if ( listFirst(thisDependency.type,":") eq "coldbox" ){ 339 408 /* Try to inject coldbox dependencies */ 340 409 injectColdboxDSL(thisDependency,targetObject,arguments.debugMode); 341 } 410 } 411 else if ( listFirst(thisDependency.type,":") eq "model" ){ 412 /* Try to inject coldbox dependencies */ 413 injectModelDSL(thisDependency,targetObject,arguments.debugMode); 414 } 342 415 343 416 }//end for loop of dependencies. … … 354 427 <!------------------------------------------- PRIVATE -------------------------------------------> 355 428 356 <!--- inject ColdboxDSL --->357 <cffunction name="inject ColdboxDSL" access="private" returntype="void" hint="Inject dependencies using the coldboxdependency DSL" output="false" >429 <!--- injectModelDSL ---> 430 <cffunction name="injectModelDSL" access="private" returntype="void" hint="Inject dependencies using the model dependency DSL" output="false" > 358 431 <!--- ************************************************************* ---> 359 432 <cfargument name="Definition" required="true" type="any" hint="The dependency definition structure"> … … 369 442 var locatedDependency = "_NOT_FOUND_"; 370 443 371 /* 1 stage dependency */ 372 if( thisTypeLen eq 1 ){ 373 /* Coldbox Reference is the only one available */ 374 locatedDependency = getController(); 375 } 376 /* 2 stage dependencies */ 377 else if(thisTypeLen eq 2){ 378 /* configBean or mailsettingsbean */ 379 thisLocationType = listLast(thisType,":"); 380 if( thisLocationType eq "configbean" ){ 381 locatedDependency = getSettingsBean(); 382 } 383 else if( thisLocationType eq "mailsettingsbean" ){ 384 locatedDependency = getMailSettings(); 385 } 386 } 387 /* 3 stage dependencies */ 444 /* 2 stage dependency dsl */ 445 if(thisTypeLen eq 2){ 446 thisLocationType = getToken(thisType,2,":"); 447 /* Get model object*/ 448 locatedDependency = getModel(thisLocationType); 449 } 450 /* 3 stage dependency dsl */ 388 451 else if(thisTypeLen eq 3){ 389 452 thisLocationType = getToken(thisType,2,":"); 390 453 thisLocationKey = getToken(thisType,3,":"); 391 /* Fork on types */ 392 if( thisLocationType eq "setting" ){ 393 locatedDependency = getSetting(thisLocationKey); 394 } 395 else if( thisLocationType eq "plugin" ){ 396 locatedDependency = getPlugin(thisLocationKey); 397 } 398 else if( thisLocationType eq "myplugin" ){ 399 locatedDependency = getMyPlugin(thisLocationKey); 400 } 401 else if( thisLocationType eq "datasource" ){ 402 locatedDependency = getDatasource(thisLocationKey); 403 } 404 else if( thisLocationType eq "model" ){ 405 locatedDependency = getModel(thisLocationKey); 406 } 454 /* Call model method to get dependency */ 455 locatedDependency = evaluate("getModel(thisLocationType).#thisLocationKey#()"); 407 456 }//end 3 stage DSL 408 457 … … 427 476 </cfscript> 428 477 </cffunction> 478 479 <!--- injectColdboxDSL ---> 480 <cffunction name="injectColdboxDSL" access="private" returntype="void" hint="Inject dependencies using the coldbox dependency DSL" output="false" > 481 <!--- ************************************************************* ---> 482 <cfargument name="Definition" required="true" type="any" hint="The dependency definition structure"> 483 <cfargument name="targetObject" required="true" type="any" hint="The target object"> 484 <cfargument name="debugMode" required="true" type="boolean" hint="The debug mode"> 485 <!--- ************************************************************* ---> 486 <cfscript> 487 var thisDependency = arguments.Definition; 488 var thisType = thisDependency.type; 489 var thisTypeLen = listLen(thisType,":"); 490 var thisLocationType = ""; 491 var thisLocationKey = ""; 492 var locatedDependency = "_NOT_FOUND_"; 493 494 /* 1 stage dependency */ 495 if( thisTypeLen eq 1 ){ 496 /* Coldbox Reference is the only one available on 1 stage DSL */ 497 locatedDependency = getController(); 498 } 499 /* 2 stage dependencies. Model:Test or Coldbox:etc */ 500 else if(thisTypeLen eq 2){ 501 thisLocationKey = getToken(thisType,2,":"); 502 if( thisLocationKey eq "configbean" ){ 503 locatedDependency = getSettingsBean(); 504 } 505 else if( thisLocationKey eq "mailsettingsbean" ){ 506 locatedDependency = getMailSettings(); 507 } 508 } 509 /* 3 stage dependencies */ 510 else if(thisTypeLen eq 3){ 511 thisLocationType = getToken(thisType,2,":"); 512 thisLocationKey = getToken(thisType,3,":"); 513 /* Fork on types */ 514 if( thisLocationType eq "setting" ){ 515 locatedDependency = getSetting(thisLocationKey); 516 } 517 else if( thisLocationType eq "plugin" ){ 518 locatedDependency = getPlugin(thisLocationKey); 519 } 520 else if( thisLocationType eq "myplugin" ){ 521 locatedDependency = getMyPlugin(thisLocationKey); 522 } 523 else if( thisLocationType eq "datasource" ){ 524 locatedDependency = getDatasource(thisLocationKey); 525 } 526 }//end 3 stage DSL 527 528 /* Verify injetion */ 529 if( isSimpleValue(locatedDependency) AND locatedDependency EQ "_NOT_FOUND_" ){ 530 /* Only log if debugmode, else no injection */ 531 if( arguments.debugMode ){ 532 getPlugin("logger").logEntry("warning","Dependency: #thisDependency.toString()# --> not found in factory"); 533 } 534 } 535 else{ 536 /* Inject Dependency */ 537 injectBean(targetBean=arguments.targetObject, 538 beanName=thisDependency.name, 539 beanObject=locatedDependency, 540 scope=thisDependency.scope); 541 /* Debug Mode Check */ 542 if( arguments.debugMode ){ 543 getPlugin("logger").logEntry("information","Dependency: #thisDependency.toString()# --> injected into #getMetadata(arguments.targetObject).name#."); 544 } 545 } 546 </cfscript> 547 </cffunction> 429 548 430 549 <!--- injectIOC ---> … … 501 620 var cbox_reserved_functions = "setSetting,setDebugMode,setNextEvent,setNextRoute,setController,settingExists,setPluginName,setPluginVersion,setPluginDescription,setProperty,setproperties"; 502 621 var foundDependencies = ""; 622 var DSLNamespaces = "coldbox,ioc,ocm"; 503 623 504 624 /* Look for Object's attributes, and override if found. */ … … 513 633 if( structKeyExists(md,"properties") and ArrayLen(md.properties) gt 0){ 514 634 for(x=1; x lte ArrayLen(md.properties); x=x+1 ){ 515 /* Check types */635 /* Check types are valid for autowiring. */ 516 636 if( structKeyExists(md.properties[x],"type") AND 517 (md.properties[x].type eq "ioc" OR md.properties[x].type eq "ocm" OR findNoCase("coldbox",md.properties[x].type)) ){ 637 ( listFindNoCase(DSLNamespaces,md.properties[x].type) OR 638 findnocase("model",md.properties[x].type) OR 639 findnocase("coldbox",md.properties[x].type) ) 640 ){ 518 641 /* New MD Entry */ 519 642 entry = structnew(); -
coldbox/trunk/testharness/handlers/ehGeneral.cfc
r1891 r1893 27 27 <cfproperty name="MailSettingsBean" type="coldbox:mailsettingsBean" scope="instance"> 28 28 <cfproperty name="MySiteDSN" type="coldbox:datasource:mysite" scope="instance"> 29 <cfproperty name="testModel" type="coldbox:model:testModel" scope="instance"> 29 <cfproperty name="testModel" type="model:testModel" scope="instance"> 30 <cfproperty name="initDate" type="model:formBean:getinitDate" scope="instance"> 30 31 31 32 … … 92 93 <cfset var complexStruct = ""> 93 94 <cfset var complete = ""> 94 <cfdump var="#instance#"><cfabort>95 <!--- <cfset Event.setValue("MailBean",getmyMailSettings())> --->95 96 <!--- <cfset Event.setValue("MailBean",getmyMailSettings())> ---> 96 97 <cfset Event.setValue("MailBean",getmyMailSettings())> 97 98 … … 205 206 var rc = Event.getCollection(); 206 207 //populate bean 207 rc.FormBean = controller.getPlugin("beanfactory").populateBean("#controller.getSetting("AppMapping")#.model.formBean");208 rc.FormBean = populateModel("MyFormBean"); 208 209 Event.setView("vwFormBean"); 209 210 </cfscript>
