use of javax.jcr.nodetype.NodeDefinition in project jackrabbit by apache.
the class RestoreTest method testRestoreWithUUIDConflictJcr2_4.
/**
* Tests if restoring the <code>Version</code> of an existing node throws an
* <code>ItemExistsException</code> if removeExisting is set to FALSE.
*/
public void testRestoreWithUUIDConflictJcr2_4() throws RepositoryException, NotExecutableException {
try {
Node naa = createVersionableNode(versionableNode, nodeName4, versionableNodeType);
// Verify that nodes used for the test have proper opv behaviour
NodeDefinition nd = naa.getDefinition();
if (nd.getOnParentVersion() != OnParentVersionAction.COPY && nd.getOnParentVersion() != OnParentVersionAction.VERSION) {
throw new NotExecutableException("Child nodes must have OPV COPY or VERSION in order to be able to test Node.restore with uuid conflict.");
}
Version v = versionManager.checkin(versionableNode.getPath());
versionManager.checkout(versionableNode.getPath());
superuser.move(naa.getPath(), versionableNode2.getPath() + "/" + naa.getName());
superuser.save();
versionManager.restore(new Version[] { v }, false);
fail("Node.restore( Version, boolean ): An ItemExistsException must be thrown if the node to be restored already exsits and removeExisting was set to false.");
} catch (ItemExistsException e) {
// success
}
}
use of javax.jcr.nodetype.NodeDefinition in project jackrabbit by apache.
the class RestoreTest method testRestoreWithUUIDConflict.
/**
* Tests if restoring the <code>Version</code> of an existing node throws an
* <code>ItemExistsException</code> if removeExisting is set to FALSE.
*/
@SuppressWarnings("deprecation")
public void testRestoreWithUUIDConflict() throws RepositoryException, NotExecutableException {
try {
Node naa = createVersionableNode(versionableNode, nodeName4, versionableNodeType);
// Verify that nodes used for the test have proper opv behaviour
NodeDefinition nd = naa.getDefinition();
if (nd.getOnParentVersion() != OnParentVersionAction.COPY && nd.getOnParentVersion() != OnParentVersionAction.VERSION) {
throw new NotExecutableException("Child nodes must have OPV COPY or VERSION in order to be able to test Node.restore with uuid conflict.");
}
Version v = versionableNode.checkin();
versionableNode.checkout();
superuser.move(naa.getPath(), versionableNode2.getPath() + "/" + naa.getName());
superuser.save();
versionableNode.restore(v, false);
fail("Node.restore( Version, boolean ): An ItemExistsException must be thrown if the node to be restored already exsits and removeExisting was set to false.");
} catch (ItemExistsException e) {
// success
}
}
use of javax.jcr.nodetype.NodeDefinition in project jackrabbit by apache.
the class NodeTypeManagerImpl method getNodeDefinition.
/**
* Retrieve the <code>NodeDefinition</code> for the given
* <code>QNodeDefinition</code>.
*
* @param def
* @return
*/
@Override
public NodeDefinition getNodeDefinition(QNodeDefinition def) {
synchronized (ndCache) {
NodeDefinition ndi = ndCache.get(def);
if (ndi == null) {
ndi = new NodeDefinitionImpl(def, this, getNamePathResolver());
ndCache.put(def, ndi);
}
return ndi;
}
}
use of javax.jcr.nodetype.NodeDefinition in project jackrabbit by apache.
the class NodeTypeUtil method locateChildNodeDef.
/**
* Locate a non-protected child node def declared by a non-abstract node type
* parsing all node types
*
* @param session the session to access the node types
* @param regardDefaultPrimaryType if true, the default primary type of the
* returned <code>NodeDef</code> is
* according to param <code>defaultPrimaryType</code>.
* If false, the returned <code>NodeDef</code>
* might have a default primary type or
* not.
* @param defaultPrimaryType if <code>regardDefaultPrimaryType</code>
* is true: if true, the returned
* <code>NodeDef</code> has a default
* primary type, else not
* @param residual if true, the returned <code>NodeDef</code>
* is of the residual name "*", else not
* @return
* @throws RepositoryException
*/
public static NodeDefinition locateChildNodeDef(Session session, boolean regardDefaultPrimaryType, boolean defaultPrimaryType, boolean residual) throws RepositoryException {
NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
NodeTypeIterator types = manager.getAllNodeTypes();
boolean skip = false;
while (types.hasNext()) {
NodeType type = types.nextNodeType();
// node types with more than one residual child node definition
// will cause trouble in test cases. the implementation
// might pick another definition than the definition returned by
// this method, when a child node is set.
NodeDefinition[] childDefs = type.getChildNodeDefinitions();
int residuals = 0;
for (int i = 0; i < childDefs.length; i++) {
if (childDefs[i].getName().equals("*")) {
residuals++;
}
}
if (residuals > 1) {
// more than one residual, not suitable for tests
continue;
}
NodeDefinition[] nodeDefs = type.getDeclaredChildNodeDefinitions();
for (int i = 0; i < nodeDefs.length; i++) {
NodeDefinition nodeDef = nodeDefs[i];
if (nodeDef.getDeclaringNodeType().isAbstract()) {
continue;
}
if (nodeDef.isProtected()) {
continue;
}
if (nodeDef.getRequiredPrimaryTypes().length > 1) {
// of primary node types is not specified
continue;
}
if (regardDefaultPrimaryType) {
if (defaultPrimaryType && nodeDef.getDefaultPrimaryType() == null) {
continue;
}
if (!defaultPrimaryType && nodeDef.getDefaultPrimaryType() != null) {
continue;
}
}
if (residual && !nodeDef.getName().equals("*")) {
continue;
}
if (!residual) {
// if another child node def is a residual definition
// skip the current node type
NodeDefinition[] nodeDefsAll = type.getChildNodeDefinitions();
for (int j = 0; j < nodeDefsAll.length; j++) {
if (nodeDefsAll[j].getName().equals("*")) {
skip = true;
break;
}
}
if (skip) {
// break the loop of the current child not defs
skip = false;
break;
}
}
return nodeDef;
}
}
return null;
}
use of javax.jcr.nodetype.NodeDefinition in project sling by apache.
the class MockNodeTypeGenerator method getSimpleChildNodeDef.
public NodeDefinition getSimpleChildNodeDef(String name) {
NodeDefinition childNodeDef1 = mock(NodeDefinition.class);
NodeType[] reqPrimaryTypes = { getSimpleNodeTypeWithName(NODETYPE_REQ_PRIMARY_TYPE_NAME1), getSimpleNodeTypeWithName(NODETYPE_REQ_PRIMARY_TYPE_NAME2) };
when(childNodeDef1.getRequiredPrimaryTypes()).thenReturn(reqPrimaryTypes);
when(childNodeDef1.getName()).thenReturn(name);
when(childNodeDef1.getOnParentVersion()).thenReturn(OnParentVersionAction.COPY);
return childNodeDef1;
}
Aggregations