children.clear();
Map<Name, Integer> childNames = new HashMap<Name, Integer>();
Map<Name, Property> properties = federatedNode.getPropertiesByName();
properties.clear();
UUID uuid = null;
UuidFactory uuidFactory = null;
final boolean removeDuplicateProperties = isRemoveDuplicateProperties();
// Iterate over the set of contributions (in order) ...
for (Contribution contribution : contributions) {
// If the contribution is a placeholder contribution, then the children should be merged into other children ...
if (contribution.isPlaceholder()) {
// Iterate over the children and add only if there is not already one ...
Iterator<Segment> childIterator = contribution.getChildren();
while (childIterator.hasNext()) {
Segment child = childIterator.next();
if (!childNames.containsKey(child.getName())) {
childNames.put(child.getName(), 1);
children.add(pathFactory.createSegment(child.getName()));
}
}
} else {
// Copy the children ...
Iterator<Segment> childIterator = contribution.getChildren();
while (childIterator.hasNext()) {
Segment child = childIterator.next();
int index = Path.NO_INDEX;
Integer previous = childNames.put(child.getName(), 1);
if (previous != null) {
int previousValue = previous.intValue();
// Correct the index in the child name map ...
childNames.put(child.getName(), ++previousValue);
index = previousValue;
}
children.add(pathFactory.createSegment(child.getName(), index));
}
// Copy the properties ...
Iterator<Property> propertyIterator = contribution.getProperties();
while (propertyIterator.hasNext()) {
Property property = propertyIterator.next();
// Skip the "uuid" property on all root nodes ...
if (federatedNode.getPath().isRoot() && property.getName().getLocalName().equals("uuid")) continue;
Property existing = properties.put(property.getName(), property);
if (existing != null) {
// There's already an existing property, so we need to merge them ...
Property merged = merge(existing, property, context.getPropertyFactory(), removeDuplicateProperties);
properties.put(property.getName(), merged);
}
if (uuid == null && property.getName().getLocalName().equals("uuid") && property.isSingle()) {
if (uuidFactory == null) uuidFactory = context.getValueFactories().getUuidFactory();
try {
uuid = uuidFactory.create(property.getValues().next());
} catch (IoException e) {
// Ignore conversion exceptions
assert uuid == null;
}
}