EventArgCommand

Package: MachII.framework.commands
Inherits from: framework.Command
An Command for putting an event arg into the current event.

<!--- 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: Ben Edwards (ben@ben-edwards.com) $Id: EventArgCommand.cfc 1091 2008-10-07 22:51:01Z peterfarrell $ Created version: 1.0.0 Updated version: 1.5.0 Notes: --->

Method Summary
public EventArgCommand init(string argName, [string argValue=""], [string argVariable=""], [boolean overwrite="true"])

Used by the framework for initialization.

public boolean execute(Event event, EventContext eventContext)

Executes the command.

private string getArgName()
private string getArgValue()
private string getArgVariable()
private any getArgVariableValue()

Gets an arg variable value by using evaluate.

private boolean getOverwrite()
private boolean isArgValueDefined()
private boolean isArgVariableDefined()
private void setArgName(string argName)
private void setArgValue(string argValue)
private void setArgVariable(string argVariable)
private void setOverwrite(string overwrite)
Methods inherited from framework.Command:   getLog , setParameter , getPropertyManager , setParameters , setLog , setExpressionEvaluator , getExpressionEvaluator , getParameter , setPropertyManager
Method Detail
execute

public boolean execute( Event event, EventContext eventContext )

Executes the command.

Parameters:
Event event
EventContext eventContext

Code:

	<cffunction name="execute" access="public" returntype="boolean" output="false"
		hint="Executes the command.">
		<cfargument name="event" type="MachII.framework.Event" required="true" />
		<cfargument name="eventContext" type="MachII.framework.EventContext" required="true" />
		
		<cfset var value = "" />
		<cfset var log = getLog() />		

		
		<cfif isArgVariableDefined()>
			<cfset value = getArgVariableValue() />
		<cfelseif isArgValueDefined()>
			<cfset value = getArgValue() />
		</cfif>
		
		
		<cfif getOverwrite() OR NOT arguments.event.isArgDefined(getArgName())>
			<cfif log.isDebugEnabled()>
				<cfif IsSimpleValue(value)>
					<cfset log.debug("Set event-arg named '#getArgName()#' with value '#value#'.") />
				<cfelse>
					<cfset log.debug("Set event-arg named '#getArgName()#'.", value) />
				</cfif>
			</cfif>
			
			<cfset arguments.event.setArg(getArgName(), value) />
		<cfelse>
			<cfif log.isDebugEnabled()>				
				<cfif IsSimpleValue(value)>
					<cfset log.debug("An event-arg named '#getArgName()#' with overwrite 'false' is already defined. Current value or variable: '#value#'.") />
				<cfelse>
					<cfset log.debug("An event-arg named '#getArgName()#' with overwrite 'false' is already defined.", value) />
				</cfif>
			</cfif>
		</cfif>
		
		<cfreturn true />
	</cffunction> 

getArgName

private string getArgName( )

Parameters:

Code:

	<cffunction name="getArgName" access="private" returntype="string" output="false">
		<cfreturn variables.argName />
	</cffunction> 

getArgValue

private string getArgValue( )

Parameters:

Code:

	<cffunction name="getArgValue" access="private" returntype="string" output="false">
		<cfreturn variables.argValue />
	</cffunction> 

getArgVariable

private string getArgVariable( )

Parameters:

Code:

	<cffunction name="getArgVariable" access="private" returntype="string" output="false">
		<cfreturn variables.argVariable />
	</cffunction> 

getArgVariableValue

private any getArgVariableValue( )

Gets an arg variable value by using evaluate.

Parameters:

Code:

	<cffunction name="getArgVariableValue" access="private" returntype="any" output="false"
		hint="Gets an arg variable value by using evaluate.">
		
		<cfset var value = "" />
		<cfset var log = getLog() />
		
		<cfif IsDefined(getArgVariable())>
			<cfset value = Evaluate(getArgVariable()) />
		<cfelseif log.isDebugEnabled()>
			<cfset log.debug("No value found for arg variable named '#getArgVariable()#' for event-arg named '#getArgName()#'.") />
		</cfif>
		
		<cfreturn value />
	</cffunction> 

getOverwrite

private boolean getOverwrite( )

Parameters:

Code:

	<cffunction name="getOverwrite" access="private" returntype="boolean" output="false">
		<cfreturn variables.overwrite />
	</cffunction> 

init

public EventArgCommand init( string argName, [string argValue=""], [string argVariable=""], [boolean overwrite="true"] )

Used by the framework for initialization.

Parameters:
string argName
[string argValue=""]
[string argVariable=""]
[boolean overwrite="true"]

Code:

	<cffunction name="init" access="public" returntype="EventArgCommand" output="false"
		hint="Used by the framework for initialization.">
		<cfargument name="argName" type="string" required="true" />
		<cfargument name="argValue" type="string" required="false" default="" />
		<cfargument name="argVariable" type="string" required="false" default="" />
		<cfargument name="overwrite" type="boolean" required="false" default="true" />
		
		<cfset setArgName(arguments.argName) />
		<cfset setArgValue(arguments.argValue) />
		<cfset setArgVariable(arguments.argVariable) />
		<cfset setOverwrite(arguments.overwrite) />
		
		<cfreturn this />
	</cffunction> 

isArgValueDefined

private boolean isArgValueDefined( )

Parameters:

Code:

	<cffunction name="isArgValueDefined" access="private" returntype="boolean" output="false">
		<cfreturn Len(variables.argValue) />
	</cffunction> 

isArgVariableDefined

private boolean isArgVariableDefined( )

Parameters:

Code:

	<cffunction name="isArgVariableDefined" access="private" returntype="boolean" output="false">
		<cfreturn Len(variables.argVariable) />
	</cffunction> 

setArgName

private void setArgName( string argName )

Parameters:
string argName

Code:

	<cffunction name="setArgName" access="private" returntype="void" output="false">
		<cfargument name="argName" type="string" required="true" />
		<cfset variables.argName = arguments.argName />
	</cffunction> 

setArgValue

private void setArgValue( string argValue )

Parameters:
string argValue

Code:

	<cffunction name="setArgValue" access="private" returntype="void" output="false">
		<cfargument name="argValue" type="string" required="true" />
		<cfset variables.argValue = arguments.argValue />
	</cffunction> 

setArgVariable

private void setArgVariable( string argVariable )

Parameters:
string argVariable

Code:

	<cffunction name="setArgVariable" access="private" returntype="void" output="false">
		<cfargument name="argVariable" type="string" required="true" />
		<cfset variables.argVariable = arguments.argVariable />
	</cffunction> 

setOverwrite

private void setOverwrite( string overwrite )

Parameters:
string overwrite

Code:

	<cffunction name="setOverwrite" access="private" returntype="void" output="false">
		<cfargument name="overwrite" type="string" required="true" />
		
		<cfset variables.overwrite = (arguments.overwrite IS NOT "false") />
	</cffunction>