protected Object getValueField(T state, Field field) throws PropertyException { Type type = field.getType(); String name = field.getName().getPrefixedName(); name = internalName(name); if (type.isSimpleType()) { // scalar return state.getSingle(name); } else if (type.isComplexType()) { // complex property T childState = getChild(state, name, type); if (childState == null) { return null; } return getValueComplex(childState, (ComplexType) type); } else { // array or list Type fieldType = ((ListType) type).getFieldType(); if (fieldType.isSimpleType()) { // array return state.getArray(name); } else { // complex list List<T> childStates = getChildAsList(state, name); List<Object> list = new ArrayList<>(childStates.size()); for (T childState : childStates) { Object value = getValueComplex(childState, (ComplexType) fieldType); list.add(value); } return list; } } }
/** Checks for ignored writes. May throw. */ protected boolean checkReadOnlyIgnoredWrite(Property property, T state) throws PropertyException { String name = property.getField().getName().getPrefixedName(); if (!isReadOnly() || isVersionWritableProperty(name)) { // do write return false; } if (!isVersion()) { throw new PropertyException("Cannot write readonly property: " + name); } if (!name.startsWith(DC_PREFIX)) { throw new PropertyException("Cannot set property on a version: " + name); } // ignore if value is unchanged (only for dublincore) // dublincore contains only scalars and arrays Object value = property.getValueForWrite(); Object oldValue; if (property.getType().isSimpleType()) { oldValue = state.getSingle(name); } else { oldValue = state.getArray(name); } if (!ArrayUtils.isEquals(value, oldValue)) { // do write return false; } // ignore attempt to write identical value return true; }
/** Reads state into a complex property. */ protected void readComplexProperty(T state, ComplexProperty complexProperty) throws PropertyException { if (state == null) { complexProperty.init(null); return; } if (complexProperty instanceof BlobProperty) { Blob blob = getValueBlob(state); complexProperty.init((Serializable) blob); return; } for (Property property : complexProperty) { String name = property.getField().getName().getPrefixedName(); name = internalName(name); Type type = property.getType(); if (type.isSimpleType()) { // simple property Object value = state.getSingle(name); if (value instanceof Delta) { value = ((Delta) value).getFullValue(); } property.init((Serializable) value); } else if (type.isComplexType()) { // complex property T childState = getChild(state, name, type); readComplexProperty(childState, (ComplexProperty) property); ((ComplexProperty) property).removePhantomFlag(); } else { ListType listType = (ListType) type; if (listType.getFieldType().isSimpleType()) { // array Object[] array = state.getArray(name); array = typedArray(listType.getFieldType(), array); property.init(array); } else { // complex list Field listField = listType.getField(); List<T> childStates = getChildAsList(state, name); // TODO property.init(null) if null children in DBS List<Object> list = new ArrayList<>(childStates.size()); for (T childState : childStates) { ComplexProperty p = (ComplexProperty) complexProperty.getRoot().createProperty(property, listField, 0); readComplexProperty(childState, p); list.add(p.getValue()); } property.init((Serializable) list); } } } }
protected void readPrefetchField( T state, Field field, String xpathGeneric, String xpath, Set<String> prefixes, Map<String, Serializable> prefetch) { String name = field.getName().getPrefixedName(); Type type = field.getType(); xpathGeneric = xpathGeneric == null ? name : xpathGeneric + '/' + name; xpath = xpath == null ? name : xpath + '/' + name; if (!prefixes.contains(xpathGeneric)) { return; } if (type.isSimpleType()) { // scalar Object value = state.getSingle(name); prefetch.put(xpath, (Serializable) value); } else if (type.isComplexType()) { // complex property T childState = getChild(state, name, type); if (childState != null) { readPrefetch(childState, (ComplexType) type, xpathGeneric, xpath, prefixes, prefetch); } } else { // array or list ListType listType = (ListType) type; if (listType.getFieldType().isSimpleType()) { // array Object[] value = state.getArray(name); prefetch.put(xpath, value); } else { // complex list List<T> childStates = getChildAsList(state, name); Field listField = listType.getField(); xpathGeneric += "/*"; int i = 0; for (T childState : childStates) { readPrefetch( childState, (ComplexType) listField.getType(), xpathGeneric, xpath + '/' + i++, prefixes, prefetch); } } } }
protected BlobInfo getBlobInfo(T state) throws PropertyException { BlobInfo blobInfo = new BlobInfo(); blobInfo.key = (String) state.getSingle(BLOB_DATA); blobInfo.filename = (String) state.getSingle(BLOB_NAME); blobInfo.mimeType = (String) state.getSingle(BLOB_MIME_TYPE); blobInfo.encoding = (String) state.getSingle(BLOB_ENCODING); blobInfo.digest = (String) state.getSingle(BLOB_DIGEST); blobInfo.length = (Long) state.getSingle(BLOB_LENGTH); return blobInfo; }