| 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 1299 2009-01-25 22:19:23Z 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=""], [boolean override="false"])
Loads and instantiates a command from an XML fragment. |
| private AnnounceCommand |
setupAnnounce(any commandNode)
Sets up an announce command. |
| private CacheCommand |
setupCache(any commandNode, [string parentHandlerName=""], [string parentHandlerType=""], [boolean override="false"])
Sets up a cache command. |
| private CacheClearCommand |
setupCacheClear(any commandNode)
Sets up a CacheClear command. |
| private Command |
setupDefault(any commandNode)
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=""], [boolean override="false"] )
Loads and instantiates a command from an XML fragment.
Parameters:
| any commandNode |
| [string parentHandlerName=""] |
| [string parentHandlerType=""] |
| [boolean override="false"] |
Code:
<cffunction name="createCommand" access="private" returntype="MachII.framework.Command" output="false" hint="Loads and instantiates a command from an XML fragment."> <cfargument name="commandNode" type="any" required="true" /> <cfargument name="parentHandlerName" type="string" required="false" default="" /> <cfargument name="parentHandlerType" type="string" required="false" default="" /> <cfargument name="override" type="boolean" required="false" default="false" /> <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, arguments.parentHandlerName, arguments.parentHandlerType, arguments.override) /> <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() />
<cfset variables.utils = getAppManager().getUtils() />
<cfset variables.expressionEvaluator = getAppManager().getExpressionEvaluator() />
</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=""], [boolean override="false"] )
Sets up a cache command.
Parameters:
| any commandNode |
| [string parentHandlerName=""] |
| [string parentHandlerType=""] |
| [boolean override="false"] |
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="" />
<cfargument name="override" type="boolean" required="false" default="false" />
<cfset var command = "" />
<cfset var aliases = "" />
<cfset var handlerId = "" />
<cfset var criteria = "" />
<cfset var name = "" />
<cfset handlerId = getAppManager().getCacheManager().loadCacheHandlerFromXml(arguments.commandNode, arguments.parentHandlerName, arguments.parentHandlerType, arguments.override) />
<cfif StructKeyExists(arguments.commandNode, "xmlAttributes") >
<cfif StructKeyExists(arguments.commandNode.xmlAttributes, "strategyName")>
<cfset name = arguments.commandNode.xmlAttributes["strategyName"] />
</cfif>
<cfif StructKeyExists(arguments.commandNode.xmlAttributes, "aliases")>
<cfset aliases = variables.utils.trimList(arguments.commandNode.xmlAttributes["aliases"]) />
</cfif>
<cfif StructKeyExists(arguments.commandNode.xmlAttributes, "criteria")>
<cfset criteria = variables.utils.trimList(arguments.commandNode.xmlAttributes["criteria"]) />
</cfif>
</cfif>
<cfset command = CreateObject("component", "MachII.framework.commands.CacheCommand").init(handlerId, name, aliases, 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 ids = "" />
<cfset var aliases = "" />
<cfset var strategyNames = "" />
<cfset var criteria = "" />
<cfset var condition = "" />
<cfif StructKeyExists(arguments.commandNode.xmlAttributes, "ids")>
<cfset ids = variables.utils.trimList(arguments.commandNode.xmlAttributes["ids"]) />
</cfif>
<cfif StructKeyExists(arguments.commandNode.xmlAttributes, "aliases")>
<cfset aliases = variables.utils.trimList(arguments.commandNode.xmlAttributes["aliases"]) />
</cfif>
<cfif StructKeyExists(arguments.commandNode.xmlAttributes, "strategyNames")>
<cfset strategyNames = arguments.commandNode.xmlAttributes["strategyNames"] />
</cfif>
<cfif StructKeyExists(arguments.commandNode.xmlAttributes, "criteria")>
<cfset criteria = variables.utils.trimList(arguments.commandNode.xmlAttributes["criteria"]) />
</cfif>
<cfif StructKeyExists(arguments.commandNode.xmlAttributes, "condition")>
<cfset condition = arguments.commandNode.xmlAttributes["condition"] />
</cfif>
<cfset command = CreateObject("component", "MachII.framework.commands.CacheClearCommand").init(
ids, aliases, strategyNames, criteria, condition) />
<cfset command.setLog(getAppManager().getLogFactory()) />
<cfset command.setExpressionEvaluator(variables.expressionEvaluator) />
<cfset command.setPropertyManager(getAppManager().getPropertyManager()) />
<cfreturn command />
</cffunction>
| setupDefault |
|---|
private Command setupDefault( any commandNode )
Sets up a default command.
Parameters:
| any commandNode |
Code:
<cffunction name="setupDefault" access="private" returntype="MachII.framework.Command" output="false"
hint="Sets up a default command.">
<cfargument name="commandNode" type="any" required="true" />
<cfset var command = CreateObject("component", "MachII.framework.Command").init() />
<cfset command.setParameter("commandName", arguments.commandNode.xmlName) />
<cfset command.setLog(getAppManager().getLogFactory()) />
<cfset command.setExpressionEvaluator(variables.expressionEvaluator) />
<cfset command.setPropertyManager(getAppManager().getPropertyManager()) />
<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 = variables.utils.trimList(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 persistArgsIgnore = "" />
<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 = variables.utils.trimList(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 = variables.utils.trimList(arguments.commandNode.xmlAttributes["persistArgs"]) />
</cfif>
<cfif StructKeyExists(arguments.commandNode.xmlAttributes, "persistArgsIgnore")>
<cfset persistArgsIgnore = variables.utils.trimList(arguments.commandNode.xmlAttributes["persistArgsIgnore"]) />
</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, persistArgsIgnore) />
<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>