private void setup(PackableDocConfig config, boolean auditable) { this.config = config; this.auditable = auditable; changed = false; for (FieldConfig fc : config.getFieldConfigs()) { if (!values.containsKey(fc.getName())) { values.put(fc.getName(), null); } else { if (fc.isComplex()) { Object val = values.get(fc.getName()); if (val != null) { if (fc.isArray()) { PackableDoc[] pd = (PackableDoc[]) val; for (int i = 0; i < pd.length; i++) { if (pd[i] != null) { pd[i].setup(fc.getPackableDocConfig(), auditable); } } } else { PackableDoc pd = (PackableDoc) val; pd.setup(fc.getPackableDocConfig(), auditable); } } } } } if (auditable) { oldValues = new HashMap<String, Object>(values); } }
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; }
subFieldConfigList.add(new FieldConfig(subWfDocField.getName(), subWfDocField.getDataType(), subWfDocField.getRepeat())); .add(new FieldConfig(wfDocField.getName(), wfDocField.getRepeat(), subFieldConfigList)); } else { fieldConfigList.add(new FieldConfig(wfDocField.getName(), dataType, wfDocField.getRepeat()));
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); } } }
private Object readFieldObject(FieldMapping fMapping, PackableDoc pd) throws UnifyException { Object val = pd.values.get(fMapping.getDocFieldName()); if (val != null) { if (fMapping.isComplex()) { FieldConfig fc = pd.config.getFieldConfig(fMapping.getDocFieldName()); if (fc.isArray()) { PackableDoc[] pdArray = (PackableDoc[]) val; Object[] beans = new Object[pdArray.length]; for (int i = 0; i < pdArray.length; i++) { beans[i] = readObject(fMapping.getPackableDocRWConfig(), pdArray[i]); } val = beans; } else { val = readObject(fMapping.getPackableDocRWConfig(), (PackableDoc) val); } } } return val; }
public Class<?> getFieldType(String name) throws UnifyException { return config.getFieldConfig(name).getType(); }
public PackableDocConfig(String name, List<FieldConfig> fieldConfigList) { this.name = name; fieldConfigs = new HashMap<String, FieldConfig>(); for (FieldConfig fieldConfig : fieldConfigList) { fieldConfigs.put(fieldConfig.getName(), fieldConfig); } }
public void writeFieldValue(PackableDocRWConfig rwConfig, String name, Object value) throws UnifyException { FieldConfig fc = config.getFieldConfig(name); if (!fc.isComplex()) { throw new UnifyException(UnifyCoreErrorConstants.DOCUMENT_FIELD_NOT_COMPLEX, name); } FieldMapping fMapping = rwConfig.getFieldMapping(name); if (!fMapping.isComplex()) { throw new UnifyException(UnifyCoreErrorConstants.DOCUMENT_FIELDMAPPING_NOT_COMPLEX, fMapping.getDocFieldName(), fMapping.getBeanFieldName()); } writeFieldObject(fMapping, this, value); }
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; }
public Object readFieldValue(PackableDocRWConfig rwConfig, String name) throws UnifyException { FieldConfig fc = config.getFieldConfig(name); if (!fc.isComplex()) { throw new UnifyException(UnifyCoreErrorConstants.DOCUMENT_FIELD_NOT_COMPLEX, name); } FieldMapping fMapping = rwConfig.getFieldMapping(name); if (!fMapping.isComplex()) { throw new UnifyException(UnifyCoreErrorConstants.DOCUMENT_FIELDMAPPING_NOT_COMPLEX, fMapping.getDocFieldName(), fMapping.getBeanFieldName()); } return readFieldObject(fMapping, this); }