framework.BaseComponent
| Method Summary | |
public void |
init(AppManager appManager, [struct parameters="#StructNew()#"])
Used by the framework for initialization. Do not override. |
public void |
announceEvent(string eventName, [struct eventArgs="#StructNew()#"])
Announces a new event to the framework. |
public void |
announceEventInModule(string moduleName, string eventName, [struct eventArgs="#StructNew()#"])
Announces a new event to the framework. |
private any |
bindValue(string parameterName)
Binds placeholders values in parameters. |
public string |
buildUrl(string eventName, [any urlParameters=""], [string urlBase])
Builds a framework specific url with module name. |
public string |
buildUrlToModule(string moduleName, string eventName, [any urlParameters=""], [string urlBase])
Builds a framework specific url. |
public void |
configure()
Override to provide custom configuration logic. Called after init(). |
public AppManager |
getAppManager()
Gets the components AppManager instance. |
public any |
getParameter(string name, [string defaultValue=""])
Gets a configuration parameter value, or a default value if not defined. |
public struct |
getParameters()
Gets the full set of configuration parameters for the component. |
public any |
getProperty(string propertyName)
Gets the specified property - this is just a shortcut for getPropertyManager().getProperty() |
public PropertyManager |
getPropertyManager()
Gets the components PropertyManager instance. |
public boolean |
hasParameter(string name)
DEPRECATED - use isParameterDefined() instead. Checks to see whether or not a configuration parameter is defined. |
public boolean |
isParameterDefined(string name)
Checks to see whether or not a configuration parameter is defined. |
private void |
setAppManager(AppManager appManager)
Sets the components AppManager instance. |
public void |
setParameter(string name, any value)
Sets a configuration parameter. |
public void |
setParameters(struct parameters)
Sets the full set of configuration parameters for the component. |
public any |
setProperty(string propertyName, any propertyValue)
Sets the specified property - this is just a shortcut for getPropertyManager().setProperty() |
| Method Detail |
public void announceEvent(string eventName, [struct eventArgs="#StructNew()#"])
string eventName - The name of the event to announce.[struct eventArgs="#StructNew()#"] - A struct of arguments to set as the event's args.<cffunction name="announceEvent" access="public" returntype="void" output="false" hint="Announces a new event to the framework."> <cfargument name="eventName" type="string" required="true" hint="The name of the event to announce." /> <cfargument name="eventArgs" type="struct" required="false" default="#StructNew()#" hint="A struct of arguments to set as the event's args." /> <cfset var appKey = getAppManager().getAppLoader().getAppKey() /> <cfif StructKeyExists(request, "_MachIIRequestHandler_" & appKey)> <cfset request["_MachIIRequestHandler_" & appKey].getEventContext().announceEvent(arguments.eventName, arguments.eventArgs) /> <cfelse> <cfthrow message="The required RequestHandler is necessary to announce events is not set in 'request['_MachIIRequestHandler_#appKey#']'." /> </cfif> </cffunction>
public void announceEventInModule(string moduleName, string eventName, [struct eventArgs="#StructNew()#"])
string moduleName - The name of the module in which event exists.string eventName - The name of the event to announce.[struct eventArgs="#StructNew()#"] - A struct of arguments to set as the event's args.<cffunction name="announceEventInModule" access="public" returntype="void" output="false" hint="Announces a new event to the framework."> <cfargument name="moduleName" type="string" required="true" hint="The name of the module in which event exists." /> <cfargument name="eventName" type="string" required="true" hint="The name of the event to announce." /> <cfargument name="eventArgs" type="struct" required="false" default="#StructNew()#" hint="A struct of arguments to set as the event's args." /> <cfset var appKey = getAppManager().getAppLoader().getAppKey() /> <cfif StructKeyExists(request, "_MachIIRequestHandler_" & appKey)> <cfset request["_MachIIRequestHandler_" & appKey].getEventContext().announceEvent(arguments.eventName, arguments.eventArgs, arguments.moduleName) /> <cfelse> <cfthrow message="The required RequestHandler is necessary to announce events is not set in 'request['_MachIIRequestHandler_#appKey#']'." /> </cfif> </cffunction>
private any bindValue(string parameterName)
string parameterName - The parameter name. <cffunction name="bindValue" access="private" returntype="any" output="false"
hint="Binds placeholders values in parameters.">
<cfargument name="parameterName" type="string" required="true"
hint="The parameter name." />
<cfset var propertyName = "" />
<cfset var value = variables.parameters[arguments.parameterName] />
<cfif IsSimpleValue(value) AND REFindNoCase("\${(.)*?}", value)>
<cfset propertyName = Mid(value, 3, Len(value) -3) />
<cfif getPropertyManager().isPropertyDefined(propertyName)>
<cfset value = getProperty(propertyName) />
<cfelse>
<cfthrow type="MachII.framework.ProperyNotDefinedToBindToParameter"
message="The required property is not defined to bind to a parameter named '#arguments.parameterName#'." />
</cfif>
</cfif>
<cfreturn value />
</cffunction>public string buildUrl(string eventName, [any urlParameters=""], [string urlBase])
string eventName - Name of the event to build the url with.[any urlParameters=""] - alue2) to build the url with or a struct of data.[string urlBase] - Base of the url. Defaults to the value of the urlBase property.<cffunction name="buildUrl" access="public" returntype="string" output="false" hint="Builds a framework specific url with module name."> <cfargument name="eventName" type="string" required="true" hint="Name of the event to build the url with." /> <cfargument name="urlParameters" type="any" required="false" default="" hint="Name/value pairs (urlArg1=value1|urlArg2=value2) to build the url with or a struct of data." /> <cfargument name="urlBase" type="string" required="false" hint="Base of the url. Defaults to the value of the urlBase property." /> <cfset var appKey = getAppManager().getAppLoader().getAppKey() /> <cfset arguments.moduleName = request["_MachIIRequestHandler_" & appKey].getEventContext().getAppManager().getModuleName() /> <cfreturn getAppManager().getRequestManager().buildUrl(argumentcollection=arguments) /> </cffunction>
public string buildUrlToModule(string moduleName, string eventName, [any urlParameters=""], [string urlBase])
string moduleName - Name of the module to build the url with. Defaults to base module if empty string.string eventName - Name of the event to build the url with.[any urlParameters=""] - alue2) to build the url with or a struct of data.[string urlBase] - Base of the url. Defaults to the value of the urlBase property.<cffunction name="buildUrlToModule" access="public" returntype="string" output="false" hint="Builds a framework specific url."> <cfargument name="moduleName" type="string" required="true" hint="Name of the module to build the url with. Defaults to base module if empty string." /> <cfargument name="eventName" type="string" required="true" hint="Name of the event to build the url with." /> <cfargument name="urlParameters" type="any" required="false" default="" hint="Name/value pairs (urlArg1=value1|urlArg2=value2) to build the url with or a struct of data." /> <cfargument name="urlBase" type="string" required="false" hint="Base of the url. Defaults to the value of the urlBase property." /> <cfreturn getAppManager().getRequestManager().buildUrl(argumentcollection=arguments) /> </cffunction>
public void configure()
<cffunction name="configure" access="public" returntype="void" output="false" hint="Override to provide custom configuration logic. Called after init()."> </cffunction>
public MachII.framework.AppManager getAppManager()
<cffunction name="getAppManager" access="public" returntype="MachII.framework.AppManager" output="false" hint="Gets the components AppManager instance."> <cfreturn variables.appManager /> </cffunction>
public any getParameter(string name, [string defaultValue=""])
string name - The parameter name.[string defaultValue=""] - The default value to return if the parameter is not defined. Defaults to a blank string.<cffunction name="getParameter" access="public" returntype="any" output="false" hint="Gets a configuration parameter value, or a default value if not defined."> <cfargument name="name" type="string" required="true" hint="The parameter name." /> <cfargument name="defaultValue" type="string" required="false" default="" hint="The default value to return if the parameter is not defined. Defaults to a blank string." /> <cfif isParameterDefined(arguments.name)> <cfreturn bindValue(arguments.name) /> <cfelse> <cfreturn arguments.defaultValue /> </cfif> </cffunction>
public struct getParameters()
<cffunction name="getParameters" access="public" returntype="struct" output="false" hint="Gets the full set of configuration parameters for the component."> <cfset var key = "" /> <cfset var resolvedParameters = StructNew() /> <cfloop collection="#variables.parameters#" item="key"> <cfset resolvedParameters[key] = bindValue(key) /> </cfloop> <cfreturn resolvedParameters /> </cffunction>
public any getProperty(string propertyName)
string propertyName - The name of the property to return.<cffunction name="getProperty" access="public" returntype="any" output="false" hint="Gets the specified property - this is just a shortcut for getPropertyManager().getProperty()"> <cfargument name="propertyName" type="string" required="true" hint="The name of the property to return."/> <cfreturn getPropertyManager().getProperty(arguments.propertyName) /> </cffunction>
public MachII.framework.PropertyManager getPropertyManager()
<cffunction name="getPropertyManager" access="public" returntype="MachII.framework.PropertyManager" output="false" hint="Gets the components PropertyManager instance."> <cfreturn getAppManager().getPropertyManager() /> </cffunction>
public boolean hasParameter(string name)
string name - The parameter name.<cffunction name="hasParameter" access="public" returntype="boolean" output="false" hint="DEPRECATED - use isParameterDefined() instead. Checks to see whether or not a configuration parameter is defined."> <cfargument name="name" type="string" required="true" hint="The parameter name." /> <cftry> <cfthrow type="MachII.framework.deprecatedMethod" message="The hasParameter() method has been deprecated. Please use isParameterDefined() instead." /> <cfcatch type="MachII.framework.deprecatedMethod"> </cfcatch> </cftry> <cfreturn StructKeyExists(variables.parameters, arguments.name) /> </cffunction>
public void init(AppManager appManager, [struct parameters="#StructNew()#"])
AppManager appManager - The framework instances' AppManager.[struct parameters="#StructNew()#"] - The initial set of configuration parameters.<cffunction name="init" access="public" returntype="void" output="false" hint="Used by the framework for initialization. Do not override."> <cfargument name="appManager" type="MachII.framework.AppManager" required="true" hint="The framework instances' AppManager." /> <cfargument name="parameters" type="struct" required="false" default="#StructNew()#" hint="The initial set of configuration parameters." /> <cfset setAppManager(arguments.appManager) /> <cfset setParameters(arguments.parameters) /> </cffunction>
public boolean isParameterDefined(string name)
string name - The parameter name.<cffunction name="isParameterDefined" access="public" returntype="boolean" output="false" hint="Checks to see whether or not a configuration parameter is defined."> <cfargument name="name" type="string" required="true" hint="The parameter name." /> <cfreturn StructKeyExists(variables.parameters, arguments.name) /> </cffunction>
private void setAppManager(AppManager appManager)
AppManager appManager - The AppManager instance to set.<cffunction name="setAppManager" access="private" returntype="void" output="false" hint="Sets the components AppManager instance."> <cfargument name="appManager" type="MachII.framework.AppManager" required="true" hint="The AppManager instance to set." /> <cfset variables.appManager = arguments.appManager /> </cffunction>
public void setParameter(string name, any value)
string name - The parameter name.any value - The parameter value.<cffunction name="setParameter" access="public" returntype="void" output="false" hint="Sets a configuration parameter."> <cfargument name="name" type="string" required="true" hint="The parameter name." /> <cfargument name="value" required="true" hint="The parameter value." /> <cfset variables.parameters[arguments.name] = arguments.value /> </cffunction>
public void setParameters(struct parameters)
struct parameters<cffunction name="setParameters" access="public" returntype="void" output="false" hint="Sets the full set of configuration parameters for the component."> <cfargument name="parameters" type="struct" required="true" /> <cfset var key = "" /> <cfloop collection="#arguments.parameters#" item="key"> <cfset setParameter(key, parameters[key]) /> </cfloop> </cffunction>
public any setProperty(string propertyName, any propertyValue)
string propertyName - The name of the property to set.any propertyValue - The value to store in the property.<cffunction name="setProperty" access="public" returntype="any" output="false" hint="Sets the specified property - this is just a shortcut for getPropertyManager().setProperty()"> <cfargument name="propertyName" type="string" required="true" hint="The name of the property to set."/> <cfargument name="propertyValue" type="any" required="true" hint="The value to store in the property." /> <cfreturn getPropertyManager().setProperty(arguments.propertyName, arguments.propertyValue) /> </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
$Id: BaseComponent.cfc 485 2007-09-08 03:18:25Z pfarrell $
Created version: 1.0.10
Updated version: 1.5.0
Notes:
The BaseComponent extended by Listener, EventFilter and Plugin components and gives
quick access to things such as announcing a new event or getting/setting properties.
- Implemented accessors to access the PropertyManager instead of direct name space
calling. (pfarrell)
- Deprecated hasParameter(). Duplicate method isParameterDefined is more inline with
the rest of the framework. (pfarrell)
--->
<cfcomponent
displayname="Mach-II Base Component"
output="false"
hint="Base Mach-II component.">
<!---
PROPERTIES
--->
<cfset variables.appManager = "" />
<cfset variables.parameters = StructNew() />
<!---
INITIALIZATION / CONFIGURATION
--->
<cffunction name="init" access="public" returntype="void" output="false"
hint="Used by the framework for initialization. Do not override.">
<cfargument name="appManager" type="MachII.framework.AppManager" required="true"
hint="The framework instances' AppManager." />
<cfargument name="parameters" type="struct" required="false" default="#StructNew()#"
hint="The initial set of configuration parameters." />
<!--- PropertyManager be in set after AppManager --->
<cfset setAppManager(arguments.appManager) />
<cfset setParameters(arguments.parameters) />
</cffunction>
<cffunction name="configure" access="public" returntype="void" output="false"
hint="Override to provide custom configuration logic. Called after init().">
<!--- Does nothing --->
</cffunction>
<!---
PUBLIC FUNCTIONS
--->
<cffunction name="announceEvent" access="public" returntype="void" output="false"
hint="Announces a new event to the framework.">
<cfargument name="eventName" type="string" required="true"
hint="The name of the event to announce." />
<cfargument name="eventArgs" type="struct" required="false" default="#StructNew()#"
hint="A struct of arguments to set as the event's args." />
<cfset var appKey = getAppManager().getAppLoader().getAppKey() />
<cfif StructKeyExists(request, "_MachIIRequestHandler_" & appKey)>
<cfset request["_MachIIRequestHandler_" & appKey].getEventContext().announceEvent(arguments.eventName, arguments.eventArgs) />
<cfelse>
<cfthrow message="The required RequestHandler is necessary to announce events is not set in 'request['_MachIIRequestHandler_#appKey#']'." />
</cfif>
</cffunction>
<cffunction name="announceEventInModule" access="public" returntype="void" output="false"
hint="Announces a new event to the framework.">
<cfargument name="moduleName" type="string" required="true"
hint="The name of the module in which event exists." />
<cfargument name="eventName" type="string" required="true"
hint="The name of the event to announce." />
<cfargument name="eventArgs" type="struct" required="false" default="#StructNew()#"
hint="A struct of arguments to set as the event's args." />
<cfset var appKey = getAppManager().getAppLoader().getAppKey() />
<cfif StructKeyExists(request, "_MachIIRequestHandler_" & appKey)>
<cfset request["_MachIIRequestHandler_" & appKey].getEventContext().announceEvent(arguments.eventName, arguments.eventArgs, arguments.moduleName) />
<cfelse>
<cfthrow message="The required RequestHandler is necessary to announce events is not set in 'request['_MachIIRequestHandler_#appKey#']'." />
</cfif>
</cffunction>
<cffunction name="buildUrl" access="public" returntype="string" output="false"
hint="Builds a framework specific url with module name.">
<cfargument name="eventName" type="string" required="true"
hint="Name of the event to build the url with." />
<cfargument name="urlParameters" type="any" required="false" default=""
hint="Name/value pairs (urlArg1=value1|urlArg2=value2) to build the url with or a struct of data." />
<cfargument name="urlBase" type="string" required="false"
hint="Base of the url. Defaults to the value of the urlBase property." />
<cfset var appKey = getAppManager().getAppLoader().getAppKey() />
<!--- Grab the module name from the context of the currently executing request--->
<cfset arguments.moduleName = request["_MachIIRequestHandler_" & appKey].getEventContext().getAppManager().getModuleName() />
<cfreturn getAppManager().getRequestManager().buildUrl(argumentcollection=arguments) />
</cffunction>
<cffunction name="buildUrlToModule" access="public" returntype="string" output="false"
hint="Builds a framework specific url.">
<cfargument name="moduleName" type="string" required="true"
hint="Name of the module to build the url with. Defaults to base module if empty string." />
<cfargument name="eventName" type="string" required="true"
hint="Name of the event to build the url with." />
<cfargument name="urlParameters" type="any" required="false" default=""
hint="Name/value pairs (urlArg1=value1|urlArg2=value2) to build the url with or a struct of data." />
<cfargument name="urlBase" type="string" required="false"
hint="Base of the url. Defaults to the value of the urlBase property." />
<cfreturn getAppManager().getRequestManager().buildUrl(argumentcollection=arguments) />
</cffunction>
<cffunction name="setParameter" access="public" returntype="void" output="false"
hint="Sets a configuration parameter.">
<cfargument name="name" type="string" required="true"
hint="The parameter name." />
<cfargument name="value" required="true"
hint="The parameter value." />
<cfset variables.parameters[arguments.name] = arguments.value />
</cffunction>
<cffunction name="getParameter" access="public" returntype="any" output="false"
hint="Gets a configuration parameter value, or a default value if not defined.">
<cfargument name="name" type="string" required="true"
hint="The parameter name." />
<cfargument name="defaultValue" type="string" required="false" default=""
hint="The default value to return if the parameter is not defined. Defaults to a blank string." />
<cfif isParameterDefined(arguments.name)>
<cfreturn bindValue(arguments.name) />
<cfelse>
<cfreturn arguments.defaultValue />
</cfif>
</cffunction>
<cffunction name="isParameterDefined" access="public" returntype="boolean" output="false"
hint="Checks to see whether or not a configuration parameter is defined.">
<cfargument name="name" type="string" required="true"
hint="The parameter name." />
<cfreturn StructKeyExists(variables.parameters, arguments.name) />
</cffunction>
<cffunction name="hasParameter" access="public" returntype="boolean" output="false"
hint="DEPRECATED - use isParameterDefined() instead. Checks to see whether or not a configuration parameter is defined.">
<cfargument name="name" type="string" required="true"
hint="The parameter name." />
<cftry>
<cfthrow type="MachII.framework.deprecatedMethod"
message="The hasParameter() method has been deprecated. Please use isParameterDefined() instead." />
<cfcatch type="MachII.framework.deprecatedMethod">
<!--- Do nothing --->
</cfcatch>
</cftry>
<cfreturn StructKeyExists(variables.parameters, arguments.name) />
</cffunction>
<cffunction name="getProperty" access="public" returntype="any" output="false"
hint="Gets the specified property - this is just a shortcut for getPropertyManager().getProperty()">
<cfargument name="propertyName" type="string" required="true"
hint="The name of the property to return."/>
<cfreturn getPropertyManager().getProperty(arguments.propertyName) />
</cffunction>
<cffunction name="setProperty" access="public" returntype="any" output="false"
hint="Sets the specified property - this is just a shortcut for getPropertyManager().setProperty()">
<cfargument name="propertyName" type="string" required="true"
hint="The name of the property to set."/>
<cfargument name="propertyValue" type="any" required="true"
hint="The value to store in the property." />
<cfreturn getPropertyManager().setProperty(arguments.propertyName, arguments.propertyValue) />
</cffunction>
<!---
PROTECTED FUNCTIONS
--->
<cffunction name="bindValue" access="private" returntype="any" output="false"
hint="Binds placeholders values in parameters.">
<cfargument name="parameterName" type="string" required="true"
hint="The parameter name." />
<cfset var propertyName = "" />
<cfset var value = variables.parameters[arguments.parameterName] />
<!--- Can only bind simple parameter values --->
<cfif IsSimpleValue(value) AND REFindNoCase("\${(.)*?}", value)>
<cfset propertyName = Mid(value, 3, Len(value) -3) />
<cfif getPropertyManager().isPropertyDefined(propertyName)>
<cfset value = getProperty(propertyName) />
<cfelse>
<cfthrow type="MachII.framework.ProperyNotDefinedToBindToParameter"
message="The required property is not defined to bind to a parameter named '#arguments.parameterName#'." />
</cfif>
</cfif>
<cfreturn value />
</cffunction>
<!---
ACCESSORS
--->
<cffunction name="setParameters" access="public" returntype="void" output="false"
hint="Sets the full set of configuration parameters for the component.">
<cfargument name="parameters" type="struct" required="true" />
<cfset var key = "" />
<cfloop collection="#arguments.parameters#" item="key">
<cfset setParameter(key, parameters[key]) />
</cfloop>
</cffunction>
<cffunction name="getParameters" access="public" returntype="struct" output="false"
hint="Gets the full set of configuration parameters for the component.">
<cfset var key = "" />
<cfset var resolvedParameters = StructNew() />
<!--- Get values and bind placeholders --->
<cfloop collection="#variables.parameters#" item="key">
<cfset resolvedParameters[key] = bindValue(key) />
</cfloop>
<cfreturn resolvedParameters />
</cffunction>
<cffunction name="setAppManager" access="private" returntype="void" output="false"
hint="Sets the components AppManager instance.">
<cfargument name="appManager" type="MachII.framework.AppManager" required="true"
hint="The AppManager instance to set." />
<cfset variables.appManager = arguments.appManager />
</cffunction>
<cffunction name="getAppManager" access="public" returntype="MachII.framework.AppManager" output="false"
hint="Gets the components AppManager instance.">
<cfreturn variables.appManager />
</cffunction>
<cffunction name="getPropertyManager" access="public" returntype="MachII.framework.PropertyManager" output="false"
hint="Gets the components PropertyManager instance.">
<cfreturn getAppManager().getPropertyManager() />
</cffunction>
</cfcomponent>