// ------------------------------------------------------------------------------
int newMixinValuesCount = existingMixinValues.length - 1;
Value[] newMixinValues = new Value[newMixinValuesCount];
List<Name> newMixinNames = new ArrayList<Name>(newMixinValuesCount);
Name primaryTypeName = getPrimaryNodeType().getInternalName();
int j = 0;
for (int i = 0; i < existingMixinValues.length; i++) {
if (!existingMixinValues[i].getString().equals(mixinName)) {
if (j < newMixinValuesCount) {
newMixinValues[j++] = existingMixinValues[i];
newMixinNames.add(cache.nameFactory.create(existingMixinValues[i].getString()));
} else {
throw new NoSuchNodeTypeException(JcrI18n.invalidMixinTypeForNode.text(mixinName, getPath()));
}
}
}
// ------------------------------------------------------------------------------
// Check that any remaining properties that use the mixin type to be removed
// match the residual definition for the node.
// ------------------------------------------------------------------------------
for (PropertyIterator iter = getProperties(); iter.hasNext();) {
Property property = iter.nextProperty();
if (mixinName.equals(property.getDefinition().getDeclaringNodeType().getName())) {
JcrPropertyDefinition match;
// Only the residual definition would work - if there were any other definition for this name,
// the mixin type would not have been added due to the conflict
if (property.getDefinition().isMultiple()) {
match = cache.nodeTypes().findPropertyDefinition(primaryTypeName,
newMixinNames,
JcrNodeType.RESIDUAL_NAME,
property.getValues(),
true);
} else {
match = cache.nodeTypes().findPropertyDefinition(primaryTypeName,
newMixinNames,
JcrNodeType.RESIDUAL_NAME,
property.getValue(),
true,
true);
}
if (match == null) {
throw new ConstraintViolationException(JcrI18n.noDefinition.text("property",
property.getName(),
getPath(),
primaryTypeName,
newMixinNames));
}
}
}
// ------------------------------------------------------------------------------
// Check that any remaining child nodes that use the mixin type to be removed
// match the residual definition for the node.
// ------------------------------------------------------------------------------
for (NodeIterator iter = getNodes(); iter.hasNext();) {
AbstractJcrNode node = (AbstractJcrNode)iter.nextNode();
Name childNodeName = cache.nameFactory.create(node.getName());
int snsCount = node.nodeInfo().getChildrenCount(childNodeName);
if (mixinName.equals(node.getDefinition().getDeclaringNodeType().getName())) {
// Only the residual definition would work - if there were any other definition for this name,
// the mixin type would not have been added due to the conflict
JcrNodeDefinition match = cache.nodeTypes().findChildNodeDefinition(primaryTypeName,