use of javax.jcr.nodetype.NodeDefinition in project jackrabbit by apache.
the class SessionImporter method startNode.
/**
* {@inheritDoc}
*/
public void startNode(NodeInfo nodeInfo, List<PropInfo> propInfos) throws RepositoryException {
NodeImpl parent = parents.peek();
// process node
NodeImpl node = null;
NodeId id = nodeInfo.getId();
Name nodeName = nodeInfo.getName();
Name ntName = nodeInfo.getNodeTypeName();
Name[] mixins = nodeInfo.getMixinNames();
if (parent == null) {
log.debug("Skipping node: " + nodeName);
// parent node was skipped, skip this child node too
// push null onto stack for skipped node
parents.push(null);
// notify the p-i-importer
if (pnImporter != null) {
pnImporter.startChildInfo(nodeInfo, propInfos);
}
return;
}
if (parent.getDefinition().isProtected()) {
// skip protected node
parents.push(null);
log.debug("Skipping protected node: " + nodeName);
if (pnImporter != null) {
// pnImporter was already started (current nodeInfo is a sibling)
// notify it about this child node.
pnImporter.startChildInfo(nodeInfo, propInfos);
} else {
// potentially is able to deal with it, notify it about the child node.
for (ProtectedItemImporter pni : pItemImporters) {
if (pni instanceof ProtectedNodeImporter && ((ProtectedNodeImporter) pni).start(parent)) {
log.debug("Protected node -> delegated to ProtectedNodeImporter");
pnImporter = (ProtectedNodeImporter) pni;
pnImporter.startChildInfo(nodeInfo, propInfos);
break;
}
/* else: p-i-Importer isn't able to deal with the protected tree.
try next. and if none can handle the passed parent the
tree below will be skipped */
}
}
return;
}
if (parent.hasNode(nodeName)) {
// a node with that name already exists...
NodeImpl existing = parent.getNode(nodeName);
NodeDefinition def = existing.getDefinition();
if (!def.allowsSameNameSiblings()) {
// check for potential conflicts
if (def.isProtected() && existing.isNodeType(ntName)) {
/*
use the existing node as parent for the possible subsequent
import of a protected tree, that the protected node importer
may or may not be able to deal with.
-> upon the next 'startNode' the check for the parent being
protected will notify the protected node importer.
-> if the importer is able to deal with that node it needs
to care of the complete subtree until it is notified
during the 'endNode' call.
-> if the import can't deal with that node or if that node
is the a leaf in the tree to be imported 'end' will
not have an effect on the importer, that was never started.
*/
log.debug("Skipping protected node: " + existing);
parents.push(existing);
return;
}
if (def.isAutoCreated() && existing.isNodeType(ntName)) {
// this node has already been auto-created, no need to create it
node = existing;
} else {
// (see http://issues.apache.org/jira/browse/JCR-1128)
if (!(existing.getId().equals(id) && (uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING || uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING))) {
throw new ItemExistsException("Node with the same UUID exists:" + existing);
}
// fall through
}
}
}
if (node == null) {
// create node
if (id == null) {
// no potential uuid conflict, always add new node
checkPermission(parent, nodeName);
node = createNode(parent, nodeName, ntName, mixins, null);
} else {
// potential uuid conflict
boolean isConflicting;
try {
// the following is a fail-fast test whether
// an item exists (regardless of access control)
session.getHierarchyManager().getName(id);
isConflicting = true;
} catch (ItemNotFoundException infe) {
isConflicting = false;
}
if (isConflicting) {
// resolve uuid conflict
node = resolveUUIDConflict(parent, id, nodeInfo);
if (node == null) {
// no new node has been created, so skip this node
// push null onto stack for skipped node
parents.push(null);
log.debug("Skipping existing node " + nodeInfo.getName());
return;
}
} else {
// create new with given uuid
checkPermission(parent, nodeName);
node = createNode(parent, nodeName, ntName, mixins, id);
}
}
}
for (PropInfo pi : propInfos) {
// find applicable definition
QPropertyDefinition def = pi.getApplicablePropertyDef(node.getEffectiveNodeType());
if (def.isProtected()) {
// skip protected property
log.debug("Skipping protected property " + pi.getName());
// notify the ProtectedPropertyImporter.
for (ProtectedItemImporter ppi : pItemImporters) {
if (ppi instanceof ProtectedPropertyImporter && ((ProtectedPropertyImporter) ppi).handlePropInfo(node, pi, def)) {
log.debug("Protected property -> delegated to ProtectedPropertyImporter");
break;
}
/* else: p-i-Importer isn't able to deal with this property.
try next pp-importer */
}
} else {
// regular property -> create the property
createProperty(node, pi, def);
}
}
parents.push(node);
}
use of javax.jcr.nodetype.NodeDefinition in project jackrabbit by apache.
the class GQL method resolveChildNodeName.
/**
* Resolves the given node name. If the name has a prefix then the name
* is returned immediately as is. Otherwise the node type manager is
* searched for a node definition that defines a named child node with
* a local name that matches the provided <code>name</code>. If such a match
* is found the name of the node definition is returned.
*
* @param name the name of a node (optionally without a prefix).
* @return the resolved node name.
* @throws RepositoryException if an error occurs while reading from the
* node type manager.
*/
private String resolveChildNodeName(String name) throws RepositoryException {
if (isPrefixed(name)) {
return name;
}
if (childNodeNames == null) {
childNodeNames = new HashMap<String, String>();
NodeTypeManager ntMgr = session.getWorkspace().getNodeTypeManager();
NodeTypeIterator it = ntMgr.getAllNodeTypes();
while (it.hasNext()) {
NodeType nt = it.nextNodeType();
NodeDefinition[] defs = nt.getDeclaredChildNodeDefinitions();
for (NodeDefinition def : defs) {
String cnn = def.getName();
if (!cnn.equals("*")) {
String localName = cnn;
int idx = cnn.indexOf(':');
if (idx != -1) {
localName = cnn.substring(idx + 1);
}
childNodeNames.put(localName, cnn);
}
}
}
}
String cnn = childNodeNames.get(name);
if (cnn != null) {
return cnn;
} else {
return name;
}
}
use of javax.jcr.nodetype.NodeDefinition in project jackrabbit by apache.
the class CompactNodeTypeDefWriter method write.
/**
* Write one NodeTypeDefinition to this writer
*
* @param ntd node type definition
* @throws IOException if an I/O error occurs
*/
public void write(NodeTypeDefinition ntd) throws IOException {
writeName(ntd);
writeSupertypes(ntd);
writeOptions(ntd);
PropertyDefinition[] pdefs = ntd.getDeclaredPropertyDefinitions();
if (pdefs != null) {
for (PropertyDefinition pd : pdefs) {
writePropDef(pd);
}
}
NodeDefinition[] ndefs = ntd.getDeclaredChildNodeDefinitions();
if (ndefs != null) {
for (NodeDefinition nd : ndefs) {
writeNodeDef(nd);
}
}
out.write("\n\n");
}
use of javax.jcr.nodetype.NodeDefinition in project jackrabbit by apache.
the class CanAddChildNodeCallWithNodeTypeTest method testResidualAndIllegalType.
/**
* Tests if <code>NodeType.canAddChildNode(String childNodeName, String nodeTypeName)</code>
* returns false if <code>childNodeName</code> does not match the <code>NodeDef</code>
* and <code>nodeTypeName</code> does not matches the node type of a residual
* <code>NodeDef</code>.
*/
public void testResidualAndIllegalType() throws NotExecutableException, RepositoryException {
NodeDefinition nodeDef = NodeTypeUtil.locateChildNodeDef(session, false, false, true);
if (nodeDef == null) {
throw new NotExecutableException("No testable residual child node def.");
}
NodeType nodeType = nodeDef.getDeclaringNodeType();
String undefinedName = NodeTypeUtil.getUndefinedChildNodeName(nodeType);
String legalType = nodeDef.getRequiredPrimaryTypes()[0].getName();
String illegalType = NodeTypeUtil.getIllegalChildNodeType(manager, legalType);
if (illegalType == null) {
throw new NotExecutableException("No illegal node type name found");
}
assertFalse("NodeType.canAddChildNode(String childNodeName, String nodeTypeName) " + "must return false for a not defined childNodeName if nodeTypeName " + "does not matches the type of a residual child node def", nodeType.canAddChildNode(undefinedName, illegalType));
}
use of javax.jcr.nodetype.NodeDefinition in project jackrabbit by apache.
the class CanAddChildNodeCallWithoutNodeTypeTest method testUndefined.
/**
* Tests if <code>NodeType.canAddChildNode(String childNodeName)</code> returns
* true if <code>NodeType</code> nor does contain a <code>NodeDef</code> named
* <code>childNodeName</code> nor a residual definition.
*/
public void testUndefined() throws NotExecutableException, RepositoryException {
NodeDefinition nodeDef = NodeTypeUtil.locateChildNodeDef(session, false, true, false);
if (nodeDef == null) {
throw new NotExecutableException("No testable node type found.");
}
NodeType nodeType = nodeDef.getDeclaringNodeType();
String undefinedName = NodeTypeUtil.getUndefinedChildNodeName(nodeType);
assertFalse("NodeType.canAddChildNode(String childNodeName) must return " + "false if 'childNodeName' is a undefined child node def", nodeType.canAddChildNode(undefinedName));
}
Aggregations