It seems like all people want me to do these days is modify enums from DXL and everytime I find a new problem. This time, I am trying to take a text attribute in one module (cp Operating Environment) and copy it to a multi valued enumerated attribute in another module (Operating Environment). I have an existing trigger that makes sure the text attribute is in the proper format - each Operating Environment value is seperated by a new line. The trigger also checks the existing enumeration to see if a value exists, if it does not exist, it appends "cp " to beginning of each value to mark it as a new value. I have a seperate script that checks the value of the text attribute and modifies the enum accordingly - removes a "cp " prefix and adds the value to the enum. The error I am currently getting says "You have specified a duplicate type name". This error message is returned from the modify command. I am taking this to mean that I can not edit the type without changing the name but I have changed the enum values and used the same name without getting this error, any thoughts? void rebuildEnum(AttrDef aDef, Object cObj){ Module oldCur = current Current = COTS // contains type to be edited string aType = "Host Operating Environment Type" //typeName to edit string aName = aDef.name AttrType at = find(COTS, aType) // get the type if (null at){ errorBox("AttrType " aType " not found") halt() } // cpVal is a text field containing values to be assigned to the enum in the COTS module // an existing trigger ensures the format of this attribute is correct in the cpCOTS module string cpVal = cObj.aName int numVals = 1, i // determine the number of values for (i = 0; i < length(cpVal); i++){ if (cpVal[i] == '\n'){ numVals++ } } string cpVals_parsed[numVals] = {} int j, lastBreak = 0, idx = 0 // parse values into an array for (j = 0; j < length(cpVal); j++){ if (cpVal[j] == '\n'){ cpVals_parsed[idx++] = cpVal[lastBreak:i-1] lastBreak = i + 1 } } cpVals_parsed[idx] = cpVal[lastBreak:] // skiplist is used to alphabetize and avoid duplicates Skip listVals = createString() // KEY: string - OE name; DATA: int - mapping to previous type int k string temp, errMsg = null for (k = 0; k < numVals; k++){ temp = cpVals_parsed[k] // remove spaces from the end of entries while (temp[length(temp)-1] == ' '){ temp = temp[0:length(temp)-2] } // if it is a new value, add it to the skip with a mapping of -1 if (temp[0:2] == "cp "){ put(listVals, temp[3:], -1) } } // add the existing enum values and their current position to the skip int h for (h = 0; h < at.size; h++){ put(listVals, at.strings[h], h) } Array aModify = create(at.size, 4) int map, index = 0 // build modification array for map in listVals do { put(aModify, (string key(listVals)), index, 0) // at.strings put(aModify, index, index, 1) // at.values put(aModify, -1, index, 2) // colors - dont care about put(aModify, map, index++, 3) // mapping } // modify type at = modify(at, aType, aModify, errMsg) // this line returns a non null errMsg // clean up delete(aModify) delete(listVals) current = oldCur if (!null errMsg){ errorBox(errMsg "\nThis error caused by a non-null errMsg.") halt() } } SystemAdmin - Fri Aug 26 14:34:36 EDT 2011 |
Re: More enum modification ... Current = COTS // contains type to be edited ...
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: More enum modification Mathias Mamsch - Sun Aug 28 15:27:30 EDT 2011 ... Current = COTS // contains type to be edited ...
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
While this 'current module' stuff seems to be my Don Quixote quest, I do forget to add that when in doubt one should add ... print "Current module before modify '" name(current Module) "'\n" which pretty much clears up the doubt.
And Autodeclare is my Mobi Deck, disallowed content detected. So this thread just have everything I need. |