static str 60 addValidateCode(FormName formname, TableId refTableId, FieldId
refFieldId)
{
#AOT
TreeNode treeNode;
TreeNode methodsTreeNode;
str oldsource;
str newsource;
str superString = "super()";
str busRuleString;
str newMethodName;
str newMethodCode;
;
treeNode = TreeNode::findNode(#FormsPath + "\\" + formName);
treeNode = treeNode.AOTfindChild("Data Sources");
treeNode = treeNode.AOTfindChild(tableId2Name(refTableId));
if(refFieldId)
{
newMethodName = "validate";
newMethodCode = "public boolean validate()\n{\n boolean ret;\n
;\n ret = super() && PABusInessRules::CheckRules(element, this," +
strfmt(' %1',refFieldId) + ");\n\n return ret;\n}\n";
//bus rule string is different if applied to a fieldId
busRuleString = "super() && PABusInessRules::CheckRules(element,
this," + strfmt(' %1)',refFieldId);
treeNode = treeNode.AOTfindChild("fields");
treeNode = treeNode.AOTfindChild(fieldId2Name(refTableId,RefFieldId));
}
else
{
newMethodName = "validateWrite";
newMethodCode = "public boolean validateWrite()\n{\n boolean
ret;\n ;\n ret = super() && PABusInessRules::CheckRules(element,
this);\n\n return ret;\n}\n";
busRuleString = "super() && PABusinessRules::CheckRules(element,
this)";
}
methodsTreeNode = treeNode.AOTfindChild("Methods");
treeNode = methodsTreeNode.AOTfindChild(newMethodName);
if(!treeNode)
{
methodsTreeNode.AOTadd(newMethodName);
methodsTreeNode.AOTsave();
treeNode = methodsTreeNode.AOTfindChild(newMethodName);
newSource = newMethodCode;
treeNode.AOTsetSource(newsource,false);
}
else
{
oldsource = treeNode.AOTgetSource();
// check if rule already applied
if(strscan(oldSource,busRuleString,1,strlen(oldSource)) == 0)
{
newSource = strReplace(oldsource,superString,busRuleString);
//new line to be inserted
treeNode.AOTsetSource(newsource);
}
}
TreeNode = TreeNode::findNode(#FormsPath + "\\" + formName);
treeNode.AOTcompile();
treeNode.AOTsave();
return busRuleString;
}
No comments:
Post a Comment