use of com.tvd12.dahlia.core.setting.FieldArraySetting in project dahlia by youngmonkeys.
the class LocalCollectionSettingReader method readFieldArraySetting.
protected FieldSetting readFieldArraySetting(JSONObject setting) {
FieldArraySetting field = new FieldArraySetting();
if (setting.has(SettingFields.MAX_SIZE))
field.setMaxSize(setting.getInt(SettingFields.MAX_SIZE));
if (setting.has(SettingFields.ITEM)) {
JSONObject itemSetting = setting.getJSONObject(SettingFields.ITEM);
DataType itemType = null;
if (itemSetting.has(SettingFields.TYPE))
itemType = DataType.valueOfName(itemSetting.getString(SettingFields.TYPE));
else
throw new IllegalArgumentException("item 'type' is required");
FieldSetting item = readFieldSetting(itemType, itemSetting);
field.setItem(item);
} else {
throw new IllegalArgumentException("'item' field is required");
}
return field;
}
use of com.tvd12.dahlia.core.setting.FieldArraySetting in project dahlia by youngmonkeys.
the class SettingObjectToArrayField method newSetting.
@Override
protected FieldArraySetting newSetting(SettingObjectToFields mappers, EzyObject object) {
FieldArraySetting setting = new FieldArraySetting();
setting.setMaxSize(object.get(SettingFields.MAX_SIZE, int.class));
EzyObject itemSetting = object.get(SettingFields.ITEM, EzyObject.class);
FieldSetting item = mappers.toSetting(itemSetting);
setting.setItem(item);
return setting;
}
use of com.tvd12.dahlia.core.setting.FieldArraySetting in project dahlia by youngmonkeys.
the class FieldArrayReader method readValue.
@Override
protected EzyArray readValue(FieldReaders readers, FileProxy file, FieldSetting setting) throws IOException {
FieldArraySetting fs = (FieldArraySetting) setting;
FieldSetting itemSetting = fs.getItem();
int size = file.readShort();
EzyArray array = EzyEntityFactory.newArray();
for (int i = 0; i < size; ++i) {
Object item = readers.readValue(file, itemSetting);
array.add(item);
}
return array;
}
use of com.tvd12.dahlia.core.setting.FieldArraySetting in project dahlia by youngmonkeys.
the class FieldArrayWriter method writeValue.
@Override
protected void writeValue(FieldWriters writers, FileProxy file, FieldSetting setting, EzyArray value) throws IOException {
int size = value.size();
file.writeShort((short) size);
FieldArraySetting fs = (FieldArraySetting) setting;
FieldSetting itemSetting = fs.getItem();
for (int i = 0; i < size; ++i) writers.write(file, itemSetting, value.get(i));
}
Aggregations