CommandLoaderBase

Package: MachII.framework
Base component to load commands for the framework.

<!--- 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: Peter J. Farrell (peter@mach-ii.com) $Id: CommandLoaderBase.cfc 774 2008-05-11 04:00:35Z peterfarrell $ Created version: 1.5.0 Updated version: 1.6.0 Notes: --->

Method Summary
public void init()

Initialization function called by the framework.

private Command createCommand(any commandNode, [string parentHandlerName=""], [string parentHandlerType=""])
private AnnounceCommand setupAnnounce(any commandNode)

Sets up an announce command.

private CacheCommand setupCache(any commandNode, [string parentHandlerName=""], [string parentHandlerType=""])

Sets up a cache command.

private CacheClearCommand setupCacheClear(any commandNode)

Sets up a CacheClear command.

private Command setupDefault()

Sets up a default command.

private EventArgCommand setupEventArg(any commandNode)

Sets up an event-arg command.

private EventBeanCommand setupEventBean(any commandNode)

Sets up a event-bean command.

private EventMappingCommand setupEventMapping(any commandNode)

Sets up an event-mapping command.

private ExecuteCommand setupExecute(any commandNode)

Sets up an execute command.

private FilterCommand setupFilter(any commandNode)

Sets up a filter command.

private NotifyCommand setupNotify(any commandNode)

Sets up a notify command.

private PublishCommand setupPublish(any commandNode)

Sets up a publish command.

private RedirectCommand setupRedirect(any commandNode)

Sets up a redirect command.

private ViewPageCommand setupViewPage(any commandNode)

Sets up a view-page command.

Method Detail
createCommand

private Command createCommand( any commandNode, [string parentHandlerName=""], [string parentHandlerType=""] )

Parameters:
any commandNode
[string parentHandlerName=""]
[string parentHandlerType=""]

Code:

	<cffunction name="createCommand" access="private" returntype="MachII.framework.Command" output="false">
		<cfargument name="commandNode" type="any" required="true" />
		<cfargument name="parentHandlerName" type="string" required="false" default="" />
		<cfargument name="parentHandlerType" type="string" required="false" default="" />
		
		<cfset var command = "" />

		
		
		<cfif arguments.commandNode.xmlName EQ "view-page">
			<cfset command = setupViewPage(arguments.commandNode) />
		
		<cfelseif arguments.commandNode.xmlName EQ "notify">
			<cfset command = setupNotify(arguments.commandNode) />
		
		<cfelseif arguments.commandNode.xmlName EQ "announce">
			<cfset command = setupAnnounce(arguments.commandNode) />
		
		<cfelseif arguments.commandNode.xmlName EQ "publish">
			<cfset command = setupPublish(arguments.commandNode) />
		
		<cfelseif arguments.commandNode.xmlName EQ "event-mapping">
			<cfset command = setupEventMapping(arguments.commandNode) />
		
		<cfelseif arguments.commandNode.xmlName EQ "execute">
			<cfset command = setupExecute(arguments.commandNode) />
		
		<cfelseif arguments.commandNode.xmlName EQ "filter">
			<cfset command = setupFilter(arguments.commandNode) />
		
		<cfelseif arguments.commandNode.xmlName EQ "event-bean">
			<cfset command = setupEventBean(arguments.commandNode) />
		
		<cfelseif arguments.commandNode.xmlName EQ "redirect">
			<cfset command = setupRedirect(arguments.commandNode) />
		
		<cfelseif arguments.commandNode.xmlName EQ "event-arg">
			<cfset command = setupEventArg(arguments.commandNode) />
		
		<cfelseif arguments.commandNode.xmlName EQ "cache">
			<cfset command = setupCache(arguments.commandNode, parentHandlerName, parentHandlerType) />
		
		<cfelseif arguments.commandNode.xmlName EQ "cache-clear">
			<cfset command = setupCacheClear(arguments.commandNode) />
		
		<cfelse>
			<cfset command = setupDefault(arguments.commandNode) />
		</cfif>
		
		<cfreturn command />
	</cffunction> 

init

public void init( )

Initialization function called by the framework.

Parameters:

Code:

	<cffunction name="init" access="public" returntype="void" output="false"
		hint="Initialization function called by the framework.">
		<cfset variables.beanUtil = CreateObject("component", "MachII.util.BeanUtil").init() />
	</cffunction> 

setupAnnounce

private AnnounceCommand setupAnnounce( any commandNode )

Sets up an announce command.

Parameters:
any commandNode

Code:

	<cffunction name="setupAnnounce" access="private" returntype="MachII.framework.commands.AnnounceCommand" output="false"
		hint="Sets up an announce command.">
		<cfargument name="commandNode" type="any" required="true" />
		
		<cfset var command = "" />
		<cfset var eventName = arguments.commandNode.xmlAttributes["event"] />
		<cfset var copyEventArgs = true />
		<cfset var moduleName = "" />
		
		<cfif StructKeyExists(arguments.commandNode.xmlAttributes, "copyEventArgs")>
			<cfset copyEventArgs = arguments.commandNode.xmlAttributes["copyEventArgs"] />
		</cfif>
		<cfif StructKeyExists(arguments.commandNode.xmlAttributes, "module")>
			<cfset moduleName = arguments.commandNode.xmlAttributes["module"] />
		<cfelse>
			<cfset moduleName = getAppManager().getModuleName() />
		</cfif>
		
		<cfset command = CreateObject("component", "MachII.framework.commands.AnnounceCommand").init(eventName, copyEventArgs, moduleName) />
		
		<cfreturn command />
	</cffunction> 

setupCache

private CacheCommand setupCache( any commandNode, [string parentHandlerName=""], [string parentHandlerType=""] )

Sets up a cache command.

Parameters:
any commandNode
[string parentHandlerName=""]
[string parentHandlerType=""]

Code:

	<cffunction name="setupCache" access="private" returntype="MachII.framework.commands.CacheCommand" output="false"
		hint="Sets up a cache command.">
		<cfargument name="commandNode" type="any" required="true" />
		<cfargument name="parentHandlerName" type="string" required="false" default="" />
		<cfargument name="parentHandlerType" type="string" required="false" default="" />
		
		<cfset var command = "" />
		<cfset var cacheAlias = "" />
		<cfset var handlerId = "" />
		<cfset var criteria = "" />
		<cfset var name = "" />
		
		<cfset handlerId = getAppManager().getCacheManager().loadCacheHandlerFromXml(commandNode, parentHandlerName, parentHandlerType) />
		
		<cfif StructKeyExists(arguments.commandNode, "xmlAttributes") >
			
			<cfif StructKeyExists(arguments.commandNode.xmlAttributes, "name")>
				<cfset name = arguments.commandNode.xmlAttributes["name"] />
			</cfif>
			<cfif StructKeyExists(arguments.commandNode.xmlAttributes, "alias")>
				<cfset cacheAlias = arguments.commandNode.xmlAttributes["alias"] />
			</cfif>
			<cfif StructKeyExists(arguments.commandNode.xmlAttributes, "criteria")>
				<cfset criteria = arguments.commandNode.xmlAttributes["criteria"] />
			</cfif>
		</cfif>
		
		<cfset command = CreateObject("component", "MachII.framework.commands.CacheCommand").init(handlerId, name, cacheAlias, criteria) />
		<cfset command.setLog(getAppManager().getLogFactory()) />
		
		<cfreturn command />
	</cffunction> 

setupCacheClear

private CacheClearCommand setupCacheClear( any commandNode )

Sets up a CacheClear command.

Parameters:
any commandNode

Code:

	<cffunction name="setupCacheClear" access="private" returntype="MachII.framework.commands.CacheClearCommand" output="false"
		hint="Sets up a CacheClear command.">
		<cfargument name="commandNode" type="any" required="true" />
		
		<cfset var command = "" />
		<cfset var cacheAlias = "" />
		<cfset var cacheCondition = "" />
		<cfset var name = "" />
		<cfset var criteria = "" />
		
		<cfif StructKeyExists(arguments.commandNode, "xmlAttributes")>
			<cfif StructKeyExists(arguments.commandNode.xmlAttributes, "alias")>
				<cfset cacheAlias = arguments.commandNode.xmlAttributes["alias"] />	
			</cfif>		
			<cfif StructKeyExists(arguments.commandNode.xmlAttributes, "condition")>
				<cfset cacheCondition = arguments.commandNode.xmlAttributes["condition"] />	
			</cfif>	
			<cfif StructKeyExists(arguments.commandNode.xmlAttributes, "criteria")>
				<cfset criteria = arguments.commandNode.xmlAttributes["criteria"] />
			</cfif>
			<cfif StructKeyExists(arguments.commandNode.xmlAttributes, "name")>
				<cfset name = arguments.commandNode.xmlAttributes["name"] />
			</cfif>
		</cfif>

		<cfset command = CreateObject("component", "MachII.framework.commands.CacheClearCommand").init(
			name, cacheAlias, cacheCondition, criteria) />
		<cfset command.setLog(getAppManager().getLogFactory()) />
		
		<cfreturn command />
	</cffunction> 

setupDefault

private Command setupDefault( )

Sets up a default command.

Parameters:

Code:

	<cffunction name="setupDefault" access="private" returntype="MachII.framework.Command" output="false"
		hint="Sets up a default command.">
		
		<cfset var command = CreateObject("component", "MachII.framework.Command").init() />
		
		<cfreturn command />
	</cffunction> 

setupEventArg

private EventArgCommand setupEventArg( any commandNode )

Sets up an event-arg command.

Parameters:
any commandNode

Code:

	<cffunction name="setupEventArg" access="private" returntype="MachII.framework.commands.EventArgCommand" output="false"
		hint="Sets up an event-arg command.">
		<cfargument name="commandNode" type="any" required="true" />
		
		<cfset var command = "" />
		<cfset var argValue = "" />
		<cfset var argVariable = "" />
		<cfset var overwrite = true />
		<cfset var argName = arguments.commandNode.xmlAttributes["name"] />
		
		<cfif StructKeyExists(arguments.commandNode.xmlAttributes, "value")>
			<cfset argValue = arguments.commandNode.xmlAttributes["value"] />
		</cfif>
		<cfif StructKeyExists(arguments.commandNode.xmlAttributes, "variable")>
			<cfset argVariable = arguments.commandNode.xmlAttributes["variable"] />
		</cfif>
		<cfif StructKeyExists(arguments.commandNode.xmlAttributes, "overwrite")>
			<cfset overwrite = arguments.commandNode.xmlAttributes["overwrite"] />
		</cfif>
		
		<cfset command = CreateObject("component", "MachII.framework.commands.EventArgCommand").init(argName, argValue, argVariable, overwrite) />
		
		<cfset command.setLog(getAppManager().getLogFactory()) />
		
		<cfreturn command />
	</cffunction> 

setupEventBean

private EventBeanCommand setupEventBean( any commandNode )

Sets up a event-bean command.

Parameters:
any commandNode

Code:

	<cffunction name="setupEventBean" access="private" returntype="MachII.framework.commands.EventBeanCommand" output="false"
		hint="Sets up a event-bean command.">
		<cfargument name="commandNode" type="any" required="true" />
		
		<cfset var command = "" />
		<cfset var beanName = arguments.commandNode.xmlAttributes["name"] />
		<cfset var beanType = arguments.commandNode.xmlAttributes["type"] />
		<cfset var beanFields = "" />
		<cfset var reinit = true />
		
		<cfif StructKeyExists(arguments.commandNode.xmlAttributes, "fields")>
			<cfset beanFields = arguments.commandNode.xmlAttributes["fields"] />
		</cfif>
		<cfif StructKeyExists(arguments.commandNode.xmlAttributes, "reinit")>
			<cfset reinit = arguments.commandNode.xmlAttributes["reinit"] />
		</cfif>
		
		<cfset command = CreateObject("component", "MachII.framework.commands.EventBeanCommand").init(beanName, beanType, beanFields, reinit, variables.beanUtil) />
		
		<cfset command.setLog(getAppManager().getLogFactory()) />

		<cfreturn command />
	</cffunction> 

setupEventMapping

private EventMappingCommand setupEventMapping( any commandNode )

Sets up an event-mapping command.

Parameters:
any commandNode

Code:

	<cffunction name="setupEventMapping" access="private" returntype="MachII.framework.commands.EventMappingCommand" output="false"
		hint="Sets up an event-mapping command.">
		<cfargument name="commandNode" type="any" required="true" />
		
		<cfset var command = "" />
		<cfset var eventName = arguments.commandNode.xmlAttributes["event"] />
		<cfset var mappingName = arguments.commandNode.xmlAttributes["mapping"] />
		<cfset var mappingModule = "" />
		
		<cfif StructKeyExists(arguments.commandNode.xmlAttributes, "mappingModule")>
			<cfset mappingModule = arguments.commandNode.xmlAttributes["mappingModule"] />
		<cfelse>
			<cfset mappingModule = getAppManager().getModuleName() />
		</cfif>
		
		<cfset command = CreateObject("component", "MachII.framework.commands.EventMappingCommand").init(eventName, mappingName, mappingModule) />
		
		<cfreturn command />
	</cffunction> 

setupExecute

private ExecuteCommand setupExecute( any commandNode )

Sets up an execute command.

Parameters:
any commandNode

Code:

	<cffunction name="setupExecute" access="private" returntype="MachII.framework.commands.ExecuteCommand" output="false"
		hint="Sets up an execute command.">
		<cfargument name="commandNode" type="any" required="true" />
		
		<cfset var command = "" />
		<cfset var subroutine = arguments.commandNode.xmlAttributes["subroutine"] />
		
		<cfset command = CreateObject("component", "MachII.framework.commands.ExecuteCommand").init(subroutine) />
		
		<cfreturn command />
	</cffunction> 

setupFilter

private FilterCommand setupFilter( any commandNode )

Sets up a filter command.

Parameters:
any commandNode

Code:

	<cffunction name="setupFilter" access="private" returntype="MachII.framework.commands.FilterCommand" output="false"
		hint="Sets up a filter command.">
		<cfargument name="commandNode" type="any" required="true" />
		
		<cfset var command = "" />
		<cfset var filterName = arguments.commandNode.xmlAttributes["name"] />
		<cfset var filterParams = StructNew() />
		<cfset var paramNodes = arguments.commandNode.xmlChildren />
		<cfset var paramName = "" />
		<cfset var paramValue = "" />
		<cfset var filter = getAppManager().getFilterManager().getFilter(filterName) />
		<cfset var i = "" />

		<cfloop from="1" to="#ArrayLen(paramNodes)#" index="i">
			<cfset paramName = paramNodes[i].xmlAttributes["name"] />
			<cfif NOT StructKeyExists(paramNodes[i].xmlAttributes, "value")>
				<cfset paramValue = getAppManager().getUtils().recurseComplexValues(paramNodes[i]) />
			<cfelse>
				<cfset paramValue = paramNodes[i].xmlAttributes["value"] />
			</cfif>
			<cfset filterParams[paramName] = paramValue />
		</cfloop>

		<cfset command = CreateObject("component", "MachII.framework.commands.FilterCommand").init(filter, filterParams) />
		
		<cfreturn command />
	</cffunction> 

setupNotify

private NotifyCommand setupNotify( any commandNode )

Sets up a notify command.

Parameters:
any commandNode

Code:

	<cffunction name="setupNotify" access="private" returntype="MachII.framework.commands.NotifyCommand" output="false"
		hint="Sets up a notify command.">
		<cfargument name="commandNode" type="any" required="true" />
		
		<cfset var command = "" />
		<cfset var notifyListener = arguments.commandNode.xmlAttributes["listener"] />
		<cfset var notifyMethod = arguments.commandNode.xmlAttributes["method"] />
		<cfset var notifyResultKey = "" />
		<cfset var notifyResultArg = "" />
		<cfset var listener = getAppManager().getListenerManager().getListener(notifyListener) />
		
		<cfif StructKeyExists(arguments.commandNode.xmlAttributes, "resultKey")>
			<cfset notifyResultKey = arguments.commandNode.xmlAttributes["resultKey"] />
		</cfif>
		<cfif StructKeyExists(arguments.commandNode.xmlAttributes, "resultArg")>
			<cfset notifyResultArg = arguments.commandNode.xmlAttributes["resultArg"] />
		</cfif>
		
		<cfset command = CreateObject("component", "MachII.framework.commands.NotifyCommand").init(listener, notifyMethod, notifyResultKey, notifyResultArg) />
		
		<cfreturn command />
	</cffunction> 

setupPublish

private PublishCommand setupPublish( any commandNode )

Sets up a publish command.

Parameters:
any commandNode

Code:

	<cffunction name="setupPublish" access="private" returntype="MachII.framework.commands.PublishCommand" output="false"
		hint="Sets up a publish command.">
		<cfargument name="commandNode" type="any" required="true" />
		
		<cfset var command = "" />
		<cfset var message = arguments.commandNode.xmlAttributes["message"] />
		<cfset var messageHandler = getAppManager().getMessageManager().getMessageHandler(message) />
		
		<cfset command = CreateObject("component", "MachII.framework.commands.PublishCommand").init(message, messageHandler) />
		
		<cfreturn command />
	</cffunction> 

setupRedirect

private RedirectCommand setupRedirect( any commandNode )

Sets up a redirect command.

Parameters:
any commandNode

Code:

	<cffunction name="setupRedirect" access="private" returntype="MachII.framework.commands.RedirectCommand" output="false"
		hint="Sets up a redirect command.">
		<cfargument name="commandNode" type="any" required="true" />
		
		<cfset var command = "" />
		<cfset var eventName = "" />
		<cfset var redirectUrl = getAppManager().getPropertyManager().getProperty("urlBase", "index.cfm") />
		<cfset var moduleName = "" />
		<cfset var args = "" />
		<cfset var persist = false />
		<cfset var persistArgs = "" />
		<cfset var statusType = "temporary" />
		<cfset var eventParameter = getAppManager().getPropertyManager().getProperty("eventParameter", "event") />
		<cfset var redirectPersistParameter = getAppManager().getPropertyManager().getProperty("redirectPersistParameter", "persistId") /> />
		
		<cfif StructKeyExists(arguments.commandNode.xmlAttributes, "event")>
			<cfset eventName = arguments.commandNode.xmlAttributes["event"] />
		</cfif>
		<cfif StructKeyExists(arguments.commandNode.xmlAttributes, "url")>
			<cfset redirectUrl = arguments.commandNode.xmlAttributes["url"] />
		</cfif>
		<cfif StructKeyExists(arguments.commandNode.xmlAttributes, "args")>
			<cfset args = arguments.commandNode.xmlAttributes["args"] />
		</cfif>
		<cfif StructKeyExists(arguments.commandNode.xmlAttributes, "persist")>
			<cfset persist = arguments.commandNode.xmlAttributes["persist"] />
		</cfif>
		<cfif StructKeyExists(arguments.commandNode.xmlAttributes, "persistArgs")>
			<cfset persistArgs = arguments.commandNode.xmlAttributes["persistArgs"] />
		</cfif>
		<cfif StructKeyExists(arguments.commandNode.xmlAttributes, "module")>
			<cfset moduleName = arguments.commandNode.xmlAttributes["module"] />
		<cfelse>
			<cfset moduleName = getAppManager().getModuleName() />
		</cfif>
		<cfif StructKeyExists(arguments.commandNode.xmlAttributes, "statusType")>
			<cfset statusType = arguments.commandNode.xmlAttributes["statusType"] />
		</cfif>
		
		<cfset command = CreateObject("component", "MachII.framework.commands.RedirectCommand").init(eventName, eventParameter, redirectPersistParameter, moduleName, redirectUrl, args, persist, persistArgs, statusType) />
		
		<cfset command.setLog(getAppManager().getLogFactory()) />
		
		<cfreturn command />
	</cffunction> 

setupViewPage

private ViewPageCommand setupViewPage( any commandNode )

Sets up a view-page command.

Parameters:
any commandNode

Code:

	<cffunction name="setupViewPage" access="private" returntype="MachII.framework.commands.ViewPageCommand" output="false"
		hint="Sets up a view-page command.">
		<cfargument name="commandNode" type="any" required="true" />
		
		<cfset var command = "" />
		<cfset var viewName = arguments.commandNode.xmlAttributes["name"] />
		<cfset var contentKey = "" />
		<cfset var contentArg = "" />
		<cfset var appendContent = "" />
		
		<cfif StructKeyExists(arguments.commandNode.xmlAttributes, "contentKey")>
			<cfset contentKey = commandNode.xmlAttributes["contentKey"] />
		</cfif>
		<cfif StructKeyExists(arguments.commandNode.xmlAttributes, "contentArg")>
			<cfset contentArg = commandNode.xmlAttributes["contentArg"] />
		</cfif>
		<cfif StructKeyExists(arguments.commandNode.xmlAttributes, "append")>
			<cfset appendContent = arguments.commandNode.xmlAttributes["append"] />
		</cfif>
		
		<cfset command = CreateObject("component", "MachII.framework.commands.ViewPageCommand").init(viewName, contentKey, contentArg, appendContent) />
		
		<cfreturn command />
	</cffunction>