/** * Builds the argument invocation string for calling a constructor * * @param classVariables The collection of member variables as XMLElements * @param constructorArguments The set of names for constructor arguments * @param allocatedMemberVariables The set of member variables already allocated * @param element The specific 'new' xml element */ private static String buildArguments( Vector classVariables, Set constructorArguments, Set allocatedMemberVariables, IXMLElement element) throws IOException { XMLUtil.checkExpectedNode("new", element); boolean comma = false; String arguments = ""; for (Enumeration e = element.enumerateChildren(); e.hasMoreElements(); ) { IXMLElement argument = (IXMLElement) e.nextElement(); String argType = ModelAccessor.getValueType(argument); String value = ModelAccessor.getValue(argument); /* Exclude cases where we do nothing to the value */ if (!primitives.contains(argType) && !value.equals("true") && !value.equals("false")) { // CASE 0: Translate 'this' if (value.equalsIgnoreCase("this")) { value = "m_id"; } // CASE 1: It is a singleton member variable which must be mapped to the singleton else if (allocatedMemberVariables.contains(value)) { String singletonType = getVariableType(classVariables, value); if (primitives.contains(singletonType)) { value = "(" + singletonType + ") singleton(" + value + ")"; } else value = "singleton(" + value + ")"; } // CASE 2: It is a constructor argument else if (constructorArguments.contains(value)) { // Do nothing, just use the string as is. } // CASE 3: Test for error - using a member before initializing it else if (!allocatedMemberVariables.contains(value) && isMember(classVariables, value)) { value = "!ERROR: Cannot use " + value + " without prior initialization."; } // Otherwise it is a string or enumerataion else if (argType.equals("string") || // It is an enumeartion of some kind ModelAccessor.isEnumeration(argType) || argType.equals("symbol")) { value = "LabelStr(\"" + XMLUtil.escapeQuotes(value) + "\")"; } // If we fall through to here, there is an error. else value = "!ERROR:BAD ASSIGNMENT"; } // CASE 3: It is a true or false value if (comma) arguments = arguments + ", "; arguments = arguments + value; comma = true; } return arguments; }