use of javax.jcr.nodetype.NodeDefinition in project jackrabbit by apache.
the class NodeDefTest method testIsAutoCreate.
/**
* Tests if auto create nodes are not a residual set definition (getName()
* does not return "*")
*/
public void testIsAutoCreate() throws RepositoryException {
NodeTypeIterator types = manager.getAllNodeTypes();
// loop all node types
while (types.hasNext()) {
NodeType type = types.nextNodeType();
NodeDefinition[] defs = type.getChildNodeDefinitions();
for (int i = 0; i < defs.length; i++) {
if (defs[i].isAutoCreated()) {
assertFalse("An auto create node must not be a " + "residual set definition.", defs[i].getName().equals("*"));
}
}
}
}
use of javax.jcr.nodetype.NodeDefinition in project jackrabbit by apache.
the class NodeTypeUtil method locateAllChildNodeDef.
/**
* Locate all 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 List<NodeDefinition> locateAllChildNodeDef(Session session, boolean regardDefaultPrimaryType, boolean defaultPrimaryType, boolean residual) throws RepositoryException {
List<NodeDefinition> nodeTypes = new ArrayList<NodeDefinition>();
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;
}
}
nodeTypes.add(nodeDef);
}
}
return nodeTypes;
}
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 RestoreTest method testRestoreWithUUIDConflictJcr2.
/**
* 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() 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(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 testRestoreWithUUIDConflictJcr2.
/**
* 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() 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(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
}
}
Aggregations