root / framework / branches / dev / fuseboxEvent.cfc

Revision 302, 2.9 kB (checked in by scorfield, 2 years ago)

Fixed getValue() - reported by Qasim Rasheed.

Line 
1<cfcomponent output="false" hint="I am a simple object wrapper for attributes scope.">
2<!---
3Copyright 2006 TeraTech, Inc. http://teratech.com/
4
5Licensed under the Apache License, Version 2.0 (the "License");
6you may not use this file except in compliance with the License.
7You may obtain a copy of the License at
8
9http://www.apache.org/licenses/LICENSE-2.0
10
11Unless required by applicable law or agreed to in writing, software
12distributed under the License is distributed on an "AS IS" BASIS,
13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14See the License for the specific language governing permissions and
15limitations under the License.
16--->
17
18        <cffunction name="init" returntype="any" access="public" output="false"
19                                hint="I am the constructor.">
20                <cfargument name="attributes" type="struct" required="true"
21                                        hint="I am the attributes scope passed in." />
22               
23                <cfset variables.attributes = arguments.attributes />
24               
25                <cfreturn this />
26       
27        </cffunction>
28
29        <cffunction name="getValue" returntype="any" access="public" output="false"
30                                hint="I return a given attribute value, or the default if it is not present.">
31                <cfargument name="valueName" type="string" required="true"
32                                        hint="I am the name of the attribute to return." />
33                <cfargument name="defaultValue" type="any" default=""
34                                        hint="I am the default value to return if the given attribute is missing." />
35
36                <cfif valueExists(arguments.valueName)>
37                        <cfreturn variables.attributes[arguments.valueName] />
38                <cfelse>
39                        <cfreturn arguments.defaultValue />
40                </cfif>
41
42        </cffunction>
43
44        <cffunction name="valueExists" returntype="boolean" access="public" output="false"
45                                hint="I check with a given attribute value is present.">
46                <cfargument name="valueName" type="string" required="true"
47                                        hint="I am the name of the attribute to check." />
48
49                <cfreturn structKeyExists(variables.attributes,arguments.valueName) />
50
51        </cffunction>
52
53        <cffunction name="setValue" returntype="void" access="public" output="false"
54                                hint="I update the given attribute value.">
55                <cfargument name="valueName" type="string" required="true"
56                                        hint="I am the name of the attribute to update." />
57                <cfargument name="newValue" type="any" required="true"
58                                        hint="I am the new value for the given attribute." />
59               
60                <cfset variables.attributes[arguments.valueName] = arguments.newValue />
61
62        </cffunction>
63
64        <cffunction name="getAllValues" returntype="any" access="public" output="false"
65                                hint="I return a struct containing all the attribute values - this is a reference to the actual attributes scope.">
66               
67                <cfreturn variables.attributes />
68
69        </cffunction>
70
71        <cffunction name="removeValue" returntype="void" access="public" output="false"
72                                hint="I remove a given attribute's value.">
73                <cfargument name="valueName" type="string" required="true"
74                                        hint="I am the name of the attribute to remove." />
75
76                <cfset structDelete(variables.attributes,arguments.valueName) />
77
78        </cffunction>
79
80</cfcomponent>
Note: See TracBrowser for help on using the browser.