public PackableDoc preset() throws UnifyException { for (FieldConfig fc : config.getFieldConfigs()) { if (fc.isArray()) { Class<?> type = fc.getType().getComponentType(); int len = fc.getRepeat(); Object arr = Array.newInstance(type, len); if (fc.isComplex()) { for (int i = 0; i < len; i++) { Array.set(arr, i, new PackableDoc(fc.getPackableDocConfig(), auditable).preset()); } } values.put(fc.getName(), arr); } else if (fc.isComplex()) { values.put(fc.getName(), new PackableDoc(fc.getPackableDocConfig(), auditable).preset()); } } return this; }
public void writeFieldValue(String name, Object value, Formatter<?> formatter) throws UnifyException { FieldConfig fc = config.getFieldConfig(name); if (fc.isComplex()) { throw new UnifyException(UnifyCoreErrorConstants.DOCUMENT_FIELD_COMPLEX_DIRECT_WRITE, name); } values.put(name, DataUtils.convert(fc.getType(), value, formatter)); changed = true; }
private void writeFieldObject(FieldMapping fMapping, PackableDoc pd, Object value) throws UnifyException { FieldConfig fc = pd.config.getFieldConfig(fMapping.getDocFieldName()); if (value != null) { if (fc.isComplex()) { PackableDocConfig fpdConfig = fc.getPackableDocConfig(); if (fc.isArray()) { Object[] beans = DataUtils.convert(Object[].class, value, null); PackableDoc[] fpd = new PackableDoc[beans.length]; for (int i = 0; i < beans.length; i++) { if (beans[i] != null) { fpd[i] = new PackableDoc(fpdConfig, auditable); fpd[i].readFrom(fMapping.getPackableDocRWConfig(), beans[i]); } } pd.values.put(fc.getName(), fpd); } else { PackableDoc fpd = new PackableDoc(fpdConfig, auditable); fpd.readFrom(fMapping.getPackableDocRWConfig(), value); pd.values.put(fc.getName(), fpd); } } else { pd.values.put(fc.getName(), DataUtils.convert(fc.getType(), value, null)); } } else { pd.values.put(fc.getName(), null); } } }
public Class<?> getFieldType(String name) throws UnifyException { return config.getFieldConfig(name).getType(); }