use of org.apache.jackrabbit.spi.QNodeDefinition in project jackrabbit by apache.
the class SessionImporter method startNode.
/**
* {@inheritDoc}
*/
public void startNode(NodeInfo nodeInfo, List<PropInfo> propInfos, NamePathResolver resolver) throws RepositoryException {
if (isClosed()) {
// workspace-importer only: ignore if import has been aborted before.
return;
}
checkSession();
NodeState parent = parents.peek();
if (parent == null) {
// parent node was skipped, skip this child node also
// push null onto stack for skipped node
parents.push(null);
log.debug("Skipping node '" + nodeInfo.getName() + "'.");
return;
}
NodeEntry parentEntry = (NodeEntry) parent.getHierarchyEntry();
NodeState nodeState = null;
if (parentEntry.hasNodeEntry(nodeInfo.getName())) {
try {
// a valid child node with that name already exists
NodeEntry entry = parentEntry.getNodeEntry(nodeInfo.getName(), Path.INDEX_DEFAULT);
NodeState existing = entry.getNodeState();
QNodeDefinition def = existing.getDefinition();
if (!def.allowsSameNameSiblings()) {
// existing doesn't allow same-name siblings, check for conflicts
EffectiveNodeTypeProvider provider = session.getEffectiveNodeTypeProvider();
Name[] ntNames = existing.getAllNodeTypeNames();
EffectiveNodeType entExisting = provider.getEffectiveNodeType(ntNames);
if (def.isProtected() && entExisting.includesNodeType(nodeInfo.getNodeTypeName())) {
// skip protected node
// push null onto stack for skipped node
parents.push(null);
log.debug("skipping protected node " + LogUtil.safeGetJCRPath(existing, session.getPathResolver()));
return;
}
if (def.isAutoCreated() && entExisting.includesNodeType(nodeInfo.getNodeTypeName())) {
// this node has already been auto-created, no need to create it
nodeState = existing;
} else {
throw new ItemExistsException(LogUtil.safeGetJCRPath(existing, session.getPathResolver()));
}
}
} catch (ItemNotFoundException e) {
// 'existing' doesn't exist any more -> ignore
}
}
if (nodeState == null) {
// node does not exist -> create new one
if (nodeInfo.getUUID() == null) {
// no potential uuid conflict, add new node from given info
nodeState = importNode(nodeInfo, parent);
} else {
// make sure the import does not define a uuid without having
// a primaryType or mixin that makes the new node referenceable
checkIncludesMixReferenceable(nodeInfo);
// potential uuid conflict
try {
NodeId conflictingId = session.getIdFactory().createNodeId(nodeInfo.getUUID());
NodeEntry conflicting = session.getHierarchyManager().getNodeEntry(conflictingId);
// assert that the entry is available
conflicting.getItemState();
nodeState = resolveUUIDConflict(parent, conflicting, nodeInfo);
} catch (ItemNotFoundException e) {
// no conflict: create new with given uuid
nodeState = importNode(nodeInfo, parent);
}
}
}
// node state may be 'null' if applicable def is protected
if (nodeState != null) {
// process properties
for (PropInfo pi : propInfos) {
importProperty(pi, nodeState, resolver);
}
}
// push current nodeState onto stack of parents
parents.push(nodeState);
}
use of org.apache.jackrabbit.spi.QNodeDefinition in project jackrabbit by apache.
the class SessionImporter method importNode.
/**
* @param nodeInfo
* @param parent
* @return
* @throws ConstraintViolationException
* @throws ItemNotFoundException
* @throws RepositoryException
*/
private NodeState importNode(NodeInfo nodeInfo, NodeState parent) throws ConstraintViolationException, ItemNotFoundException, RepositoryException {
Name[] parentNtNames = parent.getAllNodeTypeNames();
if (parent.hasPropertyName(nodeInfo.getName())) {
/**
* a property with the same name already exists; if this property
* has been imported as well (e.g. through document view import
* where an element can have the same name as one of the attributes
* of its parent element) we have to rename the conflicting property;
*
* see http://issues.apache.org/jira/browse/JCR-61
*/
PropertyState conflicting = parent.getPropertyState(nodeInfo.getName());
if (conflicting.getStatus() == Status.NEW) {
// assume this property has been imported as well;
// rename conflicting property
// TODO: use better reversible escaping scheme to create unique name
Name newName = session.getNameFactory().create(nodeInfo.getName().getNamespaceURI(), nodeInfo.getName().getLocalName() + "_");
if (parent.hasPropertyName(newName)) {
newName = session.getNameFactory().create(newName.getNamespaceURI(), newName.getLocalName() + "_");
}
// since name changes, need to find new applicable definition
QPropertyDefinition propDef;
if (conflicting.getValues().length == 1) {
// could be single- or multi-valued (n == 1)
try {
// try single-valued
propDef = session.getItemDefinitionProvider().getQPropertyDefinition(parentNtNames, newName, conflicting.getType(), false);
} catch (ConstraintViolationException cve) {
// try multi-valued
propDef = session.getItemDefinitionProvider().getQPropertyDefinition(parentNtNames, newName, conflicting.getType(), true);
}
} else {
// can only be multi-valued (n == 0 || n > 1)
propDef = session.getItemDefinitionProvider().getQPropertyDefinition(parentNtNames, newName, conflicting.getType(), true);
}
Operation ap = AddProperty.create(parent, newName, conflicting.getType(), propDef, conflicting.getValues());
stateMgr.execute(ap);
Operation rm = Remove.create(conflicting);
stateMgr.execute(rm);
}
}
// do create new nodeState
QNodeDefinition def = session.getItemDefinitionProvider().getQNodeDefinition(parentNtNames, nodeInfo.getName(), nodeInfo.getNodeTypeName());
if (def.isProtected()) {
log.debug("Skipping protected nodeState (" + nodeInfo.getName() + ")");
return null;
} else {
Name ntName = nodeInfo.getNodeTypeName();
if (ntName == null) {
// use default node type
ntName = def.getDefaultPrimaryType();
}
Operation an = AddNode.create(parent, nodeInfo.getName(), ntName, nodeInfo.getUUID());
stateMgr.execute(an);
// retrieve id of state that has been created during execution of AddNode
NodeState childState = (NodeState) ((AddNode) an).getAddedStates().get(0);
// and set mixin types
Name[] mixinNames = nodeInfo.getMixinNames();
if (mixinNames != null && mixinNames.length > 0) {
Operation sm = SetMixin.create(childState, nodeInfo.getMixinNames());
stateMgr.execute(sm);
}
return childState;
}
}
use of org.apache.jackrabbit.spi.QNodeDefinition in project jackrabbit by apache.
the class TestAll method testDefaultTypeNode.
/**
* Test for the <code>defaultPrimaryType</code> child node attribute.
*/
public void testDefaultTypeNode() {
QNodeDefinition def = getChildNode("childNodeType", "defaultTypeNode");
assertEquals("defaultTypeNode defaultPrimaryType", FACTORY.create(Name.NS_NT_URI, "base"), def.getDefaultPrimaryType());
}
use of org.apache.jackrabbit.spi.QNodeDefinition in project jackrabbit by apache.
the class ItemDefinitionProviderImpl method getQNodeDefinition.
public QNodeDefinition getQNodeDefinition(Name[] parentNodeTypeNames, Name nodeName, Name ntName, NodeId nodeId) throws RepositoryException {
if (parentNodeTypeNames == null) {
return getRootNodeDefinition();
}
QNodeDefinition definition;
try {
EffectiveNodeType ent = entProvider.getEffectiveNodeType(parentNodeTypeNames);
EffectiveNodeType entTarget = getEffectiveNodeType(ntName);
definition = getQNodeDefinition(ent, entTarget, nodeName);
} catch (RepositoryException e) {
log.debug("Cannot determine effective node type of {}: {}", nodeId, e);
definition = getNodeDefinition(service, sessionInfo, nodeId);
}
return definition;
}
use of org.apache.jackrabbit.spi.QNodeDefinition in project jackrabbit by apache.
the class NodeTypeImpl method getChildNodeDefinitions.
/**
* @see javax.jcr.nodetype.NodeType#getChildNodeDefinitions()
*/
public NodeDefinition[] getChildNodeDefinitions() {
QNodeDefinition[] cnda = ent.getAllQNodeDefinitions();
NodeDefinition[] nodeDefs = new NodeDefinition[cnda.length];
for (int i = 0; i < cnda.length; i++) {
nodeDefs[i] = ntMgr.getNodeDefinition(cnda[i]);
}
return nodeDefs;
}
Aggregations