if (data == null || data.isEmpty()) {
return null;
}
String className = (String) data.get("@className");
if (className == null) {
throw new FormEncodingException(
"@className attribute cannot be null");
}
Object obj = null;
try {
obj = Class.forName(className).newInstance();
if (obj instanceof Mappable) {
Mappable item = (Mappable) obj;
item.setDataMap(data);
} else {
throw new FormEncodingException("Type "
+ obj.getClass().getName()
+ " cannot be casted to FormItemRepresentation");
}
} catch (InstantiationException e) {
throw new FormEncodingException("Couldn't instantiate class "
+ className, e);
} catch (IllegalAccessException e) {
throw new FormEncodingException(
"Couldn't access constructor of class " + className, e);
} catch (ClassNotFoundException e) {
throw new FormEncodingException("Couldn't find class " + className,
e);
}
return obj;
}