Created
December 9, 2012 22:23
-
-
Save xcriptus/4247279 to your computer and use it in GitHub Desktop.
StarUML - Translator - Recursive Traversal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// These functions allow to get a list of elements according to the | |
// REPEAT feature of staruml templates | |
// This piece of code comes from the StarUML translators | |
//////////////////////////////////////////////// | |
// getAllRecursiveElements : | |
// | |
function getAllRecursiveElements(isDeep, rootElem, filterType) { | |
// 1.get elem's type | |
var rootElemPathname = rootElem.pathname; | |
// 2.get all elements whose type is filterType in MetaClass | |
var metaClass = app.MetaModel.FindMetaClass(filterType); | |
var count = metaClass.getInclusiveInstanceCount(); | |
var elemArray = new Array(); | |
var rc = rootElemPathname.split("::").length; | |
for (var i = 0; i < count; i++) { | |
var elem = metaClass.getInclusiveInstanceAt(i); | |
// 3.0 in case of filterType | |
if (elem.IsKindOf(filterType)) { | |
if (elem.pathname.indexOf(rootElemPathname + "::") == 0) { | |
// 3.1 in case of recursive option | |
if (isDeep) { | |
// 3.insertion sort by name | |
elemArray = insertElementArray(elem, elemArray); | |
} | |
// 3.2 in case of not recursive option | |
else { | |
// 3.2.1 if no. of separator of pathname of selected element == no. of separator of pathname of rootElem + 1 | |
if (elem.pathname.split("::").length == (rc+1)) { | |
elemArray = insertElementArray(elem, elemArray); | |
} | |
// 3.2.2 unless | |
else { | |
// do nothing | |
} | |
} | |
} | |
} | |
} | |
return elemArray; | |
} | |
///////////////////////////////////////////////// | |
// IsItemTrue : | |
// | |
function IsItemTrue(wholeConds) { | |
var cond = true; | |
try | |
{ | |
if ((wholeConds != "") && (wholeConds != null)) { | |
eval("var cond = "+ wholeConds); | |
return cond; | |
} else { | |
return true; | |
} | |
} | |
catch (ex) | |
{ | |
log(GetErrorPos()+": Error exists in "+wholeConds+" condition argument."); | |
throw ex; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment