Sorcerer's IsleCode QueryParam Scanner / files

     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		// arguments - string default ""
    21		if (not structKeyExists(fb_.verbInfo.attributes,"arguments")) {
    22			// prepare to gather up <argument> tags, if any:
    23			fb_.verbInfo.data.arguments = "";
    24			fb_.verbInfo.data.separator = "";
    25		} else {
    26			fb_.nAttrs = fb_.nAttrs + 1;	// for arguments - since we do not default it
    27			if (fb_.verbInfo.hasChildren) {
    28				fb_throw("fusebox.badGrammar.unexpectedChildren",
    29							"Unexpected child verbs",
    30							"The 'instantiate' verb cannot have children when using the 'arguments' attribute, in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
    31			}
    32		}
    33		// class - string default ""
    34		// webservice - string default ""
    35		// one of class or webservice must be present
    36		if (not structKeyExists(fb_.verbInfo.attributes,"class")) {
    37			if (not structKeyExists(fb_.verbInfo.attributes,"webservice")) {
    38				// error: class or webservice must be present
    39				fb_throw("fusebox.badGrammar.requiredAttributeMissing",
    40							"Required attribute is missing",
    41							"Either the attribute 'class' or 'webservice' is required, for a 'instantiate' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
    42			} else {
    43				// webservice
    44			}
    45		} else {
    46			if (not structKeyExists(fb_.verbInfo.attributes,"webservice")) {
    47				// class
    48			} else {
    49				// error: only one of class or webservice may be present
    50				fb_throw("fusebox.badGrammar.requiredAttributeMissing",
    51							"Required attribute is missing",
    52							"Either the attribute 'class' or 'webservice' is required, for a 'instantiate' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
    53			}
    54		}
    55		fb_.nAttrs = fb_.nAttrs + 1;	// for either one of class or webservice
    56		// object - string - required
    57		if (not structKeyExists(fb_.verbInfo.attributes,"object")) {
    58			fb_throw("fusebox.badGrammar.requiredAttributeMissing",
    59						"Required attribute is missing",
    60						"The attribute 'object' is required, for a 'instantiate' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
    61		}
    62		fb_.nAttrs = fb_.nAttrs + 1;	// for object
    63		// overwrite - boolean default true
    64		if (structKeyExists(fb_.verbInfo.attributes,"overwrite")) {
    65			if (listFind("true,false,yes,no",fb_.verbInfo.attributes.overwrite) eq 0) {
    66				fb_throw("fusebox.badGrammar.invalidAttributeValue",
    67							"Attribute has invalid value",
    68							"The attribute 'overwrite' must either be ""true"" or ""false"", for a 'instantiate' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
    69			}
    70		} else {
    71			fb_.verbInfo.attributes.overwrite = true;
    72		}
    73		fb_.nAttrs = fb_.nAttrs + 1;	// for overwrite - since we default it
    74		// strict mode - check attribute count:
    75		if (fb_.verbInfo.action.getCircuit().getApplication().strictMode) {
    76			if (structCount(fb_.verbInfo.attributes) neq fb_.nAttrs) {
    77				fb_throw("fusebox.badGrammar.unexpectedAttributes",
    78							"Unexpected attributes",
    79							"Unexpected attributes were found in a 'instantiate' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
    80			}
    81		}
    82	
    83	} else {
    84		
    85		// update arguments if we had any child <argument> tags:
    86		if (structKeyExists(fb_.verbInfo.attributes,"arguments")) {
    87			fb_.args = fb_.verbInfo.attributes.arguments;
    88		} else {
    89			fb_.args = fb_.verbInfo.data.arguments;
    90		}
    91
    92		// compile <instantiate>
    93		fb_.obj = fb_.verbInfo.attributes.object;
    94		fb_.constructor = "";
    95		if (find("##",fb_.obj) gt 0) {
    96			fb_.obj = '"' & fb_.obj & '"';
    97		}
    98		if (structKeyExists(fb_.verbInfo.attributes,"class")) {
    99			// look up the class definition:
   100			fb_.classDef = fb_.verbInfo.action.getCircuit().getApplication().getClassDefinition(fb_.verbInfo.attributes.class);
   101			fb_.creation = 'createObject("#fb_.classDef.type#","#fb_.classDef.classpath#")';
   102			fb_.constructor = fb_.classDef.constructor;
   103		} else {
   104			fb_.creation = 'createObject("webservice","#fb_.verbInfo.attributes.webservice#")';
   105		}
   106		// I'd rather the constructor was called immediately on construction but it can't be guaranteed that the constructor returns this
   107		if (fb_.verbInfo.attributes.overwrite) {
   108			fb_appendLine('<cfset #fb_.obj# = #fb_.creation# >');
   109			if (fb_.constructor is not "") {
   110				fb_appendLine('<cfset #fb_.obj#.#fb_.constructor#(#fb_.args#) >');
   111			} else if (fb_.args is not "") {
   112				fb_throw("fusebox.badGrammar.invalidAttributeValue",
   113							"Attribute has invalid value",
   114							"Arguments may not be specified when there is no constructor specified for the class.");
   115			}
   116		} else {
   117			fb_appendLine('<cfif not isDefined("#fb_.verbInfo.attributes.object#")>');
   118			fb_appendLine('<cfset #fb_.obj# = #fb_.creation# >');
   119			if (fb_.constructor is not "") {
   120				fb_appendLine('<cfset #fb_.obj#.#fb_.constructor#(#fb_.args#) >');
   121			} else if (fb_.args is not "") {
   122				fb_throw("fusebox.badGrammar.invalidAttributeValue",
   123							"Attribute has invalid value",
   124							"Arguments may not be specified when there is no constructor specified for the class.");
   125			}
   126			fb_appendLine('</cfif>');
   127		}
   128	}
   129</cfscript>