}
if (this.buildInNodeTypesNames.contains(recipientDefinition.getName()))
{
throw new RepositoryException(recipientDefinition.getName() + ": can't reregister built-in node type.");
}
final PlainChangesLog changesLog = new PlainChangesLogImpl();
final VolatileNodeTypeDataManager volatileNodeTypeDataManager = new VolatileNodeTypeDataManager(this);
volatileNodeTypeDataManager.registerVolatileNodeTypes(volatileNodeTypes);
ItemAutocreator itemAutocreator =
new ItemAutocreator(volatileNodeTypeDataManager, valueFactory, dataManager, false);
final Set<String> nodes = this.indexSearcherHolder.getNodesByNodeType(recipientDefinition.getName());
// check add mix:versionable super
if (isNodeType(Constants.MIX_VERSIONABLE, recipientDefinition.getDeclaredSupertypeNames())
&& !isNodeType(Constants.MIX_VERSIONABLE, ancestorDefinition.getDeclaredSupertypeNames()))
{
for (final String uuid : nodes)
{
final ItemData item = this.dataManager.getItemData(uuid);
if (item != null && item.isNode())
{
changesLog.addAll(itemAutocreator.makeMixVesionableChanges((NodeData)item).getAllStates());
}
}
}
else if (!isNodeType(Constants.MIX_VERSIONABLE, recipientDefinition.getDeclaredSupertypeNames())
&& isNodeType(Constants.MIX_VERSIONABLE, ancestorDefinition.getDeclaredSupertypeNames()))
{
if (nodes.size() > 0)
{
final StringBuffer buffer = new StringBuffer();
buffer.append("Fail to change ");
buffer.append(recipientDefinition.getName().getAsString());
buffer.append(" node type from mix:versionable = true to mix:versionable = false");
buffer.append(" because the folowing node exists: ");
if (nodes.size() < 100)
{
for (final String uuid : nodes)
{
final ItemData item = this.dataManager.getItemData(uuid);
if (item != null && item.isNode())
{
buffer.append(item.getQPath().getAsString());
buffer.append(" ");
}
}
}
throw new ConstraintViolationException(buffer.toString());
}
}
final List<NodeData> affectedNodes = new ArrayList<NodeData>();
for (final String uuid : nodes)
{
final ItemData nodeData = this.dataManager.getItemData(uuid);
if (nodeData != null)
{
if (nodeData.isNode())
{
affectedNodes.add((NodeData)nodeData);
}
}
}
// child nodes
final NodeDefinitionComparator nodeDefinitionComparator =
new NodeDefinitionComparator(volatileNodeTypeDataManager, this.dataManager, itemAutocreator, affectedNodes);
changesLog.addAll(nodeDefinitionComparator.compare(recipientDefinition,
getAllChildNodeDefinitions(ancestorDefinition.getName()),
volatileNodeTypeDataManager.getAllChildNodeDefinitions(recipientDefinition.getName())).getAllStates());
// properties defs
final PropertyDefinitionComparator propertyDefinitionComparator =
new PropertyDefinitionComparator(volatileNodeTypeDataManager, this.dataManager, itemAutocreator,
affectedNodes, this.locationFactory);
changesLog.addAll(propertyDefinitionComparator.compare(recipientDefinition,
getAllPropertyDefinitions(ancestorDefinition.getName()),
volatileNodeTypeDataManager.getAllPropertyDefinitions(recipientDefinition.getName()))
.getAllStates());
// notify listeners about changes
if (!Arrays.deepEquals(recipientDefinition.getDeclaredSupertypeNames(), ancestorDefinition
.getDeclaredSupertypeNames()))
{
for (final String uuid : nodes)
{
ItemData item = this.dataManager.getItemData(uuid);
if (item != null && item.isNode())
{
if (!(item instanceof TransientNodeData))
{
item =
new TransientNodeData(item.getQPath(), item.getIdentifier(), item.getPersistedVersion(),
((NodeData)item).getPrimaryTypeName(), ((NodeData)item).getMixinTypeNames(), ((NodeData)item)
.getOrderNumber(), ((NodeData)item).getParentIdentifier(), ((NodeData)item).getACL());
}
changesLog.add(new ItemState(item, ItemState.MIXIN_CHANGED, false, null));
}
}
}
// mixin changed