for (JcrNodeDefinition nodeDefinition : mixinType.allChildNodeDefinitions()) {
mixinChildNodeNames.add(nodeDefinition.getInternalName());
}
CachedNode node = node();
NodeCache cache = cache();
NodeTypes nodeTypes = session.nodeTypes();
// Need to figure out if the child node requires an SNS definition
ChildReferences refs = node.getChildReferences(cache());
// Create a sibling counter that reduces the count by 1, since we're always dealing with existing children
// but the 'findBestDefinitionForChild' logic is looking to *add* a child ...
SiblingCounter siblingCounter = SiblingCounter.alter(SiblingCounter.create(refs), -1);
for (Name nodeName : mixinChildNodeNames) {
int snsCount = siblingCounter.countSiblingsNamed(nodeName);
if (snsCount == 0) continue;
Iterator<ChildReference> iter = refs.iterator(nodeName);
while (iter.hasNext()) {
ChildReference ref = iter.next();
CachedNode child = cache.getNode(ref);
Name childPrimaryType = child.getPrimaryType(cache);
boolean skipProtected = true;
NodeDefinitionSet childDefns = nodeTypes.findChildNodeDefinitions(mixinType.getInternalName(), null);
JcrNodeDefinition childDefn = childDefns.findBestDefinitionForChild(nodeName, childPrimaryType,
skipProtected, siblingCounter);