in src/main/java/org/apache/sling/validation/impl/model/MergedValidationModel.java [45:81]
public MergedValidationModel(ValidationModel baseModel, ValidationModel... modelsToMerge) {
this.baseModel = baseModel;
// merge resource properties and child resources: all the ones from the base + different ones from the model to merge
resourcePropertiesMap = new HashMap<String, ResourceProperty>();
for (ResourceProperty resourceProperty : baseModel.getResourceProperties()) {
resourcePropertiesMap.put(resourceProperty.getName(), resourceProperty);
}
childResourceMap = new HashMap<String, ChildResource>();
for (ChildResource childResource : baseModel.getChildren()) {
childResourceMap.put(childResource.getName(), childResource);
}
StringBuilder sourceStringBuilder = new StringBuilder(baseModel.getSource());
for (ValidationModel modelToMerge : modelsToMerge) {
for (ResourceProperty resourceProperty : modelToMerge.getResourceProperties()) {
// only if name is not already used, the resource property should be considered
if (!resourcePropertiesMap.containsKey(resourceProperty.getName())) {
resourcePropertiesMap.put(resourceProperty.getName(), resourceProperty);
}
}
for (ChildResource childResource : modelToMerge.getChildren()) {
// only if name is not already used, the child resource should be considered
if (!childResourceMap.containsKey(childResource.getName())) {
childResourceMap.put(childResource.getName(), childResource);
}
}
// throw exception if the applicable path is restricted in the modelToMerge in comparison to baseModel
for (String path : modelToMerge.getApplicablePaths()) {
if (isPathRestricted(path, baseModel.getApplicablePaths())) {
String msg = String.format("The path '%s' from one of the models to merge is more specific than any of the base paths (%s)", path, baseModel.getApplicablePaths());
throw new IllegalArgumentException(msg);
}
}
sourceStringBuilder.append(" + ").append(modelToMerge.getSource());
}
source = sourceStringBuilder.toString();
}