1<!---
2Copyright 2006-2007 TeraTech, Inc. http://teratech.com/
3 4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7 8http://www.apache.org/licenses/LICENSE-2.0
9 10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15--->
16<cfscript>
17 if (fb_.verbInfo.executionMode is "start") {
18 // validate attributes
19 fb_.nAttrs = 0;
20 // class - string default ""
21 // object - string default ""
22 // webservice - string default ""
23 // one of class / object / webservice must be present
24 if (not structKeyExists(fb_.verbInfo.attributes,"class")) {
25 if (not structKeyExists(fb_.verbInfo.attributes,"object")) {
26 if (not structKeyExists(fb_.verbInfo.attributes,"webservice")) {
27 // error: class or object or webservice must be present
28 fb_throw("fusebox.badGrammar.requiredAttributeMissing",
29 "Required attribute is missing",
30 "One of the attributes 'class', 'object' or 'webservice' is required, for a 'invoke' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
31 } else {
32 // webservice
33 }
34 } else {
35 if (not structKeyExists(fb_.verbInfo.attributes,"webservice")) {
36 // object
37 } else {
38 // error: only one of class or object or webservice may be present
39 fb_throw("fusebox.badGrammar.requiredAttributeMissing",
40 "Required attribute is missing",
41 "One of the attributes 'class', 'object' or 'webservice' is required, for a 'invoke' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
42 }
43 }
44 } else {
45 if (structKeyExists(fb_.verbInfo.attributes,"object") or
46 structKeyExists(fb_.verbInfo.attributes,"webservice")) {
47 // error: only one of class or object or webservice may be present
48 fb_throw("fusebox.badGrammar.requiredAttributeMissing",
49 "Required attribute is missing",
50 "One of the attributes 'class', 'object' or 'webservice' is required, for a 'invoke' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
51 } else {
52 // class
53 }
54 }
55 fb_.nAttrs = fb_.nAttrs + 1; // for any one of class, object or webservice
56 // methodcall - string default ""
57 // method - string default "" (new in FB5)
58 // one of methodcall or method must be present
59 if (not structKeyExists(fb_.verbInfo.attributes,"methodcall")) {
60 if (not structKeyExists(fb_.verbInfo.attributes,"method")) {
61 fb_throw("fusebox.badGrammar.requiredAttributeMissing",
62 "Required attribute is missing",
63 "One of the attributes 'methodcall' or 'method' is required, for a 'invoke' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
64 } else {
65 // method - prepare to gather up <argument> tags:
66 fb_.verbInfo.data.arguments = "";
67 fb_.verbInfo.data.separator = "";
68 }
69 } else {
70 if (not structKeyExists(fb_.verbInfo.attributes,"method")) {
71 // methodcall - FB41 compatible
72 if (fb_.verbInfo.hasChildren) {
73 fb_throw("fusebox.badGrammar.unexpectedChildren",
74 "Unexpected child verbs",
75 "The 'invoke' verb cannot have children when using the 'methodcall' attribute, in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
76 }
77 } else {
78 // error: only one of methodcall or method may be present
79 fb_throw("fusebox.badGrammar.requiredAttributeMissing",
80 "Required attribute is missing",
81 "One of the attributes 'methodcall' or 'method' is required, for a 'invoke' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
82 }
83 }
84 fb_.nAttrs = fb_.nAttrs + 1; // for either one of methodcall or method
85 // overwrite - boolean default true (if returnvariable is present)
86 if (structKeyExists(fb_.verbInfo.attributes,"overwrite")) {
87 if (listFind("true,false,yes,no",fb_.verbInfo.attributes.overwrite) eq 0) {
88 fb_throw("fusebox.badGrammar.invalidAttributeValue",
89 "Attribute has invalid value",
90 "The attribute 'overwrite' must either be ""true"" or ""false"", for a 'invoke' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
91 }
92 } else {
93 if (structKeyExists(fb_.verbInfo.attributes,"returnvariable")) {
94 fb_.verbInfo.attributes.overwrite = true;
95 } else {
96 fb_.verbInfo.attributes.overwrite = false;
97 }
98 }
99 fb_.nAttrs = fb_.nAttrs + 1; // for overwrite - since we default it
100 // returnvariable - string - required if overwrite is true
101 if (not structKeyExists(fb_.verbInfo.attributes,"returnvariable")) {
102 if (fb_.verbInfo.attributes.overwrite) {
103 fb_throw("fusebox.badGrammar.requiredAttributeMissing",
104 "Required attribute is missing",
105 "The attribute 'returnvariable' is required if 'overwrite' is 'true', for a 'invoke' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
106 }
107 // default to "" to make subsequent code easier
108 fb_.verbInfo.attributes.returnvariable = "";
109 }
110 fb_.nAttrs = fb_.nAttrs + 1; // for returnvariable - since we default it
111 // strict mode - check attribute count:
112 if (fb_.verbInfo.action.getCircuit().getApplication().strictMode) {
113 if (structCount(fb_.verbInfo.attributes) neq fb_.nAttrs) {
114 fb_throw("fusebox.badGrammar.unexpectedAttributes",
115 "Unexpected attributes",
116 "Unexpected attributes were found in a 'invoke' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
117 }
118 }
119 120 } else { // compile the code on the end tag:
121 122 // check whether we're using the old-style methodcall or the new-style method / argument form:
123 if (structKeyExists(fb_.verbInfo.attributes,"methodcall")) {
124 fb_.methodcall = fb_.verbInfo.attributes.methodcall;
125 } else {
126 // complete the method call:
127 fb_.methodcall = fb_.verbInfo.attributes.method & "(" & fb_.verbInfo.data.arguments & ")";
128 }
129 // compile <invoke>
130 fb_.ret = fb_.verbInfo.attributes.returnvariable;
131 if (structKeyExists(fb_.verbInfo.attributes,"object")) {
132 // handled
133 fb_.obj = fb_.verbInfo.attributes.object;
134 } else if (structKeyExists(fb_.verbInfo.attributes,"class")) {
135 // look it up
136 fb_.classDef = fb_.verbInfo.action.getCircuit().getApplication().getClassDefinition(fb_.verbInfo.attributes.class);
137 fb_.obj = 'createObject("#fb_.classDef.type#","#fb_.classDef.classpath#")';
138 } else if (structKeyExists(fb_.verbInfo.attributes,"webservice")) {
139 // this makes no sense but it's what the FB41 core files do:
140 fb_.obj = fb_.verbInfo.attributes.webservice;
141 }
142 if (find("##",fb_.ret) gt 0) {
143 fb_.ret = '"' & fb_.ret & '"';
144 }
145 if (fb_.verbInfo.attributes.overwrite) {
146 fb_appendLine('<cfset #fb_.ret# = #fb_.obj#.#fb_.methodcall# >');
147 } else {
148 if (fb_.verbInfo.attributes.returnvariable is not "") {
149 fb_appendLine('<cfif not isDefined("#fb_.verbInfo.attributes.returnvariable#")><cfset #fb_.ret# = #fb_.obj#.#fb_.methodcall# ></cfif>');
150 } else {
151 fb_appendLine('<cfset #fb_.obj#.#fb_.methodcall# >');
152 }
153 }
154 }
155</cfscript>