| 1 | <!----------------------------------------------------------------------- |
|---|
| 2 | ******************************************************************************** |
|---|
| 3 | Copyright 2005-2008 ColdBox Framework by Luis Majano and Ortus Solutions, Corp |
|---|
| 4 | www.coldboxframework.com | www.luismajano.com | www.ortussolutions.com |
|---|
| 5 | ******************************************************************************** |
|---|
| 6 | |
|---|
| 7 | Author : Luis Majano |
|---|
| 8 | Date : January 18, 2007 |
|---|
| 9 | Description : |
|---|
| 10 | This cfc takes care of debugging settings. |
|---|
| 11 | |
|---|
| 12 | Modification History: |
|---|
| 13 | 01/18/2007 - Created |
|---|
| 14 | -----------------------------------------------------------------------> |
|---|
| 15 | <cfcomponent name="LoaderService" output="false" hint="The application and framework loader service" extends="coldbox.system.services.BaseService"> |
|---|
| 16 | |
|---|
| 17 | <!------------------------------------------- CONSTRUCTOR -------------------------------------------> |
|---|
| 18 | |
|---|
| 19 | <cffunction name="init" access="public" output="false" returntype="LoaderService" hint="Constructor"> |
|---|
| 20 | <cfargument name="controller" type="any" required="true"> |
|---|
| 21 | <cfscript> |
|---|
| 22 | setController(arguments.controller); |
|---|
| 23 | return this; |
|---|
| 24 | </cfscript> |
|---|
| 25 | </cffunction> |
|---|
| 26 | |
|---|
| 27 | <!------------------------------------------- PUBLIC -------------------------------------------> |
|---|
| 28 | |
|---|
| 29 | <!--- Setup Calls ---> |
|---|
| 30 | <cffunction name="setupCalls" returntype="void" access="public" hint="I execute the framework and application loading scripts" output="false"> |
|---|
| 31 | <!--- ************************************************************* ---> |
|---|
| 32 | <cfargument name="overrideConfigFile" type="string" required="false" default="" hint="Only used for unit testing or reparsing of a specific coldbox config file."> |
|---|
| 33 | <cfargument name="overrideAppMapping" type="string" required="false" default="" hint="Only used for unit testing or reparsing of a specific coldbox config file."/> |
|---|
| 34 | <!--- ************************************************************* ---> |
|---|
| 35 | <cfscript> |
|---|
| 36 | //execute the configLoader |
|---|
| 37 | configLoader(argumentCollection=arguments); |
|---|
| 38 | //execute the handler registrations after configurations loaded |
|---|
| 39 | getController().getHandlerService().registerHandlers(); |
|---|
| 40 | </cfscript> |
|---|
| 41 | </cffunction> |
|---|
| 42 | |
|---|
| 43 | <!--- Config Loader Method ---> |
|---|
| 44 | <cffunction name="configLoader" returntype="void" access="Public" hint="I Load the configurations only, init the framework variables and more." output="false"> |
|---|
| 45 | <!--- ************************************************************* ---> |
|---|
| 46 | <cfargument name="overrideConfigFile" required="false" type="string" default="" hint="Only used for unit testing or reparsing of a specific coldbox config file."> |
|---|
| 47 | <cfargument name="overrideAppMapping" type="string" required="false" default="" hint="Only used for unit testing or reparsing of a specific coldbox config file."/> |
|---|
| 48 | <!--- ************************************************************* ---> |
|---|
| 49 | <cfscript> |
|---|
| 50 | var XMLParser = ""; |
|---|
| 51 | var CacheConfigBean = CreateObject("Component","coldbox.system.cache.config.CacheConfigBean"); |
|---|
| 52 | var DebuggerConfigBean = CreateObject("Component","coldbox.system.beans.debuggerConfigBean"); |
|---|
| 53 | var FrameworkSettings = structNew(); |
|---|
| 54 | var ConfigSettings = structNew(); |
|---|
| 55 | |
|---|
| 56 | /* Clear the Cache Dictionaries */ |
|---|
| 57 | controller.getPluginService().clearDictionary(); |
|---|
| 58 | controller.getHandlerService().clearDictionaries(); |
|---|
| 59 | |
|---|
| 60 | //Prepare Parser |
|---|
| 61 | XMLParser = controller.getPlugin("XMLParser"); |
|---|
| 62 | |
|---|
| 63 | //Load Coldbox Config Settings Structure |
|---|
| 64 | FrameworkSettings = XMLParser.loadFramework(arguments.overrideConfigFile); |
|---|
| 65 | controller.setColdboxSettings(FrameworkSettings); |
|---|
| 66 | |
|---|
| 67 | //Create the Cache Config Bean with data from the framework's settings.xml |
|---|
| 68 | CacheConfigBean.populate(FrameworkSettings); |
|---|
| 69 | //Configure the Object Cache for first usage. |
|---|
| 70 | controller.getColdboxOCM().configure(CacheConfigBean); |
|---|
| 71 | |
|---|
| 72 | //Load Application Config Settings Now that framework has been loaded. |
|---|
| 73 | ConfigSettings = XMLParser.parseConfig(arguments.overrideAppMapping); |
|---|
| 74 | controller.setConfigSettings(ConfigSettings); |
|---|
| 75 | |
|---|
| 76 | //Check for Cache OVerride Settings in Config |
|---|
| 77 | if ( ConfigSettings.CacheSettings.OVERRIDE ){ |
|---|
| 78 | //Recreate the Config Bean |
|---|
| 79 | CacheConfigBean = CacheConfigBean.init(ConfigSettings.CacheSettings.ObjectDefaultTimeout, |
|---|
| 80 | ConfigSettings.CacheSettings.ObjectDefaultLastAccessTimeout, |
|---|
| 81 | ConfigSettings.CacheSettings.ReapFrequency, |
|---|
| 82 | ConfigSettings.CacheSettings.MaxObjects, |
|---|
| 83 | ConfigSettings.CacheSettings.FreeMemoryPercentageThreshold, |
|---|
| 84 | ConfigSettings.CacheSettings.UseLastAccessTimeouts, |
|---|
| 85 | ConfigSettings.CacheSettings.EvictionPolicy); |
|---|
| 86 | //Re-Configure the Object Cache. |
|---|
| 87 | controller.getColdboxOCM().configure(CacheConfigBean); |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | /* Populate Debugger with settings from the framework */ |
|---|
| 91 | DebuggerConfigBean.populate(FrameworkSettings); |
|---|
| 92 | |
|---|
| 93 | /* Check for Debugger Override, if true, then overpopulate with configuration settings overriding framework settings. */ |
|---|
| 94 | if( ConfigSettings.DebuggerSettings.OVERRIDE ){ |
|---|
| 95 | DebuggerConfigBean.populate(ConfigSettings.DebuggerSettings); |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | /* Configure the Debugger with framework wide settings.*/ |
|---|
| 99 | controller.getDebuggerService().setDebuggerConfigBean(DebuggerConfigBean); |
|---|
| 100 | |
|---|
| 101 | /* Register The Interceptors */ |
|---|
| 102 | controller.getInterceptorService().registerInterceptors(); |
|---|
| 103 | |
|---|
| 104 | /* Flag the initiation, Framework is ready to serve requests. Praise be to GOD. */ |
|---|
| 105 | controller.setColdboxInitiated(true); |
|---|
| 106 | |
|---|
| 107 | /* Execute afterConfigurationLoad */ |
|---|
| 108 | controller.getInterceptorService().processState("afterConfigurationLoad"); |
|---|
| 109 | |
|---|
| 110 | /* Register Aspects */ |
|---|
| 111 | registerAspects(); |
|---|
| 112 | |
|---|
| 113 | /* Execute afterAspectsLoad */ |
|---|
| 114 | controller.getInterceptorService().processState("afterAspectsLoad"); |
|---|
| 115 | </cfscript> |
|---|
| 116 | </cffunction> |
|---|
| 117 | |
|---|
| 118 | <!--- Register the Aspects ---> |
|---|
| 119 | <cffunction name="registerAspects" access="public" returntype="void" hint="I Register the current Application's Aspects" output="false" > |
|---|
| 120 | <cfscript> |
|---|
| 121 | /* Initialize Logging if requested. */ |
|---|
| 122 | if ( controller.getSetting("EnableColdboxLogging") ){ |
|---|
| 123 | controller.getPlugin("logger").initLogLocation(); |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | /* IoC Plugin Manager Configuration */ |
|---|
| 127 | if ( controller.getSetting("IOCFramework") neq "" ){ |
|---|
| 128 | //Create IoC Factory and configure it. |
|---|
| 129 | controller.getPlugin("ioc").configure(); |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | /* Load i18N if application is using it. */ |
|---|
| 133 | if ( controller.getSetting("using_i18N") ){ |
|---|
| 134 | //Create i18n Plugin and configure it. |
|---|
| 135 | controller.getPlugin("i18n").init_i18N(controller.getSetting("DefaultResourceBundle"),controller.getSetting("DefaultLocale")); |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | /* Set Debugging Mode according to configuration File */ |
|---|
| 139 | controller.getDebuggerService().setDebugMode(controller.getSetting("DebugMode")); |
|---|
| 140 | |
|---|
| 141 | /* Flag the aspects inited. */ |
|---|
| 142 | controller.setAspectsInitiated(true); |
|---|
| 143 | </cfscript> |
|---|
| 144 | </cffunction> |
|---|
| 145 | |
|---|
| 146 | <!------------------------------------------- PRIVATE -------------------------------------------> |
|---|
| 147 | |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | </cfcomponent> |
|---|