use of org.apache.jackrabbit.spi.commons.nodetype.NodeTypeDefDiff in project jackrabbit by apache.
the class CompactNodeTypeDefTest method testCompactNodeTypeDef.
public void testCompactNodeTypeDef() throws Exception {
// Read in node type def from test file
Reader reader = new InputStreamReader(getClass().getClassLoader().getResourceAsStream(TEST_FILE));
CompactNodeTypeDefReader<QNodeTypeDefinition, NamespaceMapping> cndReader = new CompactNodeTypeDefReader<QNodeTypeDefinition, NamespaceMapping>(reader, TEST_FILE, new QDefinitionBuilderFactory());
List<QNodeTypeDefinition> ntdList1 = cndReader.getNodeTypeDefinitions();
NamespaceMapping nsm = cndReader.getNamespaceMapping();
NamePathResolver resolver = new DefaultNamePathResolver(nsm);
// Put imported node type def back into CND form with CND writer
StringWriter sw = new StringWriter();
CompactNodeTypeDefWriter.write(ntdList1, nsm, resolver, sw);
// Rerun the reader on the product of the writer
cndReader = new CompactNodeTypeDefReader<QNodeTypeDefinition, NamespaceMapping>(new StringReader(sw.toString()), TEST_FILE, new QDefinitionBuilderFactory());
List<QNodeTypeDefinition> ntdList2 = cndReader.getNodeTypeDefinitions();
if (ntdList1.size() == 0 || ntdList1.size() != ntdList2.size()) {
fail("Exported node type definition was not successfully read back in");
} else {
for (int k = 0; k < ntdList1.size(); k++) {
QNodeTypeDefinition ntd1 = ntdList1.get(k);
QNodeTypeDefinition ntd2 = ntdList2.get(k);
NodeTypeDefDiff diff = NodeTypeDefDiff.create(ntd1, ntd2);
if (diff.isModified() && !diff.isTrivial()) {
fail("Exported node type definition was not successfully read back in. " + ntd2.getName() + "differs from original");
}
}
}
}
use of org.apache.jackrabbit.spi.commons.nodetype.NodeTypeDefDiff in project jackrabbit by apache.
the class NodeTypeRegistry method reregisterNodeType.
/**
* Internal implementation of {@link #reregisterNodeType(QNodeTypeDefinition)}.
*
* @param ntd node type definition
* @param external whether this invocation should be considered external
* @return the new effective node type
* @throws NoSuchNodeTypeException if <code>ntd</code> refers to an
* unknown node type
* @throws InvalidNodeTypeDefException if the node type definition
* is invalid
* @throws RepositoryException if another error occurs
*/
private EffectiveNodeType reregisterNodeType(QNodeTypeDefinition ntd, boolean external) throws NoSuchNodeTypeException, InvalidNodeTypeDefException, RepositoryException {
EffectiveNodeType entNew;
synchronized (this) {
Name name = ntd.getName();
if (!registeredNTDefs.containsKey(name)) {
throw new NoSuchNodeTypeException(name.toString());
}
if (builtInNTDefs.contains(name)) {
throw new RepositoryException(name.toString() + ": can't reregister built-in node type.");
}
/**
* validate new node type definition
*/
ntd = checkNtBaseSubtyping(ntd, registeredNTDefs);
validateNodeTypeDef(ntd, entCache, registeredNTDefs, nsReg, false);
/**
* build diff of current and new definition and determine type of change
*/
QNodeTypeDefinition ntdOld = registeredNTDefs.get(name);
NodeTypeDefDiff diff = NodeTypeDefDiff.create(ntdOld, ntd);
if (!diff.isModified()) {
// the definition has not been modified, there's nothing to do here...
return getEffectiveNodeType(name);
}
// make sure existing content would not conflict
// with new node type definition
checkForConflictingContent(ntd, diff);
/**
* re-register node type definition and update caches &
* notify listeners on re-registration
*/
internalUnregister(name);
// remove old node type definition from store
customNTDefs.remove(name);
entNew = internalRegister(ntd);
// add new node type definition to store
customNTDefs.add(ntd);
// persist node type definitions
persistCustomNodeTypeDefs(customNTDefs);
// notify listeners
notifyReRegistered(name);
}
// inform cluster if this is not an external invocation
if (!external && eventChannel != null) {
eventChannel.reregistered(ntd);
}
return entNew;
}
Aggregations