ModuleManager

Package: MachII.framework
Manages registered modules for the framework instance.
Method Summary
public ModuleManager init(AppManager appManager, string baseConfigFileDirectory, string configDtdPath, [boolean validateXml="false"])

Initialization function called by the framework.

public void addModule(string moduleName, Module module, [boolean override="false"])

Registers a module with the specified name.

public void configure()

Configures each of the registered modules.

public AppManager getAppManager()

Sets the AppManager instance this ModuleManager belongs to.

public string getBaseConfigFileDirectory()
public string getBaseName()
public string getDtdPath()
public Module getModule(string moduleName)

Gets a module with the specified name.

public array getModuleNames()

Returns an array of module names.

public struct getModules()

Returns a struct of all registered modules.

public boolean getValidateXML()
public boolean isModuleDefined(string moduleName)

Returns true if a module is registered with the specified name.

public void loadXml(string configXml, [boolean override="false"])

Loads xml for the manager

public void setAppManager(AppManager appManager)

Returns the AppManager instance this ModuleManager belongs to.

public void setBaseConfigFileDirectory(string baseConfigFileDirectory)
public void setBaseName(string baseName)
public void setDtdPath(string dtdPath)
public void setValidateXML(string validateXML)
Method Detail
addModule

public void addModule( string moduleName, Module module, [boolean override="false"] )

Registers a module with the specified name.

Parameters:
string moduleName
Module module
[boolean override="false"]

Code:

	<cffunction name="addModule" access="public" returntype="void" output="false"
		hint="Registers a module with the specified name.">
		<cfargument name="moduleName" type="string" required="true" />
		<cfargument name="module" type="MachII.framework.Module" required="true" />
		<cfargument name="override" type="boolean" required="false" default="false" />
		
		<cfif NOT arguments.override AND isModuleDefined(arguments.moduleName)>
			<cfthrow type="MachII.framework.ModuleAlreadyDefined"
				message="A Module with name '#arguments.moduleName#' is already registered." />
		<cfelse>
			<cfset variables.modules[arguments.moduleName] = arguments.module />
		</cfif>
	</cffunction> 

configure

public void configure( )

Configures each of the registered modules.

Parameters:

Code:

	<cffunction name="configure" access="public" returntype="void" output="false"
		hint="Configures each of the registered modules.">
		<cfset var key = "" />
		<cfloop collection="#variables.modules#" item="key">
			<cfset getModule(key).configure(getDtdPath(), getValidateXML()) />
		</cfloop>
	</cffunction> 

getAppManager

public AppManager getAppManager( )

Sets the AppManager instance this ModuleManager belongs to.

Parameters:

Code:

	<cffunction name="getAppManager" access="public" returntype="MachII.framework.AppManager" output="false"
		hint="Sets the AppManager instance this ModuleManager belongs to.">
		<cfreturn variables.appManager />
	</cffunction> 

getBaseConfigFileDirectory

public string getBaseConfigFileDirectory( )

Parameters:

Code:

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

getBaseName

public string getBaseName( )

Parameters:

Code:

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

getDtdPath

public string getDtdPath( )

Parameters:

Code:

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

getModule

public Module getModule( string moduleName )

Gets a module with the specified name.

Parameters:
string moduleName

Code:

	<cffunction name="getModule" access="public" returntype="MachII.framework.Module" output="false"
		hint="Gets a module with the specified name.">
		<cfargument name="moduleName" type="string" required="true" />
		
		<cfif isModuleDefined(arguments.moduleName)>
			<cfreturn variables.modules[arguments.moduleName] />
		<cfelse>
			<cfthrow type="MachII.framework.ModuleNotDefined" 
				message="Module with name '#arguments.moduleName#' is not defined." />
		</cfif>
	</cffunction> 

getModuleNames

public array getModuleNames( )

Returns an array of module names.

Parameters:

Code:

	<cffunction name="getModuleNames" access="public" returntype="array" output="false"
		hint="Returns an array of module names.">
		<cfreturn StructKeyArray(variables.modules) />
	</cffunction> 

getModules

public struct getModules( )

Returns a struct of all registered modules.

Parameters:

Code:

	<cffunction name="getModules" access="public" returntype="struct" output="false"
		hint="Returns a struct of all registered modules.">
		<cfreturn variables.modules />
	</cffunction> 

getValidateXML

public boolean getValidateXML( )

Parameters:

Code:

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

init

public ModuleManager init( AppManager appManager, string baseConfigFileDirectory, string configDtdPath, [boolean validateXml="false"] )

Initialization function called by the framework.

Parameters:
AppManager appManager
string baseConfigFileDirectory
string configDtdPath
[boolean validateXml="false"]

Code:

	<cffunction name="init" access="public" returntype="ModuleManager" output="false"
		hint="Initialization function called by the framework.">
		<cfargument name="appManager" type="MachII.framework.AppManager" required="true" />
		<cfargument name="baseConfigFileDirectory" type="string" required="true"
			hint="The directory of the base config file. Required for relative path support resolution." />
		<cfargument name="configDtdPath" type="string" required="true"
		 	hint="The full path to the configuration DTD file." />
		<cfargument name="validateXml" type="boolean" required="false" default="false"
			hint="Should the XML be validated before parsing." />
		
		<cfset setAppManager(arguments.appManager) />
		<cfset setBaseConfigFileDirectory(arguments.baseConfigFileDirectory) />
		<cfset setDtdPath(arguments.configDtdPath) />
		<cfset setValidateXml(arguments.validateXml) />

		<cfreturn this />
	</cffunction> 

isModuleDefined

public boolean isModuleDefined( string moduleName )

Returns true if a module is registered with the specified name.

Parameters:
string moduleName

Code:

	<cffunction name="isModuleDefined" access="public" returntype="boolean" output="false"
		hint="Returns true if a module is registered with the specified name.">
		<cfargument name="moduleName" type="string" required="true" />
		<cfreturn StructKeyExists(variables.modules, arguments.moduleName) />
	</cffunction> 

loadXml

public void loadXml( string configXml, [boolean override="false"] )

Loads xml for the manager

Parameters:
string configXml
[boolean override="false"]

Code:

	<cffunction name="loadXml" access="public" returntype="void" output="false"
		hint="Loads xml for the manager">
		<cfargument name="configXml" type="string" required="true" />
		<cfargument name="override" type="boolean" required="false" default="false" />
		
		<cfset var moduleNodes = "" />
		<cfset var modulesNode = "" />
		<cfset var modulesNodes = "" />
		<cfset var name = "" />
		<cfset var file = "" />
		<cfset var module = "" />
		<cfset var overrideXml = "" />
		<cfset var baseName = "" />
		<cfset var i = 0 />

		
		<cfif NOT arguments.override>
			<cfset modulesNode = XMLSearch(arguments.configXML, "mach-ii/modules") />
		<cfelse>
			<cfset modulesNode = XMLSearch(arguments.configXML, ".//modules") />
		</cfif>
		<cfif arrayLen(modulesNode) eq 1>
			<cfset modulesNode = modulesNode[1]>
			<cfif structKeyExists(modulesNode[1].xmlAttributes, "baseName")>
				<cfset baseName = modulesNode[1].xmlAttributes["baseName"] />
			</cfif>
			<cfset setBaseName(baseName) />
		</cfif>
		
		
		<cfif NOT arguments.override>
			<cfset moduleNodes = XMLSearch(arguments.configXML, "mach-ii/modules/module") />
		<cfelse>
			<cfset moduleNodes = XMLSearch(arguments.configXML, ".//modules/module") />
		</cfif>
		<cfloop from="1" to="#ArrayLen(moduleNodes)#" index="i">
			<cfset name = moduleNodes[i].xmlAttributes["name"] />
			<cfset file = moduleNodes[i].xmlAttributes["file"] />
			
			
			<cfif Left(file, 1) IS ".">
				<cfset file = getAppManager().getUtils().expandRelativePath(getBaseConfigFileDirectory(), file) />
			<cfelse>
				<cfset file = ExpandPath(file) />
			</cfif>
			
			<cfif StructKeyExists(moduleNodes[i], "mach-ii")>
				<cfset overrideXml = moduleNodes[i]["mach-ii"] />
			<cfelse>
				<cfset overrideXml = "" />
			</cfif>
		
			
			<cfset module = CreateObject("component", "MachII.framework.Module").init(getAppManager(), name, file, overrideXml) />

			
			<cfset addModule(name, module, arguments.override) />
		</cfloop>
	</cffunction> 

setAppManager

public void setAppManager( AppManager appManager )

Returns the AppManager instance this ModuleManager belongs to.

Parameters:
AppManager appManager

Code:

	<cffunction name="setAppManager" access="public" returntype="void" output="false"
		hint="Returns the AppManager instance this ModuleManager belongs to.">
		<cfargument name="appManager" type="MachII.framework.AppManager" required="true" />
		<cfset variables.appManager = arguments.appManager />
	</cffunction> 

setBaseConfigFileDirectory

public void setBaseConfigFileDirectory( string baseConfigFileDirectory )

Parameters:
string baseConfigFileDirectory

Code:

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

setBaseName

public void setBaseName( string baseName )

Parameters:
string baseName

Code:

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

setValidateXML

public void setValidateXML( string validateXML )

Parameters:
string validateXML

Code:

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