private void setAttributeValues(BufferedWriter out,
TreeMap<String, DmcUncheckedObject> objects, PrintfFormat pf)
throws IOException, ResultException {
String attrName = null;
String objName = null;
DmcUncheckedObject attrDef = null;
String typeName = null;
DmcUncheckedObject typeDef = null;
boolean multiValued = false;
boolean isReference = false;
boolean isEnumType = false;
Iterator<DmcUncheckedObject> it = objects.values().iterator();
while (it.hasNext()) {
DmcUncheckedObject obj = it.next();
objName = obj.getSV("name");
// // trickiness here to handle the fact that the actual rule
// definition object
// // has to be called RuleDEF since Rule is the name of the class
// definition that
// // is created to represent the Rule instance.
// if (obj.getConstructionClass().equals("RuleDefinition")){
// objName = objName + "DEF";
// }
Iterator<String> attributeNames = obj.getAttributeNames();
while (attributeNames.hasNext()) {
NamedStringArray attr = obj.get(attributeNames.next());
attrName = attr.getName();
if (attrName == null) {
DebugInfo.debug("Attr name null");
continue;
}
attrDef = attributeDefs.get(attrName);
multiValued = false;
isReference = false;
isEnumType = false;
if (attrDef == null) {
ResultException ex = new ResultException();
ex.addError("Unknown attribute: " + attrName);
ex.result.lastResult().fileName("metaSchema.dms");
ex.result.lastResult().lineNumber(obj.lineNumber);
throw (ex);
}
// MULTIVALUED 1
if (attrDef.getSV("valueType") != null)
multiValued = true;
typeName = attrDef.getSV("type");
typeDef = typeDefs.get(typeName);
if (typeDef == null) {
// If this is null, we need to look for an internally
// generated Reference type
typeDef = typeDefs.get(typeName + "REF");
isReference = true;
if (typeDef.getSV("isEnumType") != null)
isEnumType = true;
}
StringBuffer attrNameCapped = new StringBuffer();
attrNameCapped.append(attrName);
attrNameCapped.setCharAt(0,
Character.toUpperCase(attrNameCapped.charAt(0)));
if (attrName.equals("type")) {
// The type attribute has to be handled slightly differently
// than most attributes
// to adjust for the fact that we create those internal
// Reference types to handle
// references to definitions.
isReference = false;
isEnumType = false;
typeName = obj.getSV("type");
typeDef = typeDefs.get(typeName);
if (typeDef == null) {
// If this is null, we need to look for an internally
// generated Reference type
typeDef = typeDefs.get(typeName + "REF");
isReference = true;
if (typeDef.getSV("isEnumType") != null)
isEnumType = true;
}
out.write(" _" + pf.sprintf(objName));
out.write(".setType(");
if (isReference) {
out.write("_" + obj.getSV(attrName) + "REF);\n");
} else {
out.write("_" + obj.getSV(attrName) + ");\n");
}
} else {
if (multiValued) {
for (String attrVal : attr) {
out.write(" _" + pf.sprintf(objName));
out.write(".add" + attrNameCapped + "(");
if (isReference) {
if (isEnumType)
out.write(typeName + "." + attrVal + ");\n");
else
out.write("_" + attrVal + ");\n");
} else {
out.write("\"" + attrVal + "\");\n");
}
}
} else {
out.write(" _" + pf.sprintf(objName));
out.write(".set" + attrNameCapped + "(");
if (isReference) {
if (isEnumType)
out.write(typeName + "." + obj.getSV(attrName)
+ ");\n");
else
out.write("_" + obj.getSV(attrName) + ");\n");
} else {
String value = obj.getSV(attrName);
if (attrName.equals("name")) {
String val = obj.getSV(attrName);
if (val.endsWith("EnumREF")) {
// DebugInfo.debug("Enum name: " + val);
value = val.replaceFirst("REF", "");
// DebugInfo.debug("value = " + value);
}