{
// System.out.println("setValue(" + newValue + ") subjectType [" + subjectType.getName() + "]");
if (newValue instanceof String) {
// This can be the case in an editable droplist, in which case it can only be mapped to a string or TextData
if (TextData.class.isAssignableFrom(subjectType)) {
TextData newObject;
try {
// Map the string back to the underlying type for proper mapping
newObject = (TextData) subjectType.newInstance();
newObject.setValue((String)newValue);
subject.setValue(newObject);
} catch (Exception e) {
throw new UsageException("Could not instantiate an instance of " + subjectType.getName(), e);
}
}
else if (String.class.equals(subjectType)) {
subject.setValue(newValue.toString());
}
}
else if (newValue instanceof ListElement) {
ListElement element = (ListElement) newValue;
if (Integer.class.equals(subjectType) || Integer.TYPE.equals(subjectType)) {
subject.setValue(new Integer(element.getIntegerValue()));
}
else if (IntegerData.class.equals(subjectType)) {
subject.setValue(new IntegerData(element.getIntegerValue()));
}
else if (IntegerNullable.class.equals(subjectType)) {
subject.setValue(new IntegerNullable(element.getIntegerValue()));
}
else if (IntegerData.class.isAssignableFrom(subjectType)) {
try {
IntegerData anIntData = (IntegerData)subjectType.newInstance();
anIntData.setValue(element.getIntegerValue());
subject.setValue(anIntData);
}
catch (Exception e) {
// No default constructor
_log.debug("Could not instantiate class " + subjectType.getName(), e);
}
}
else if (TextData.class.equals(subjectType)) {
// TF:27/8/07:We need to clone the return value, otherwise we'll be returning the actual textdata mapped to the listelement
// and any changes on this list element will erroneously affect the underlying list
subject.setValue(CloneHelper.clone(element.getTextValue(), false));
}
else if (TextNullable.class.equals(subjectType)) {
subject.setValue(new TextNullable(element.getTextValue()));
}
else if (TextData.class.isAssignableFrom(subjectType)) {
try {
TextData aTextData = (TextData)subjectType.newInstance();
aTextData.setValue(element.getTextValue());
subject.setValue(aTextData);
}
catch (Exception e) {
// No default constructor
_log.debug("Could not instantiate class " + subjectType.getName(), e);