| Package: MachII.framework |
| Manages registered modules for the framework instance. |
<!--- 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 Author: Kurt Wiersma (kurt@mach-ii.com) $Id: ModuleManager.cfc 827 2008-06-18 08:21:31Z peterfarrell $ Created version: 1.5.0 Updated version: 1.5.0 Notes: ---> |
| 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 | 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 | 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 variables.modules[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>
| 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 = ArrayNew(1) />
<cfset var modulesNode = "" />
<cfset var modulesNodes = "" />
<cfset var module = "" />
<cfset var name = "" />
<cfset var file = "" />
<cfset var overrideXml = "" />
<cfset var i = 0 />
<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>
| 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>