framework.Command | +--framework.commands.EventBeanCommand
| Method Summary | |
public EventBeanCommand |
init(string beanName, string beanType, string beanFields, boolean reinit)
Used by the framework for initialization. |
public boolean |
execute(Event event, EventContext eventContext)
Executes the command. |
private string |
getBeanFields()
|
private string |
getBeanName()
|
private string |
getBeanType()
|
private BeanUtil |
getBeanUtil()
|
private boolean |
getReinit()
|
public boolean |
isBeanFieldsDefined()
|
private void |
setBeanFields(string beanFields)
|
private void |
setBeanName(string beanName)
|
private void |
setBeanType(string beanType)
|
private void |
setBeanUtil(BeanUtil beanUtil)
|
private void |
setReinit(boolean reinit)
|
| Methods inherited from framework.Command |
setParameter,
getParameter,
setParameters
|
| Method Detail |
public boolean execute(Event event, EventContext eventContext)
Event eventEventContext eventContext<cffunction name="execute" access="public" returntype="boolean" hint="Executes the command."> <cfargument name="event" type="MachII.framework.Event" required="true" /> <cfargument name="eventContext" type="MachII.framework.EventContext" required="true" /> <cfset var bean = "" /> <cfset var reinit = TRUE /> <cfif NOT getReinit() AND arguments.event.isArgDefined(getBeanName())> <cfset bean = arguments.event.getArg(getBeanName()) /> <cfif isBeanFieldsDefined()> <cfset getBeanUtil().setBeanFields(bean, getBeanFields(), arguments.event.getArgs()) /> <cfelse> <cfset getBeanUtil().setBeanAutoFields(bean, arguments.event.getArgs()) /> </cfif> <cfelse> <cfif isBeanFieldsDefined()> <cfset bean = getBeanUtil().createBean(getBeanType()) /> <cfset getBeanUtil().setBeanFields(bean, getBeanFields(), arguments.event.getArgs()) /> <cfelse> <cfset bean = getBeanUtil().createBean(getBeanType(), arguments.event.getArgs()) /> </cfif> <cfset arguments.event.setArg(getBeanName(), bean, getBeanType()) /> </cfif> <cfreturn true /> </cffunction>
private string getBeanFields()
<cffunction name="getBeanFields" access="private" returntype="string" output="false"> <cfreturn variables.beanFields /> </cffunction>
private string getBeanName()
<cffunction name="getBeanName" access="private" returntype="string" output="false"> <cfreturn variables.beanName /> </cffunction>
private string getBeanType()
<cffunction name="getBeanType" access="private" returntype="string" output="false"> <cfreturn variables.beanType /> </cffunction>
private MachII.util.BeanUtil getBeanUtil()
<cffunction name="getBeanUtil" access="private" returntype="MachII.util.BeanUtil" output="false"> <cfreturn variables.beanUtil /> </cffunction>
private boolean getReinit()
<cffunction name="getReinit" access="private" returntype="boolean" output="false"> <cfreturn variables.reinit /> </cffunction>
public EventBeanCommand init(string beanName, string beanType, string beanFields, boolean reinit)
string beanNamestring beanTypestring beanFieldsboolean reinit <cffunction name="init" access="public" returntype="EventBeanCommand" output="false"
hint="Used by the framework for initialization.">
<cfargument name="beanName" type="string" required="true" />
<cfargument name="beanType" type="string" required="true" />
<cfargument name="beanFields" type="string" required="true" />
<cfargument name="reinit" type="boolean" required="true" />
<cfset setBeanName(arguments.beanName) />
<cfset setBeanType(arguments.beanType) />
<cfset setBeanFields(arguments.beanFields) />
<cfset setReinit(arguments.reinit) />
<cfset setBeanUtil(CreateObject("component", "MachII.util.BeanUtil").init()) />
<cfreturn this />
</cffunction>public boolean isBeanFieldsDefined()
<cffunction name="isBeanFieldsDefined" access="public" returntype="boolean" output="false"> <cfreturn NOT getBeanFields() EQ '' /> </cffunction>
private void setBeanFields(string beanFields)
string beanFields<cffunction name="setBeanFields" access="private" returntype="void" output="false"> <cfargument name="beanFields" type="string" required="true" /> <cfset variables.beanFields = arguments.beanFields /> </cffunction>
private void setBeanName(string beanName)
string beanName<cffunction name="setBeanName" access="private" returntype="void" output="false"> <cfargument name="beanName" type="string" required="true" /> <cfset variables.beanName = arguments.beanName /> </cffunction>
private void setBeanType(string beanType)
string beanType<cffunction name="setBeanType" access="private" returntype="void" output="false"> <cfargument name="beanType" type="string" required="true" /> <cfset variables.beanType = arguments.beanType /> </cffunction>
private void setBeanUtil(BeanUtil beanUtil)
BeanUtil beanUtil<cffunction name="setBeanUtil" access="private" returntype="void" output="false"> <cfargument name="beanUtil" type="MachII.util.BeanUtil" required="true" /> <cfset variables.beanUtil = arguments.beanUtil /> </cffunction>
private void setReinit(boolean reinit)
boolean reinit<cffunction name="setReinit" access="private" returntype="void" output="false"> <cfargument name="reinit" type="boolean" required="true" /> <cfset variables.reinit = arguments.reinit /> </cffunction>
<!---
License:
Copyright 2007 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: EventBeanCommand.cfc 482 2007-09-05 02:07:07Z pfarrell $
Created version: 1.0.6
Updated version: 1.5.0
Notes:
--->
<cfcomponent
displayname="EventBeanCommand"
extends="MachII.framework.Command"
output="false"
hint="An Command for creating and populating a bean in the current event.">
<!---
PROPERTIES
--->
<cfset variables.beanName = "" />
<cfset variables.beanType = "" />
<cfset variables.beanFields = "" />
<cfset variables.reinit = "" />
<cfset variables.beanUtil = "" />
<!---
INITIALIZATION / CONFIGURATION
--->
<cffunction name="init" access="public" returntype="EventBeanCommand" output="false"
hint="Used by the framework for initialization.">
<cfargument name="beanName" type="string" required="true" />
<cfargument name="beanType" type="string" required="true" />
<cfargument name="beanFields" type="string" required="true" />
<cfargument name="reinit" type="boolean" required="true" />
<cfset setBeanName(arguments.beanName) />
<cfset setBeanType(arguments.beanType) />
<cfset setBeanFields(arguments.beanFields) />
<cfset setReinit(arguments.reinit) />
<cfset setBeanUtil(CreateObject("component", "MachII.util.BeanUtil").init()) />
<cfreturn this />
</cffunction>
<!---
PUBLIC FUNCTIONS
--->
<cffunction name="execute" access="public" returntype="boolean"
hint="Executes the command.">
<cfargument name="event" type="MachII.framework.Event" required="true" />
<cfargument name="eventContext" type="MachII.framework.EventContext" required="true" />
<cfset var bean = "" />
<cfset var reinit = TRUE />
<!--- If reinit is FALSE, get the bean from the event --->
<cfif NOT getReinit() AND arguments.event.isArgDefined(getBeanName())>
<cfset bean = arguments.event.getArg(getBeanName()) />
<cfif isBeanFieldsDefined()>
<cfset getBeanUtil().setBeanFields(bean, getBeanFields(), arguments.event.getArgs()) />
<cfelse>
<cfset getBeanUtil().setBeanAutoFields(bean, arguments.event.getArgs()) />
</cfif>
<cfelse>
<cfif isBeanFieldsDefined()>
<cfset bean = getBeanUtil().createBean(getBeanType()) />
<cfset getBeanUtil().setBeanFields(bean, getBeanFields(), arguments.event.getArgs()) />
<cfelse>
<cfset bean = getBeanUtil().createBean(getBeanType(), arguments.event.getArgs()) />
</cfif>
<cfset arguments.event.setArg(getBeanName(), bean, getBeanType()) />
</cfif>
<cfreturn true />
</cffunction>
<!---
ACCESSORS
--->
<cffunction name="setBeanName" access="private" returntype="void" output="false">
<cfargument name="beanName" type="string" required="true" />
<cfset variables.beanName = arguments.beanName />
</cffunction>
<cffunction name="getBeanName" access="private" returntype="string" output="false">
<cfreturn variables.beanName />
</cffunction>
<cffunction name="setBeanType" access="private" returntype="void" output="false">
<cfargument name="beanType" type="string" required="true" />
<cfset variables.beanType = arguments.beanType />
</cffunction>
<cffunction name="getBeanType" access="private" returntype="string" output="false">
<cfreturn variables.beanType />
</cffunction>
<cffunction name="setBeanFields" access="private" returntype="void" output="false">
<cfargument name="beanFields" type="string" required="true" />
<cfset variables.beanFields = arguments.beanFields />
</cffunction>
<cffunction name="getBeanFields" access="private" returntype="string" output="false">
<cfreturn variables.beanFields />
</cffunction>
<cffunction name="isBeanFieldsDefined" access="public" returntype="boolean" output="false">
<cfreturn NOT getBeanFields() EQ '' />
</cffunction>
<cffunction name="setReinit" access="private" returntype="void" output="false">
<cfargument name="reinit" type="boolean" required="true" />
<cfset variables.reinit = arguments.reinit />
</cffunction>
<cffunction name="getReinit" access="private" returntype="boolean" output="false">
<cfreturn variables.reinit />
</cffunction>
<cffunction name="setBeanUtil" access="private" returntype="void" output="false">
<cfargument name="beanUtil" type="MachII.util.BeanUtil" required="true" />
<cfset variables.beanUtil = arguments.beanUtil />
</cffunction>
<cffunction name="getBeanUtil" access="private" returntype="MachII.util.BeanUtil" output="false">
<cfreturn variables.beanUtil />
</cffunction>
</cfcomponent>