}
Object populateFields(FactData fact,
Object factObject) {
for (int i = 0; i < fact.getFieldData().size(); i++) {
FieldData field = (FieldData) fact.getFieldData().get(i);
Object val = null;
if (field.getValue() != null && !field.getValue().equals("")) {
if (field.getValue().startsWith("=")) {
// eval the val into existence
val = eval(field.getValue().substring(1),
populatedData);
} else if (field.getNature() == FieldData.TYPE_ENUM) {
// The string representation of a java enum value is a
// format like CheeseType.CHEDDAR
String valueOfEnum = field.getValue();
String fullName = null;
if (field.getValue().indexOf(".") != -1) {
String classNameOfEnum = field.getValue().substring(0,
field.getValue().lastIndexOf("."));
valueOfEnum = field.getValue().substring(
field.getValue().lastIndexOf(".") + 1);
try {
//This is a Java enum type if the type can be resolved by ClassTypeResolver
//Revisit: Better way to determine java enum type or Guvnor enum type.
fullName = resolver
.getFullTypeName(classNameOfEnum);
if (fullName != null && !"".equals(fullName)) {
valueOfEnum = fullName + "." + valueOfEnum;
}
val = eval(valueOfEnum);
} catch (ClassNotFoundException e) {
// This is a Guvnor enum type
fullName = classNameOfEnum;
if (fullName != null && !"".equals(fullName)) {
valueOfEnum = fullName + "." + valueOfEnum;
}
val = valueOfEnum;
}
} else {
val = valueOfEnum;
}
} else {
val = field.getValue();
}
Map<String, Object> vars = new HashMap<String, Object>();
vars.putAll(populatedData);
vars.put("__val__",
val);
vars.put("__fact__",
factObject);
eval("__fact__." + field.getName() + " = __val__",
vars);
}
}
return factObject;
}