This documentation is not maintained. Please refer to doc.castsoftware.com/technologies to find the latest updates.

On this page:

Summary: this pages describes the castscript language

Note that the CAST Script / FlexFramework feature described in this page is deprecated. You should instead consider using the Extension SDK to handle XML configuration files.

Example castscript file

First of all take the following example castscript file stored in CAST_INSTALLATION_DIR\configuration\Script_Libraries\Core\EJB\ EJB3.castscript. This is only part of the entire script and focuses on the createEJBMDB function for EJBs. The goal of this castscript file is to create a Message Driven Bean whose name is ejbName and its associated class is ejbClassName. To do this, we will create the Message Driven Bean, the prototype link from the bean to the class and add a property on the EJB to set the class name:

module Core.EJB.EJB3;
use Core.J2EE;
use Core.ConstantsMetamodel;
use Core.Log;
use Core.Error;
 
void createEJBMDB(string ejbName, string ejbClassName)
{
	symbol ejbSym = findOrCreateSymbol(ejbName, JV_EJB_MESSAGE);
	if (ejbSym == null) {exit ("impossible to create the EJB MDB: " + ejbName);}
	log("created JV_EJB_MESSAGE: " + ejbName, DEBUG); 
	symbol ejbClassSym = findUniqueSymbol(ejbClassName, JV_CLASS);
	if (ejbClassSym == null) {exit ("impossible to find the class: " + ejbClassName);}
	addOrReplaceProperty(ejbSym, Cast_EJB_AllProperties_BeanClass, ejbClassName);
	createLink(ejbSym, ejbClassSym, prototypeLink);
	log("created link from JV_EJB_MESSAGE: " + ejbName + " to JV_CLASS: " + ejbClassName, DEBUG);
}
  • First you need to declare the module that is equal to the name of sub-directories starting from the "Custom CAST Script Library Root Path" directory + "." + the name of your file without the extension castscript.
  • Then you have to import any modules required to build your function
  • Declare your function with the type returned, its name and its parameters.
  • Use the Castscript Native Function findOrCreateSymbol to create the Message driven bean. Note that the object type set by the second parameter is a name that is defined in the Core.ConstantsMetamodel module. This will tell the J2EE Analyzer to create an EJB Message Driven Bean whose name will be the value of the parameter ejbName.
  • At any step of your Script, you can exit if an error that prevents you from continuing occurs with the exit function. This will report an error in the CAST Analysis Manager log and stop the parsing of this XML file
  • At any step of your script, you can log a message with the level DEBUG. This message will appear in the analysis log only if you select the Activate CAST Scripts trace checkbox when using the Run analysis only option. This function is very useful when you want to understand why a function doesn't work or if it produces the expected behavior.

castscript language content

Key words

booleanmodule
breaknull
casenative
continueprivate
constpublic  => default value
defaultreturn
deprecatedstring
elseswitch
falsesymbol
foreachtrue
ifuse
invoid
intwhile
list

Special characters

.Module qualifier
::Provides access to a module function
{start of a block
}end of a block
||OR logic
&&AND logic
==Equals
!=Different
=Allocation
+Numeric expression
-Numeric expression
*Numeric expression
/Numeric expression
^Numeric expression
;End of statement
<Less than
>More than
<=less than or equal to
>=more than or equal to
//Single line comment
/* */Multi line comment => non-nest as in C++
"Start or end of string: escape character \
'Start or end of character \
(
)
:For cases

Rules

compilation_unitmodule_statement
use_statement
declarations
module_statementmodule module_name ';'
use_statementuse module_name ';'
declarationsdeclaration
| declarations declaration
module_nameidentifier
|  module_name "." identifier
declarationfunction_declaration
|constant_declaration
constant_declaration[deprecated] const type identifier  '=' expression ';'
function_declaration[deprecated] [native] [private] functionReturn_type indentifier( parameterType parameterName, ...); 

Please note that native functions declaration is used only in castscript Core files and not available for custom castscript files.

boolean_valuetrue
| false
type :primitive_type
|  list '(' primitive_type ')'
primitive_type :int 
| string
| boolean
| symbol
function_declaration[deprecated] [private | public] return_type indentifier '(' list_param ')'  body
return_typetype
void
body'{' list_statement '}'
list_statementstatement
| list_statement statement
statementblock  | if_statement | assignment |  switch_statement | return_statement | continue_statement | while_statement | foreach_statement | break_statement
qualified_nameidentifier 
| module_name '::' identifier
| module_name  '::' call_function
| call_function
call_functionidentifier '(' [list_argument] ')'
list_argumentexpression | list_argument ',' expression
expressionexpr_logiq_relat
expr_logiq_relat :expr_logiq_relat || expr_logiq_relat
| expr_logiq_relat && expr_logiq_relat
| '!' terme_logiq_relat
| terme_logiq_relat
terme_logiq_relat :expr_match
| expr_match op_relat expr_match
op_relat :'<' | '>' | '<=' | '>=' | '==' | '!='
expr_match :expr_matc op_arith terme_match
| terme_match
op_arith:'+' | '-' | '*' | '/' | '^'
terme_match:terme_match_primitive
| '{' list_term_match '}'
 
list_term_match:terme_match_primitive
|   list_term_match ','  terme_match_primitive
terme_match_primitive:qualified_name | Number | quoted_string | op_unaire Number | '(' expr_logiq_relat ')' | op_unaire '(' expr_logiq_relat ')' | boolean_value | null
op_unaire'+' | '-'
block'{' list_statement '}'
if_statementif '(' condition ')' block [else_statement]
conditionexpression
else_statementelse '{' list_statement '}'
assignment[type] identifier '=' expression
switch_statement :switch '(' expression ')' '{' list_case default_switch '}'
list_caseliste_case case | case
casecase (qualified_name|quoted_string|number | true | false | null)':' [block]
default_switchdefault ':' block
return_statement :return [expression] ';'
continue_statement:continue ';'
while_statement :while '(' condition')' block
foreach_statement:foreach '(' primitive_type identifier in qualified_name ')' block

Please note that if you use an existing variable in a foreach loop, i.e.:

... symbol myVariable....; foreach (myVariable in ...) {}

This will generate an error message explaining that the variable is not defined. If this is the case, please make sure that you define the variable in the foreach statement:

statement:foreach (symbol myVariable in ...) {}
break_statement :break ';'

Miscellaneous

Modules

Only one module per file:

module a.b;use c.d; 

The "." is obligatory. For example:

module a.b;

To retrieve a function after a module:

c.d::f()

Expression: allowed characters

<||"
>&&'
<===(
>=
)

if_statement

if (condition) {
    list_statement
} [else_statement]

else_statement : else '{'
  list_statement '}'

condition : expression - example:

boolean flagCheck = true;
if (flagCheck == true)

{ print("The flag is set to true."); }
else

{ print("The flag is set to false."); }

affectation_statement

qualified_name = expression ';'

example:

bool flagCheck = true;
a = f(flagCheck, 'string value');

switch_statement

switch (expression) {

case Value1 :
 instructions block
case Value2 :
 instructions block
case value... :
 instructions block
default:
 instructions block
}

value : number | stringliteral | qualified_name - example:

int caseSwitch = 1;
switch (caseSwitch)
{
    case 1:
        print("Case 1");
        break;
    case 2:
        print("Case 2");
        break;
    default:
        print("Default case");
        break;
}

return_statement

return [expression];

example:

return f(a, b);

continue_statement

continue;

break_statement

break;

while_statement

while (condition) {
   instructions block
}

Example:

    int n = 1;
        while (n < 6)
        {
            print("Current value of n is smaller than 6");
            n= n+1;
        }

foreach_statement

foreach (type expression in list) {
   instructions block
}

example:

list(string) types = GROUP_SqlObject + HIB_ENTITY + JPA_ENTITY ;
foreach(string sqlObjectType in types)
{
	log(DEBUG, ">>> type is  "+sqlObjectType ;
}