| 1 | <cfscript>
|
|---|
| 2 | // @ Author Qasim Rasheed (qasimrasheed@gmail.com)
|
|---|
| 3 | // Original idea taken by ColdSpring lexicon by Nathan Strutz.
|
|---|
| 4 | // Initializes ColdSpring into the current application scope (respecting the fusebox application key). This tag accepts one of more bean tag as children
|
|---|
| 5 | // usage:
|
|---|
| 6 | // 1. add the lexicon declaration to your circuit file:
|
|---|
| 7 | // <circuit xmlns:cs="coldspring/">
|
|---|
| 8 | // 2. use the verb in a fuseaction:
|
|---|
| 9 | // <cs:initialize coldspringfactory="servicefactory" defaultproperties="default coldspring properties">
|
|---|
| 10 | // <cs:bean beanDefinitionFile="..." />
|
|---|
| 11 | // more bean tags......
|
|---|
| 12 | // </cs:initialize>
|
|---|
| 13 | //
|
|---|
| 14 | if (fb_.verbInfo.executionMode is "start") {
|
|---|
| 15 | // coldspringfactory is optional:
|
|---|
| 16 | fb_.coldspringfactory = 'servicefactory';
|
|---|
| 17 | if (structKeyExists(fb_.verbInfo.attributes,"coldspringfactory")) {
|
|---|
| 18 | fb_.coldspringfactory = '#fb_.verbInfo.attributes.coldspringfactory#';
|
|---|
| 19 | }
|
|---|
| 20 |
|
|---|
| 21 | // default properties is optional:
|
|---|
| 22 | fb_.defaultproperties = '##structnew()##';
|
|---|
| 23 | if ( structKeyExists(fb_.verbInfo.attributes,"defaultproperties" ) ) {
|
|---|
| 24 | fb_.defaultproperties = fb_.verbInfo.attributes.defaultproperties;
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | // if it has no bean tag as children.
|
|---|
| 28 | if ( not fb_.verbInfo.hasChildren ) {
|
|---|
| 29 | fb_throw("fusebox.badGrammar.childTagMissing",
|
|---|
| 30 | "Child bean tag is missing",
|
|---|
| 31 | "Child bean tag is missing for verb 'initialize' in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | // this is where the child <bean> verbs will store their data:
|
|---|
| 35 | fb_.verbInfo.beans = arrayNew(1);
|
|---|
| 36 |
|
|---|
| 37 | } else {
|
|---|
| 38 | // set ColdSpring in this fusebox instance's application space
|
|---|
| 39 | fb_appendLine('<cfset myFusebox.getApplication().getApplicationData().#fb_.coldspringfactory# = createObject("component", "coldspring.beans.DefaultXmlBeanFactory").init( defaultProperties="#fb_.defaultproperties#" )/>');
|
|---|
| 40 | fb_.i = 1;
|
|---|
| 41 | // load all bean definitions
|
|---|
| 42 | for ( fb_.i = 1; fb_.i lte arraylen( fb_.verbInfo.beans ); fb_.i = fb_.i + 1){
|
|---|
| 43 | fb_appendLine('<cfset myFusebox.getApplication().getApplicationData().#fb_.coldspringfactory#.loadBeansFromXmlFile( beanDefinitionFile="#fb_.verbInfo.beans[fb_.i]#" ) />');
|
|---|
| 44 | }
|
|---|
| 45 | }
|
|---|
| 46 | </cfscript> |
|---|