private static void validatePropertyMap(AbstractPropertyMap propertyMap, AbstractPropertyMap currentPropertyMap, PropertyDefinitionMap propertyDefinitionMap, List<String> errorMessages) { // if the entire map is read-only then the new map must match the current map if the current map is non-empty if (propertyDefinitionMap.isReadOnly() && null != currentPropertyMap && !currentPropertyMap.getMap().isEmpty()) { if (!propertyMap.getMap().equals(currentPropertyMap.getMap())) { errorMessages.add("ReadOnly property '" + propertyDefinitionMap.getName() + "' has a value " + propertyMap.getMap() + " different than the current value " + currentPropertyMap.getMap() + "]. It is not allowed to change."); return; } } Map<String, PropertyDefinition> childPropertyDefinitions = propertyDefinitionMap.getMap(); for (PropertyDefinition childPropertyDefinition : childPropertyDefinitions.values()) { validateProperty(childPropertyDefinition, propertyMap, currentPropertyMap, errorMessages); } }
private static void adaptPropertyMap(AbstractPropertyMap source, AbstractPropertyMap target, PropertyDefinitionMap definition, Object parent, boolean adaptReadonlyProperties) { if ((adaptReadonlyProperties || !definition.isReadOnly()) && target == null) { target = new PropertyMap(definition.getName()); add(parent, (PropertyMap) target); } for (Map.Entry<String, PropertyDefinition> e : definition.getPropertyDefinitions().entrySet()) { String name = e.getKey(); PropertyDefinition def = e.getValue(); Property sourceChild = source.get(name); // only bother if we have something to adapt from if (sourceChild != null) { Property targetChild = target.get(name); adaptProperty(sourceChild, targetChild, def, target, adaptReadonlyProperties); } } }