public PlainChangesLog setPrimaryType(final NodeData nodeData, final InternalQName nodeTypeName)
throws RepositoryException
{
final PlainChangesLog changesLog = new PlainChangesLogImpl();
final NodeTypeData ancestorDefinition = getNodeType(nodeData.getPrimaryTypeName());
final NodeTypeData recipientDefinition = getNodeType(nodeTypeName);
InternalQName[] ancestorAllNodeTypeNames = null;
if (nodeData.getMixinTypeNames() == null || nodeData.getMixinTypeNames().length == 0)
{
ancestorAllNodeTypeNames = new InternalQName[]{nodeData.getPrimaryTypeName()};
}
else
{
ancestorAllNodeTypeNames = new InternalQName[nodeData.getMixinTypeNames().length + 1];
ancestorAllNodeTypeNames[0] = nodeData.getPrimaryTypeName();
System.arraycopy(nodeData.getMixinTypeNames(), 0, ancestorAllNodeTypeNames, 1,
nodeData.getMixinTypeNames().length);
}
InternalQName[] recipienAllNodeTypeNames = null;
if (nodeData.getMixinTypeNames() == null || nodeData.getMixinTypeNames().length == 0)
{
recipienAllNodeTypeNames = new InternalQName[]{nodeTypeName};
}
else
{
recipienAllNodeTypeNames = new InternalQName[nodeData.getMixinTypeNames().length + 1];
recipienAllNodeTypeNames[0] = nodeTypeName;
System.arraycopy(nodeData.getMixinTypeNames(), 0, recipienAllNodeTypeNames, 1,
nodeData.getMixinTypeNames().length);
}
final boolean recipientsMixVersionable = isNodeType(Constants.MIX_VERSIONABLE, recipienAllNodeTypeNames);
final boolean ancestorIsMixVersionable = isNodeType(Constants.MIX_VERSIONABLE, ancestorAllNodeTypeNames);
ItemAutocreator itemAutocreator = new ItemAutocreator(this, valueFactory, dataManager, false);
if (recipientsMixVersionable && !ancestorIsMixVersionable)
{
changesLog.addAll(itemAutocreator.makeMixVesionableChanges(nodeData).getAllStates());
}
else if (!recipientsMixVersionable && ancestorIsMixVersionable)
{
final StringBuffer buffer = new StringBuffer();
buffer.append("Fail to change node type from ");
buffer.append(ancestorDefinition.getName().getAsString());
buffer.append(" to ");
buffer.append(recipientDefinition.getName().getAsString());
buffer.append(" because change from mix:versionable = true ");
buffer.append(" to mix:versionable = false is not alowed");
throw new ConstraintViolationException(buffer.toString());
}