root / framework / tags / fusebox5RC1 / fuseboxFactory.cfc

Revision 185, 6.9 kB (checked in by scorfield, 3 years ago)

Lots of tuning! Fixes #10 but breaks #30 (which I think I will just punt on).
Lots of duck typing going on now to make things faster.
Also far fewer calls into the writer and far fewer calls happening inside the writer itself.

Line 
1<!---
2Fusebox Software License
3Version 1.0
4
5Copyright (c) 2003, 2004, 2005, 2006 The Fusebox Corporation. All rights reserved.
6
7Redistribution and use in source and binary forms, with or without modification, are permitted
8provided that the following conditions are met:
9
101. Redistributions of source code must retain the above copyright notice, this list of conditions
11   and the following disclaimer.
12
132. Redistributions in binary form or otherwise encrypted form must reproduce the above copyright
14   notice, this list of conditions and the following disclaimer in the documentation and/or other
15   materials provided with the distribution.
16
173. The end-user documentation included with the redistribution, if any, must include the following
18   acknowledgment:
19
20   "This product includes software developed by the Fusebox Corporation (http://www.fusebox.org/)."
21
22   Alternately, this acknowledgment may appear in the software itself, if and wherever such
23   third-party acknowledgments normally appear.
24
254. The names "Fusebox" and "Fusebox Corporation" must not be used to endorse or promote products
26   derived from this software without prior written (non-electronic) permission. For written
27   permission, please contact fusebox@fusebox.org.
28
295. Products derived from this software may not be called "Fusebox", nor may "Fusebox" appear in
30   their name, without prior written (non-electronic) permission of the Fusebox Corporation. For
31   written permission, please contact fusebox@fusebox.org.
32
33If one or more of the above conditions are violated, then this license is immediately revoked and
34can be re-instated only upon prior written authorization of the Fusebox Corporation.
35
36THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38DISCLAIMED. IN NO EVENT SHALL THE FUSEBOX CORPORATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY
39DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
41BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
42STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
43OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44
45-------------------------------------------------------------------------------
46
47This software consists of voluntary contributions made by many individuals on behalf of the
48Fusebox Corporation. For more information on Fusebox, please see <http://www.fusebox.org/>.
49
50--->
51<cfcomponent output="false" hint="I am a factory object that creates verb objects.">
52
53        <cffunction name="init" returntype="fuseboxFactory" access="public" output="false"
54                                hint="I am the constructor.">
55               
56                <cfset variables.lexCompPool = 0 />
57                <cfset variables.verbLexPool = 0 />
58               
59                <cfset variables.fuseboxLexicon = structNew()/>
60                <cfset variables.fuseboxLexicon.namespace = "$fusebox" />
61                <cfset variables.fuseboxLexicon.path = "verbs/" />
62               
63                <cfreturn this />
64               
65        </cffunction>
66       
67        <cffunction name="create" returntype="any" access="public" output="false"
68                                hint="I create a verb object.">
69                <cfargument name="verb" type="string" required="true"
70                                        hint="I am the name of the verb to create." />
71                <cfargument name="action" type="any" required="true"
72                                        hint="I am the enclosing fuseaction object." />
73                <cfargument name="attributes" type="struct" required="true"
74                                        hint="I am the attributes of this verb." />
75                <cfargument name="children" type="any" required="true"
76                                        hint="I am the XML representation of this verb's children." />
77                <cfargument name="global" type="boolean" default="false"
78                                        hint="I indicate whether this is part of a regular fuseaction (false) or a global fuseaction (true)." />
79               
80                <cfset var verbObject = "" />
81               
82                <!--- global pre/post process is a special case: --->
83                <cfif arguments.global>
84                        <cfif listFind("do,fuseaction",arguments.verb)>
85                                <!--- this is OK, do is deprecated --->
86                                <cfif arguments.verb is "do" and arguments.action.getCircuit().getApplication().strictMode>
87                                        <cfthrow type="fusebox.badGrammar.deprecated"
88                                                        message="Deprecated feature"
89                                                        detail="Using the 'do' verb in a global pre/post process was deprecated in Fusebox 4.1." />
90                                </cfif>
91                        <cfelse>
92                                <!--- no other verbs are allowed --->
93                                <cfthrow type="fusebox.badGrammar.illegalVerb"
94                                                message="Illegal verb encountered"
95                                                detail="The '#arguments.verb#' verb is illegal in a global pre/post process." />
96                        </cfif>
97                <cfelse>
98                        <cfif listFind("fuseaction",arguments.verb)>
99                                <!--- verbs that are only legal in global pre/post process --->
100                                <cfthrow type="fusebox.badGrammar.illegalVerb"
101                                                message="Illegal verb encountered"
102                                                detail="The '#arguments.verb#' verb is only legal in a global pre/post process." />
103                        </cfif>
104                </cfif>
105                <cfif listLen(arguments.verb,".:") eq 2>
106                        <!--- must be namespace.verb or namespace:verb --->
107                        <cfset verbObject = createObject("component","fuseboxVerb")
108                                        .init(arguments.action, arguments.verb, arguments.attributes, arguments.children) />
109                <cfelseif listFind("do,fuseaction",arguments.verb)>
110                        <!--- built-in verbs that cannot be implemented as a lexicon --->
111                        <cfset verbObject = createObject("component","fuseboxDoFuseaction")
112                                        .init(arguments.action,arguments.attributes,arguments.children,arguments.verb) />
113                <cfelse>
114                        <!--- builtin verb implemented as a lexicon --->
115                        <cfset verbObject = createObject("component","fuseboxVerb")
116                                        .init(arguments.action, variables.fuseboxLexicon.namespace & ":" & arguments.verb,
117                                                        arguments.attributes, arguments.children) />
118                </cfif>
119                <cfreturn verbObject />
120               
121        </cffunction>
122       
123        <cffunction name="createLexiconCompiler" returntype="any" access="public" output="false"
124                                hint="I return a lexicon compiler context (either from the pool or a newly created instance).">
125       
126                <cfset var obj = 0 />
127               
128                <cfif isSimpleValue(variables.lexCompPool)>
129                        <cfset obj = createObject("component","fuseboxLexiconCompiler") />
130                <cfelse>
131                        <cfset obj = variables.lexCompPool />
132                        <cfset variables.lexCompPool = obj._next />
133                </cfif>
134               
135                <cfreturn obj />
136       
137        </cffunction>
138       
139        <cffunction name="freeLexiconCompiler" returntype="void" access="public" output="false"
140                                hint="I return the lexicon compiler context to the pool.">
141                <cfargument name="lexComp" type="any" required="false"
142                                        hint="I am the lexicon compiler context to be returned. I am required but it's faster to specify that I am not required." />
143       
144                <cfset arguments.lexComp._next = variables.lexCompPool />
145                <cfset variables.lexCompPool = arguments.lexComp />
146               
147        </cffunction>
148       
149        <cffunction name="getBuiltinLexicon" returntype="any" access="public" output="false"
150                                hint="I return the (magic) builtin lexicon.">
151               
152                <cfreturn variables.fuseboxLexicon />
153               
154        </cffunction>
155       
156</cfcomponent>
Note: See TracBrowser for help on using the browser.