PropertyManager

Package: MachII.framework
Manages defined properties for the framework.

<!--- License: Copyright 2006 Mach-II Corporation 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: Mach-II Corporation $Id: PropertyManager.cfc 4516 2006-09-30 20:55:17Z pfarrell $ Created version: 1.0.0 Updated version: 1.1.1 Notes: - Deprecated hasProperty(). Duplicate method isPropertyDefined is more inline with the rest of the framework. (pfarrell) - Added method to get Mach-II framework version (pfarrell) --->

Method Summary
public void init(string configXML, AppManager appManager, string version)

Initialization function called by the framework.

public void configure()

Prepares the manager for use.

public AppManager getAppManager()
public struct getProperties()

Returns all properties.

public any getProperty(string propertyName, [any defaultValue=""])

Returns the property value by name. If the property is not defined, and a default value is passed, it will be returned. If the property and a default value are both not defined then an exception is thrown.

public string getVersion()

Gets the version number of the framework.

public boolean hasProperty(string propertyName)

DEPRECATED - use isPropertyDefined() instead. Checks if property name is deinfed in the propeties.

public boolean isPropertyDefined(string propertyName)

Checks if property name is defined in the properties.

public void setAppManager(AppManager appManager)
public void setProperty(string propertyName, any propertyValue)

Sets the property value by name.

private void setVersion(string version)
Method Detail
configure

public void configure( )

Prepares the manager for use.

Parameters:

Code:

	<cffunction name="configure" access="public" returntype="void" output="false"
		hint="Prepares the manager for use.">
		
	</cffunction> 

getAppManager

public AppManager getAppManager( )

Parameters:

Code:

	<cffunction name="getAppManager" access="public" returntype="MachII.framework.AppManager" output="false">
		<cfreturn variables.appManager />
	</cffunction> 

getProperties

public struct getProperties( )

Returns all properties.

Parameters:

Code:

	<cffunction name="getProperties" access="public" returntype="struct" output="false"
		hint="Returns all properties.">
		<cfreturn variables.properties />
	</cffunction> 

getProperty

public any getProperty( string propertyName, [any defaultValue=""] )

Returns the property value by name. If the property is not defined, and a default value is passed, it will be returned. If the property and a default value are both not defined then an exception is thrown.

Parameters:
string propertyName
[any defaultValue=""]

Code:

	<cffunction name="getProperty" access="public" returntype="any" output="false"
		hint="Returns the property value by name. If the property is not defined, and a default value is passed, it will be returned. If the property and a default value are both not defined then an exception is thrown.">
		<cfargument name="propertyName" type="string" required="true" />
		<cfargument name="defaultValue" type="any" required="false" default="" />
		
		<cfif isPropertyDefined(arguments.propertyName)>
			<cfreturn variables.properties[arguments.propertyName] />
		<cfelseif StructKeyExists(arguments, 'defaultValue')>
			<cfreturn arguments.defaultValue />
		<cfelse>
			
			<cfthrow type="MachII.framework.PropertyNotDefined" 
				message="Property with name '#arguments.propertyName#' is not defined." />
		</cfif>
	</cffunction> 

getVersion

public string getVersion( )

Gets the version number of the framework.

Parameters:

Code:

	<cffunction name="getVersion" access="public" returntype="string" output="false"
		hint="Gets the version number of the framework.">
		<cfreturn variables.version />
	</cffunction> 

hasProperty

public boolean hasProperty( string propertyName )

DEPRECATED - use isPropertyDefined() instead. Checks if property name is deinfed in the propeties.

Parameters:
string propertyName

Code:

	<cffunction name="hasProperty" access="public" returntype="boolean" output="false"
		hint="DEPRECATED - use isPropertyDefined() instead. Checks if property name is deinfed in the propeties.">
		<cfargument name="propertyName" type="string" required="true" />
		<cfreturn StructKeyExists(variables.properties, arguments.propertyName) />
	</cffunction> 

init

public void init( string configXML, AppManager appManager, string version )

Initialization function called by the framework.

Parameters:
string configXML
AppManager appManager
string version

Code:

	<cffunction name="init" access="public" returntype="void" output="false"
		hint="Initialization function called by the framework.">
		<cfargument name="configXML" type="string" required="true" />
		<cfargument name="appManager" type="MachII.framework.AppManager" required="true" />
		<cfargument name="version" type="string" required="true" />
		
		<cfset var xnProperties = "" />
		<cfset var i = 0 />
		
		<cfset setAppManager(arguments.appManager) />
		<cfset setVersion(arguments.version) />

		
		<cfset xnProperties = XMLSearch(configXML,'//property') />

		<cfloop from="1" to="#ArrayLen(xnProperties)#" index="i">
			<cfset setProperty(xnProperties[i].xmlAttributes.name, xnProperties[i].xmlAttributes.value) />
		</cfloop>
		
		
		<cfif NOT isPropertyDefined('defaultEvent')>
			<cfset setProperty('defaultEvent', 'defaultEvent') />
		</cfif>
		<cfif NOT isPropertyDefined('exceptionEvent')>
			<cfset setProperty('exceptionEvent', 'exceptionEvent') />
		</cfif>
		<cfif NOT isPropertyDefined('applicationRoot')>
			<cfset setProperty('applicationRoot', '') />
		</cfif>
		<cfif NOT isPropertyDefined('eventParameter')>
			<cfset setProperty('eventParameter', 'event') />
		</cfif>
		<cfif NOT isPropertyDefined('parameterPrecedence')>
			<cfset setProperty('parameterPrecedence', 'form') />
		</cfif>
		<cfif NOT isPropertyDefined('maxEvents')>
			<cfset setProperty('maxEvents', 10) />
		</cfif>
	</cffunction> 

isPropertyDefined

public boolean isPropertyDefined( string propertyName )

Checks if property name is defined in the properties.

Parameters:
string propertyName

Code:

	<cffunction name="isPropertyDefined" access="public" returntype="boolean" output="false"
		hint="Checks if property name is defined in the properties.">
		<cfargument name="propertyName" type="string" required="true" />
		<cfreturn StructKeyExists(variables.properties, arguments.propertyName) />
	</cffunction> 

setAppManager

public void setAppManager( AppManager appManager )

Parameters:
AppManager appManager

Code:

	<cffunction name="setAppManager" access="public" returntype="void" output="false">
		<cfargument name="appManager" type="MachII.framework.AppManager" required="true" />
		<cfset variables.appManager = arguments.appManager />
	</cffunction> 

setProperty

public void setProperty( string propertyName, any propertyValue )

Sets the property value by name.

Parameters:
string propertyName
any propertyValue

Code:

	<cffunction name="setProperty" access="public" returntype="void" output="false"
		hint="Sets the property value by name.">
		<cfargument name="propertyName" type="string" required="true" />
		<cfargument name="propertyValue" type="any" required="true" />
		<cfset variables.properties[arguments.propertyName] = arguments.propertyValue />
	</cffunction> 

setVersion

private void setVersion( string version )

Parameters:
string version

Code:

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