root/coldbox/trunk/src/system/services/loaderService.cfc @ 867

Revision 867, 7.7 kB (checked in by lmajano, 6 years ago)

updates.

Line 
1<!-----------------------------------------------------------------------
2********************************************************************************
3Copyright 2005-2007 ColdBox Framework by Luis Majano and Ortus Solutions, Corp
4www.coldboxframework.com | www.luismajano.com | www.ortussolutions.com
5********************************************************************************
6
7Author      :   Luis Majano
8Date        :   January 18, 2007
9Description :
10        This cfc takes care of debugging settings.
11
12Modification History:
1301/18/2007 - Created
14----------------------------------------------------------------------->
15<cfcomponent name="loaderService" output="false" hint="The application and framework loader service" extends="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 configuration and loading.." output="false">
31                <cfargument name="overrideConfigFile" type="string" required="false" default="" hint="Only used for unit testing or reparsing of a specific coldbox config file.">
32                <cfargument name="overrideAppMapping" type="string" required="false" default="" hint="Only used for unit testing or reparsing of a specific coldbox config file."/>
33                <cfscript>
34                        //execute the configLoader
35                        configLoader(arguments.overrideConfigFile, arguments.overrideAppMapping);
36                        //execute the handler registrations
37                        registerHandlers();
38                </cfscript>
39        </cffunction>
40
41        <!--- Config Loader Method --->
42        <cffunction name="configLoader" returntype="void" access="Public" hint="I Load the configurations and init the framework variables." output="false">
43                <cfargument name="overrideConfigFile" required="false" type="string" default="" hint="Only used for unit testing or reparsing of a specific coldbox config file.">
44                <cfargument name="overrideAppMapping" type="string" required="false" default="" hint="Only used for unit testing or reparsing of a specific coldbox config file."/>
45                <cfscript>
46                var XMLParser = controller.getPlugin("XMLParser");
47                var CacheConfigBean = CreateObject("Component","coldbox.system.beans.cacheConfigBean");
48                var FrameworkSettings = structNew();
49                var ConfigSettings = structNew();
50
51                //Load Coldbox Config Settings Structure
52                FrameworkSettings = XMLParser.loadFramework(arguments.overrideConfigFile);
53                controller.setColdboxSettings(FrameworkSettings);
54
55                //Create the Cache Config Bean with data from the settings.xml
56                CacheConfigBean = CacheConfigBean.init(FrameworkSettings.CacheObjectDefaultTimeout,
57                                                                                           FrameworkSettings.CacheObjectDefaultLastAccessTimeout,
58                                                                                           FrameworkSettings.CacheReapFrequency,
59                                                                                           FrameworkSettings.CacheMaxObjects,
60                                                                                           FrameworkSettings.CacheFreeMemoryPercentageThreshold);
61                //Configure the Object Cache.
62                controller.getColdboxOCM().configure(CacheConfigBean);
63
64                //Load Application Config Settings
65                ConfigSettings =XMLParser.parseConfig(arguments.overrideAppMapping);
66                controller.setConfigSettings(ConfigSettings);
67                //Check for Cache OVerride Settings
68                if ( ConfigSettings.CacheSettings.OVERRIDE ){
69                        //Recreate the Config Bean
70                        CacheConfigBean = CacheConfigBean.init(ConfigSettings.CacheSettings.ObjectDefaultTimeout,
71                                                                                           ConfigSettings.CacheSettings.ObjectDefaultLastAccessTimeout,
72                                                                                           ConfigSettings.CacheSettings.ReapFrequency,
73                                                                                           ConfigSettings.CacheSettings.MaxObjects,
74                                                                                           ConfigSettings.CacheSettings.FreeMemoryPercentageThreshold);
75                        //Re-Configure the Object Cache.
76                        controller.getColdboxOCM().configure(CacheConfigBean);
77                }
78                //IoC Plugin Manager
79                if ( ConfigSettings.IOCFramework neq "" ){
80                        //Create IoC Factory and configure it.
81                        controller.getPlugin("ioc").configure();
82                }
83
84                //Load i18N if application is using it.
85                if ( ConfigSettings.using_i18N ){
86                        //Create i18n Plugin and configure it.
87                        controller.getPlugin("i18n").init_i18N(ConfigSettings.DefaultResourceBundle,ConfigSettings.DefaultLocale);
88                }
89
90                //Initialize AOP Logging if requested.
91                if ( ConfigSettings.EnableColdboxLogging ){
92                        controller.getPlugin("logger").initLogLocation();
93                }
94
95                //Set Debugging Mode according to configuration
96                controller.getDebuggerService().setDebugMode(ConfigSettings.DebugMode);
97
98                // Flag the initiation, Framework is ready to serve requests. Praise be to GOD.
99                controller.setColdboxInitiated(true);
100                </cfscript>
101        </cffunction>
102
103        <!--- Handler Registration System --->
104        <cffunction name="registerHandlers" access="public" returntype="void" hint="I register your application's event handlers" output="false">
105                <cfscript>
106                var HandlersPath = controller.getSetting("HandlersPath");
107                var HandlerArray = Arraynew(1);
108
109                //Check for Handlers Directory Location
110                if ( not directoryExists(HandlersPath) )
111                        controller.throw("The handlers directory: #handlerspath# does not exist please check your application structure or your Application Mapping.","","Framework.loaderService.HandlersDirectoryNotFoundException");
112
113                //Get recursive Array listing
114                HandlerArray = recurseListing(HandlerArray, HandlersPath, HandlersPath);
115
116                //Verify it
117                if ( ArrayLen(HandlerArray) eq 0 )
118                        controller.throw("No handlers were found in: #HandlerPath#. So I have no clue how you are going to run this application.","","Framework.loaderService.NoHandlersFoundException");
119
120                //Sort The Array
121                ArraySort(HandlerArray,"text");
122
123                //Set registered Handlers
124                controller.setSetting("RegisteredHandlers",arrayToList(HandlerArray));
125                </cfscript>
126        </cffunction>
127       
128<!------------------------------------------- PRIVATE ------------------------------------------->
129
130        <cffunction name="recurseListing" access="private" output="false" returntype="array">
131                <cfargument name="fileArray" type="array"  required="true">
132                <cfargument name="Directory" type="string" required="true">
133                <cfargument name="HandlersPath" type="string" required="true">
134                <cfscript>
135                var oDirectory = CreateObject("java","java.io.File").init(arguments.Directory);
136                var Files = oDirectory.list();
137                var i = 1;
138                var tempfile = "";
139                var cleanHandler = "";
140
141                //Loop Through listing if any files found.
142                for ( i=1; i lte arrayLen(Files); i=i+1 ){
143                        //get first reference as File Object
144                        tempFile = CreateObject("java","java.io.File").init(oDirectory,Files[i]);
145                        //Directory Check for recursion
146                        if ( tempFile.isDirectory() ){
147                                //recurse, directory found.
148                                arguments.fileArray = recurseListing(arguments.fileArray,tempFile.getPath(), arguments.HandlersPath);
149                        }
150                        else{
151                                //Filter only cfc's
152                                if ( listlast(tempFile.getName(),".") neq "cfc" )
153                                        continue;
154                                //Clean entry by using Handler Path
155                                cleanHandler = replacenocase(tempFile.getAbsolutePath(),arguments.handlersPath,"","all");
156                                //Clean OS separators
157                                if ( controller.getSetting("OSFileSeparator",1) eq "/")
158                                        cleanHandler = removeChars(replacenocase(cleanHandler,"/",".","all"),1,1);
159                                else
160                                        cleanHandler = removeChars(replacenocase(cleanHandler,"\",".","all"),1,1);
161                                //Clean Extension
162                                cleanHandler = controller.getPlugin("fileUtilities").ripExtension(cleanhandler);
163                                //Add data to array
164                                ArrayAppend(arguments.fileArray,cleanHandler);
165                        }
166                }
167                return arguments.fileArray;
168                </cfscript>
169        </cffunction>
170
171</cfcomponent>
Note: See TracBrowser for help on using the browser.