-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDefaultTypeDelegate.cfc
57 lines (35 loc) · 1.39 KB
/
DefaultTypeDelegate.cfc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<cfcomponent output="false">
<cffunction name="setData" returntype="void" access="public" output="false">
<cfargument name="data" type="any" required="true" />
<cfset variables.cacheData = arguments.data />
</cffunction>
<cffunction name="getEmptyData" returntype="any" access="public" output="false">
<cfset var aKey = '' />
<cfset var emptydata = 0 />
<cfset var fulltype = variables.cacheData.GetClass() />
<cfset var type = ReReplace('#fullType#','\w+\s\w+\.\w+\.(\w+)','\1','ONE') />
<cfswitch expression="#type#">
<cfcase value="String">
<cfset emptydata = "" />
</cfcase>
<cfcase value="Boolean">
<cfset emptydata = false />
</cfcase>
<cfcase value="Struct">
<!--- create a struct of empty keys that match the data's keys --->
<cfset emptydata = StructNew() />
<cfloop list="#StructKeyList( variables.cacheData )#" index="aKey">
<cfset emptydata['#aKey#'] = '' />
</cfloop>
</cfcase>
<cfcase value="QueryTable">
<!--- create an empty query from a new column list --->
<cfset emptydata = QueryNew( variables.cacheData.ColumnList ) />
</cfcase>
<cfdefaultcase>
<cfthrow message="Unknown Type" detail="getEmptySet was passsed a type (#type#) that is unknown and cannot be defaulted." />
</cfdefaultcase>
</cfswitch>
<cfreturn emptydata />
</cffunction>
</cfcomponent>