AppLoader

Package: MachII.framework
Responsible for controlling loading/reloading of the AppManager.
Method Summary
public AppLoader init(string configPath)
public AppFactory getAppFactory()
public AppManager getAppManager()
public string getConfigPath()
public date getLastReloadDate()
public void reloadConfig()
public void setAppFactory(AppFactory appFactory)
public void setAppManager(AppManager appManager)
public void setConfigPath(string configPath)
public void setLastReloadDate(date lastReloadDate)
public boolean shouldReloadConfig()
Method Detail
getAppFactory

public AppFactory getAppFactory( )

Parameters:

Code:

	<cffunction name="getAppFactory" access="public" returntype="MachII.framework.AppFactory" output="false">
		<cfreturn variables.appFactory />
	</cffunction> 

getAppManager

public AppManager getAppManager( )

Parameters:

Code:

	<cffunction name="getAppManager" access="public" returntype="MachII.framework.AppManager" output="false">
		<cfreturn variables.appManager />
	</cffunction> 

getConfigPath

public string getConfigPath( )

Parameters:

Code:

	<cffunction name="getConfigPath" access="public" returntype="string" output="false">
		<cfreturn variables.configPath />
	</cffunction> 

getLastReloadDate

public date getLastReloadDate( )

Parameters:

Code:

	<cffunction name="getLastReloadDate" access="public" returntype="date" output="false">
		<cfreturn variables.lastReloadDate />
	</cffunction> 

init

public AppLoader init( string configPath )

Parameters:
string configPath

Code:

	<cffunction name="init" access="public" returntype="MachII.framework.AppLoader" output="true">
		<cfargument name="configPath" type="string" required="true" />
		
		<cfset var appFactory = CreateObject('component', 'MachII.framework.AppFactory') />
		<cfset appFactory.init() />
		<cfset setAppFactory(appFactory) />
		
		<cfset setConfigPath(arguments.configPath) />
		<cfset reloadConfig() />
		

		<cfreturn this />
	</cffunction> 

reloadConfig

public void reloadConfig( )

Parameters:

Code:

	<cffunction name="reloadConfig" access="public" returntype="void">
		<cfset var appFactory = getAppFactory() />
		<cfset setAppManager(appFactory.createAppManager(getConfigPath())) />
		<cfset setLastReloadDate(Now()) />
	</cffunction> 

setAppFactory

public void setAppFactory( AppFactory appFactory )

Parameters:
AppFactory appFactory

Code:

	<cffunction name="setAppFactory" access="public" returntype="void" output="false">
		<cfargument name="appFactory" type="MachII.framework.AppFactory" required="true" />
		<cfset variables.appFactory = arguments.appFactory />
	</cffunction> 

setAppManager

public void setAppManager( AppManager appManager )

Parameters:
AppManager appManager

Code:

	<cffunction name="setAppManager" access="public" returntype="void" output="false">
		<cfargument name="appManager" type="MachII.framework.AppManager" required="true" />
		<cfset variables.appManager = arguments.appManager />
	</cffunction> 

setConfigPath

public void setConfigPath( string configPath )

Parameters:
string configPath

Code:

	<cffunction name="setConfigPath" access="public" returntype="void" output="false">
		<cfargument name="configPath" type="string" required="true" />
		<cfset variables.configPath = arguments.configPath />
	</cffunction> 

setLastReloadDate

public void setLastReloadDate( date lastReloadDate )

Parameters:
date lastReloadDate

Code:

	<cffunction name="setLastReloadDate" access="public" returntype="void" output="false">
		<cfargument name="lastReloadDate" type="date" required="true" />
		<cfset variables.lastReloadDate = arguments.lastReloadDate />
	</cffunction> 

shouldReloadConfig

public boolean shouldReloadConfig( )

Parameters:

Code:

	<cffunction name="shouldReloadConfig" access="public" returntype="boolean" output="false">
		
		<cfset var lastConfigDate = 0 />
		<cfset var configFile = "" />
		<cfset var shouldReload = true />
		
		<cfdirectory action="LIST" directory="#GetDirectoryFromPath(getConfigPath())#" 
			name="configFile" filter="#GetFileFromPath(getConfigPath())#" />
		
		<cfset lastConfigDate = ParseDateTime(configFile.dateLastModified) />
		<cfswitch expression="#DateCompare(getLastReloadDate(), lastConfigDate)#">
			<cfcase value="-1"><cfset shouldReload = true /></cfcase>
			<cfcase value="0"><cfset shouldReload = false /></cfcase>
			<cfcase value="1"><cfset shouldReload = false /></cfcase>
		</cfswitch>
		
		<cfreturn shouldReload />
	</cffunction>