AppLoader

Package: MachII.framework
Responsible for controlling the loading/reloading of the AppManager.

<!--- License: Copyright 2008 GreatBizTools, LLC Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Copyright: GreatBizTools, LLC $Id: AppLoader.cfc 1087 2008-09-25 23:31:51Z peterfarrell $ Created version: 1.0.0 Updated version: 1.6.0 Notes: --->

Method Summary
public AppLoader init(string configPath, string dtdPath, string appKey, [boolean validateXml="false"], [any parentAppManager=""], [any overrideXml=""], [string moduleName=""])

Used by the framework for initialization. Do not override.

public AppFactory getAppFactory()
public any getAppKey()
public AppManager getAppManager()
private string getConfigFileReloadHash()

Get the current reload hash of the master config file and any include files which is based on dateLastModified and size.

public string getConfigPath()
public string getDtdPath()
public any getLastReloadDatetime()

Gets the last reload datetime for this module or base application.

public string getLastReloadHash()
public Log getLog()

Gets the log.

public any getModuleName()

Gets the module name

public any getOverrideXml()

Gets the override Xml for this module.

public boolean getValidateXML()
public void reloadConfig([boolean validateXml="false"], [any parentAppManager=""])

Reloads the config file and sets the last reload hash.

public void reloadModuleConfig([boolean validateXml="false"], [any parentAppManager=""])

Reloads the config file and sets the last reload hash.

public void setAppFactory(AppFactory appFactory)
public void setAppKey(string appkey)
public void setAppManager(AppManager appManager)
public void setConfigPath(string configPath)
public void setDtdPath(string dtdPath)
public void setLastReloadHash(string lastReloadHash)
private void setLog(LogFactory logFactory)

Uses the log factory to create a log.

public void setModuleName(string moduleName)

Sets the name of the module

public void setOverrideXml(any overrideXml)

Sets the override Xml for this module.

public void setValidateXML(boolean validateXML)
public boolean shouldReloadBaseConfig()

Determines if any of the base configuration files should be reloaded.

public boolean shouldReloadConfig()

Determines if the configuration file should be reloaded.

public boolean shouldReloadModuleConfig()

Determines if any of the module configuration files should be reloaded.

private void updateLastReloadDatetime()

Updates the last reload datetime for this module or base application.

Method Detail
getAppFactory

public AppFactory getAppFactory( )

Parameters:

Code:

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

getAppKey

public any getAppKey( )

Parameters:

Code:

	<cffunction name="getAppKey" access="public" type="string" output="false">
		<cfreturn variables.appkey />
	</cffunction> 

getAppManager

public AppManager getAppManager( )

Parameters:

Code:

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

getConfigFileReloadHash

private string getConfigFileReloadHash( )

Get the current reload hash of the master config file and any include files which is based on dateLastModified and size.

Parameters:

Code:

	<cffunction name="getConfigFileReloadHash" access="private" returntype="string" output="false"
		hint="Get the current reload hash of the master config file and any include files which is based on dateLastModified and size.">

		<cfset var configFilePaths = getAppFactory().getConfigFilePaths() />
		<cfset var directoryResults = "" />
		<cfset var hashableString = "" />
		<cfset var i = "" />

		<cfloop from="1" to="#ArrayLen(configFilePaths)#" index="i">
			<cfdirectory action="LIST" directory="#GetDirectoryFromPath(configFilePaths[i])#" 
				name="directoryResults" filter="#GetFileFromPath(configFilePaths[i])#" />
			<cfset hashableString = hashableString & directoryResults.dateLastModified & directoryResults.size />
		</cfloop>

		<cfreturn Hash(hashableString) />
	</cffunction> 

getConfigPath

public string getConfigPath( )

Parameters:

Code:

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

getDtdPath

public string getDtdPath( )

Parameters:

Code:

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

getLastReloadDatetime

public any getLastReloadDatetime( )

Gets the last reload datetime for this module or base application.

Parameters:

Code:

	<cffunction name="getLastReloadDatetime" access="public" type="date" output="false"
		hint="Gets the last reload datetime for this module or base application.">
		<cfreturn variables.lastReloadDatetime />
	</cffunction> 

getLastReloadHash

public string getLastReloadHash( )

Parameters:

Code:

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

getLog

public Log getLog( )

Gets the log.

Parameters:

Code:

	<cffunction name="getLog" access="public" returntype="MachII.logging.Log" output="false"
		hint="Gets the log.">
		<cfreturn variables.log />
	</cffunction> 

getModuleName

public any getModuleName( )

Gets the module name

Parameters:

Code:

	<cffunction name="getModuleName" access="public" type="string" output="false"
		hint="Gets the module name">
		<cfreturn variables.moduleName />
	</cffunction> 

getOverrideXml

public any getOverrideXml( )

Gets the override Xml for this module.

Parameters:

Code:

	<cffunction name="getOverrideXml" access="public" type="any" output="false"
		hint="Gets the override Xml for this module.">
		<cfreturn variables.overrideXml />
	</cffunction> 

getValidateXML

public boolean getValidateXML( )

Parameters:

Code:

	<cffunction name="getValidateXML" access="public" returntype="boolean" output="false">
		<cfreturn variables.validateXML />
	</cffunction> 

init

public AppLoader init( string configPath, string dtdPath, string appKey, [boolean validateXml="false"], [any parentAppManager=""], [any overrideXml=""], [string moduleName=""] )

Used by the framework for initialization. Do not override.

Parameters:
string configPath
string dtdPath
string appKey
[boolean validateXml="false"]
[any parentAppManager=""]
[any overrideXml=""]
[string moduleName=""]

Code:

	<cffunction name="init" access="public" returntype="MachII.framework.AppLoader" output="false"
		hint="Used by the framework for initialization. Do not override.">
		<cfargument name="configPath" type="string" required="true"
			hint="The full path to the configuration XML file." />
		<cfargument name="dtdPath" type="string" required="true"
			hint="The full path to the Mach-II DTD file." />
		<cfargument name="appKey" type="string" required="true"
			hint="Unqiue key for this application.">
		<cfargument name="validateXml" type="boolean" required="false" default="false"
			hint="Should the XML be validated before parsing." />
		<cfargument name="parentAppManager" type="any" required="false" default=""
			hint="Optional argument for a parent app manager. If there isn't one default to empty string." />
		<cfargument name="overrideXml" type="any" required="false" default=""
			hint="Optional argument for override Xml for a module. Default to empty string." />
		<cfargument name="moduleName" type="string" required="false" default=""
			hint="Optional argument for the name of a module. Defaults to empty string." />
		
		<cfset var appFactory = CreateObject("component", "MachII.framework.AppFactory").init() />
		
		<cfset setAppFactory(appFactory) />

		<cfset setConfigPath(arguments.configPath) />
		<cfset setDtdPath(arguments.dtdPath) />
		<cfset setValidateXml(arguments.validateXml) />
		<cfset setOverrideXml(arguments.overrideXml) />
		<cfset setModuleName(arguments.moduleName) />
		<cfset setAppKey(arguments.appKey) />
		
		
		<cfset reloadConfig(arguments.validateXml, arguments.parentAppManager) />
		
		<cfreturn this />
	</cffunction> 

reloadConfig

public void reloadConfig( [boolean validateXml="false"], [any parentAppManager=""] )

Reloads the config file and sets the last reload hash.

Parameters:
[boolean validateXml="false"]
[any parentAppManager=""]

Code:

	<cffunction name="reloadConfig" access="public" returntype="void" output="false"
		hint="Reloads the config file and sets the last reload hash.">
		<cfargument name="validateXml" type="boolean" required="false" default="false"
			hint="Should the XML be validated before parsing." />
		<cfargument name="parentAppManager" type="any" required="false" default=""
			hint="Optional argument for a parent app manager. If there isn't one default to empty string." />

		<cfset updateLastReloadDatetime() />		
		<cfset setAppManager(getAppFactory().createAppManager(getConfigPath(), getDtdPath(), 
				getAppKey(), getValidateXml(), arguments.parentAppManager, getOverrideXml(), getModuleName())) />
		<cfset getAppManager().setAppLoader(this) />
		<cfset setLastReloadHash(getConfigFileReloadHash()) />
		<cfset setLog(getAppManager().getLogFactory()) />
	</cffunction> 

reloadModuleConfig

public void reloadModuleConfig( [boolean validateXml="false"], [any parentAppManager=""] )

Reloads the config file and sets the last reload hash.

Parameters:
[boolean validateXml="false"]
[any parentAppManager=""]

Code:

	<cffunction name="reloadModuleConfig" access="public" returntype="void" output="false"
		hint="Reloads the config file and sets the last reload hash.">
		<cfargument name="validateXml" type="boolean" required="false" default="false"
			hint="Should the XML be validated before parsing." />
		<cfargument name="parentAppManager" type="any" required="false" default=""
			hint="Optional argument for a parent app manager. If there isn't one default to empty string." />

		<cfset var modules = getAppManager().getModuleManager().getModules() />
		<cfset var module = 0 />
		
		
		<cfif NOT IsObject(getAppManager().getParent())>
			<cfloop collection="#modules#" item="module">
				<cfif modules[module].shouldReloadConfig()>
					<cfset modules[module].shouldReloadConfig() />
				</cfif>
			</cfloop>
		</cfif>
	</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> 

setAppKey

public void setAppKey( string appkey )

Parameters:
string appkey

Code:

	<cffunction name="setAppKey" access="public" returntype="void" output="false">
		<cfargument name="appkey" type="string" required="true" />
		<cfset variables.appkey = arguments.appkey />
	</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> 

setDtdPath

public void setDtdPath( string dtdPath )

Parameters:
string dtdPath

Code:

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

setLastReloadHash

public void setLastReloadHash( string lastReloadHash )

Parameters:
string lastReloadHash

Code:

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

setLog

private void setLog( LogFactory logFactory )

Uses the log factory to create a log.

Parameters:
LogFactory logFactory

Code:

	<cffunction name="setLog" access="private" returntype="void" output="false"
		hint="Uses the log factory to create a log.">
		<cfargument name="logFactory" type="MachII.logging.LogFactory" required="true" />
		<cfset variables.log = arguments.logFactory.getLog(getMetadata(this).name) />
	</cffunction> 

setModuleName

public void setModuleName( string moduleName )

Sets the name of the module

Parameters:
string moduleName

Code:

	<cffunction name="setModuleName" access="public" returntype="void" output="false"
		hint="Sets the name of the module">
		<cfargument name="moduleName" type="string" required="true" />
		<cfset variables.moduleName = arguments.moduleName />
	</cffunction> 

setOverrideXml

public void setOverrideXml( any overrideXml )

Sets the override Xml for this module.

Parameters:
any overrideXml

Code:

	<cffunction name="setOverrideXml" access="public" returntype="void" output="false"
		hint="Sets the override Xml for this module.">
		<cfargument name="overrideXml" type="any" required="true" />
		<cfset variables.overrideXml = arguments.overrideXml />
	</cffunction> 

setValidateXML

public void setValidateXML( boolean validateXML )

Parameters:
boolean validateXML

Code:

	<cffunction name="setValidateXML" access="public" returntype="void" output="false">
		<cfargument name="validateXML" type="boolean" required="true" />
		<cfset variables.validateXML = arguments.validateXML />
	</cffunction> 

shouldReloadBaseConfig

public boolean shouldReloadBaseConfig( )

Determines if any of the base configuration files should be reloaded.

Parameters:

Code:

	<cffunction name="shouldReloadBaseConfig" access="public" returntype="boolean" output="false"
		hint="Determines if any of the base configuration files should be reloaded.">
		
		<cfset var result = false />
		
		<cfif CompareNoCase(getLastReloadHash(), getConfigFileReloadHash()) NEQ 0>
			<cfset result = true />
		</cfif>
		
		<cfreturn result />
	</cffunction> 

shouldReloadConfig

public boolean shouldReloadConfig( )

Determines if the configuration file should be reloaded.

Parameters:

Code:

	<cffunction name="shouldReloadConfig" access="public" returntype="boolean" output="false"
		hint="Determines if the configuration file should be reloaded.">
		
		<cfset var result = false />
		
		<cfif shouldReloadBaseConfig() OR shouldReloadModuleConfig()>
			<cfset result = true />
		</cfif>
		
		<cfreturn result />
	</cffunction> 

shouldReloadModuleConfig

public boolean shouldReloadModuleConfig( )

Determines if any of the module configuration files should be reloaded.

Parameters:

Code:

	<cffunction name="shouldReloadModuleConfig" access="public" returntype="boolean" output="false"
		hint="Determines if any of the module configuration files should be reloaded.">

		<cfset var modules = getAppManager().getModuleManager().getModules() />
		<cfset var module = 0 />
		<cfset var result = false />
		
		
		<cfif NOT IsObject(getAppManager().getParent())>
			<cfloop collection="#modules#" item="module">
				<cfif modules[module].shouldReloadConfig()>
					<cfset result = true />
					<cfbreak />
				</cfif>
			</cfloop>
		</cfif>
		
		<cfreturn result />
	</cffunction> 

updateLastReloadDatetime

private void updateLastReloadDatetime( )

Updates the last reload datetime for this module or base application.

Parameters:

Code:

	<cffunction name="updateLastReloadDatetime" access="private" returntype="void" output="false"
		hint="Updates the last reload datetime for this module or base application.">
		<cfset variables.lastReloadDatetime = Now() />
	</cffunction>