use of org.apache.jackrabbit.spi.QNodeDefinition in project jackrabbit by apache.
the class TestAll method getChildNode.
/**
* Returns the named child node definition from the named node type
* definition. If either of the definitions do not exist, an assertion
* failure is generated.
*
* @param typeName node type name
* @param nodeName child node name
* @return child node definition
*/
private QNodeDefinition getChildNode(String typeName, String nodeName) {
Name name = FACTORY.create(TEST_NAMESPACE, nodeName);
QNodeTypeDefinition def = getNodeType(typeName);
QNodeDefinition[] defs = def.getChildNodeDefs();
for (int i = 0; i < defs.length; i++) {
if (name.equals(defs[i].getName())) {
return defs[i];
}
}
throw new AssertionFailedError("Child node " + nodeName + " does not exist");
}
use of org.apache.jackrabbit.spi.QNodeDefinition in project jackrabbit by apache.
the class TestAll method testEmptyNode.
/**
* Test for the empty child node definition.
*/
public void testEmptyNode() {
QNodeDefinition def = getChildNode("childNodeType", "emptyNode");
assertEquals("emptyNode allowsSameNameSiblings", false, def.allowsSameNameSiblings());
assertEquals("emptyNode defaultPrimaryType", null, def.getDefaultPrimaryType());
}
use of org.apache.jackrabbit.spi.QNodeDefinition in project jackrabbit by apache.
the class BatchedItemOperations method createNodeState.
/**
* Creates a new node based on the given definition.
* <p>
* Note that access rights are <b><i>not</i></b> enforced!
* <p>
* <b>Precondition:</b> the state manager needs to be in edit mode.
*
* @param parent
* @param nodeName
* @param nodeTypeName
* @param mixinNames
* @param id
* @param def
* @return
* @throws ItemExistsException
* @throws ConstraintViolationException
* @throws RepositoryException
* @throws IllegalStateException
*/
public NodeState createNodeState(NodeState parent, Name nodeName, Name nodeTypeName, Name[] mixinNames, NodeId id, QNodeDefinition def) throws ItemExistsException, ConstraintViolationException, RepositoryException, IllegalStateException {
// check for name collisions with existing nodes
if (!def.allowsSameNameSiblings() && parent.hasChildNodeEntry(nodeName)) {
NodeId errorId = parent.getChildNodeEntry(nodeName, 1).getId();
throw new ItemExistsException(safeGetJCRPath(errorId));
}
if (nodeTypeName == null) {
// no primary node type specified,
// try default primary type from definition
nodeTypeName = def.getDefaultPrimaryType();
if (nodeTypeName == null) {
String msg = "an applicable node type could not be determined for " + nodeName;
log.debug(msg);
throw new ConstraintViolationException(msg);
}
}
NodeState node = stateMgr.createNew(id, nodeTypeName, parent.getNodeId());
if (mixinNames != null && mixinNames.length > 0) {
node.setMixinTypeNames(new HashSet<Name>(Arrays.asList(mixinNames)));
}
// now add new child node entry to parent
parent.addChildNodeEntry(nodeName, node.getNodeId());
EffectiveNodeType ent = getEffectiveNodeType(node);
// check shareable
if (ent.includesNodeType(NameConstants.MIX_SHAREABLE)) {
node.addShare(parent.getNodeId());
}
if (!node.getMixinTypeNames().isEmpty()) {
// create jcr:mixinTypes property
QPropertyDefinition pd = ent.getApplicablePropertyDef(NameConstants.JCR_MIXINTYPES, PropertyType.NAME, true);
createPropertyState(node, pd.getName(), pd.getRequiredType(), pd);
}
// add 'auto-create' properties defined in node type
for (QPropertyDefinition pd : ent.getAutoCreatePropDefs()) {
createPropertyState(node, pd.getName(), pd.getRequiredType(), pd);
}
// recursively add 'auto-create' child nodes defined in node type
for (QNodeDefinition nd : ent.getAutoCreateNodeDefs()) {
createNodeState(node, nd.getName(), nd.getDefaultPrimaryType(), null, null, nd);
}
// store node
stateMgr.store(node);
// store parent
stateMgr.store(parent);
return node;
}
use of org.apache.jackrabbit.spi.QNodeDefinition in project jackrabbit by apache.
the class VirtualNodeTypeStateProvider method createNodeTypeState.
/**
* Creates a node type state
*
* @param parent
* @param ntDef
* @return
* @throws RepositoryException
*/
private VirtualNodeState createNodeTypeState(VirtualNodeState parent, QNodeTypeDefinition ntDef) throws RepositoryException {
NodeId id = calculateStableId(ntDef.getName().toString());
VirtualNodeState ntState = createNodeState(parent, ntDef.getName(), id, NameConstants.NT_NODETYPE);
// add properties
ntState.setPropertyValue(NameConstants.JCR_NODETYPENAME, InternalValue.create(ntDef.getName()));
ntState.setPropertyValues(NameConstants.JCR_SUPERTYPES, PropertyType.NAME, InternalValue.create(ntDef.getSupertypes()));
ntState.setPropertyValue(NameConstants.JCR_ISMIXIN, InternalValue.create(ntDef.isMixin()));
ntState.setPropertyValue(NameConstants.JCR_HASORDERABLECHILDNODES, InternalValue.create(ntDef.hasOrderableChildNodes()));
if (ntDef.getPrimaryItemName() != null) {
ntState.setPropertyValue(NameConstants.JCR_PRIMARYITEMNAME, InternalValue.create(ntDef.getPrimaryItemName()));
}
// add property defs
QPropertyDefinition[] propDefs = ntDef.getPropertyDefs();
for (int i = 0; i < propDefs.length; i++) {
VirtualNodeState pdState = createPropertyDefState(ntState, propDefs[i], ntDef, i);
ntState.addChildNodeEntry(NameConstants.JCR_PROPERTYDEFINITION, pdState.getNodeId());
// add as hard reference
ntState.addStateReference(pdState);
}
// add child node defs
QNodeDefinition[] cnDefs = ntDef.getChildNodeDefs();
for (int i = 0; i < cnDefs.length; i++) {
VirtualNodeState cnState = createChildNodeDefState(ntState, cnDefs[i], ntDef, i);
ntState.addChildNodeEntry(NameConstants.JCR_CHILDNODEDEFINITION, cnState.getNodeId());
// add as hard reference
ntState.addStateReference(cnState);
}
return ntState;
}
use of org.apache.jackrabbit.spi.QNodeDefinition in project jackrabbit by apache.
the class NodeTypeRegistry method toString.
// --------------------------------------------------------------< Object >
/**
* {@inheritDoc}
*/
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("NodeTypeRegistry (" + super.toString() + ")\n");
builder.append("Registered NodeTypes:\n");
for (QNodeTypeDefinition ntd : registeredNTDefs.values()) {
builder.append(ntd.getName());
builder.append("\n");
builder.append("\tSupertypes: " + Arrays.toString(ntd.getSupertypes()) + "\n");
builder.append("\tMixin\t" + ntd.isMixin() + "\n");
builder.append("\tOrderableChildNodes\t" + ntd.hasOrderableChildNodes() + "\n");
builder.append("\tPrimaryItemName\t" + (ntd.getPrimaryItemName() == null ? "<null>" : ntd.getPrimaryItemName().toString()) + "\n");
QPropertyDefinition[] pd = ntd.getPropertyDefs();
for (QPropertyDefinition aPd : pd) {
builder.append("\tPropertyDefinition\n");
builder.append(" (declared in " + aPd.getDeclaringNodeType() + ")\n");
builder.append("\t\tName\t\t" + (aPd.definesResidual() ? "*" : aPd.getName().toString()) + "\n");
String type = aPd.getRequiredType() == 0 ? "null" : PropertyType.nameFromValue(aPd.getRequiredType());
builder.append("\t\tRequiredType\t" + type + "\n");
QValueConstraint[] vca = aPd.getValueConstraints();
StringBuilder constraints = new StringBuilder();
if (vca == null) {
constraints.append("<null>");
} else {
for (QValueConstraint aVca : vca) {
if (constraints.length() > 0) {
constraints.append(", ");
}
constraints.append(aVca.getString());
}
}
builder.append("\t\tValueConstraints\t" + constraints + "\n");
QValue[] defVals = aPd.getDefaultValues();
StringBuilder defaultValues = new StringBuilder();
if (defVals == null) {
defaultValues.append("<null>");
} else {
for (QValue defVal : defVals) {
if (defaultValues.length() > 0) {
defaultValues.append(", ");
}
defaultValues.append(defVal.toString());
}
}
builder.append("\t\tDefaultValue\t" + defaultValues + "\n");
builder.append("\t\tAutoCreated\t" + aPd.isAutoCreated() + "\n");
builder.append("\t\tMandatory\t" + aPd.isMandatory() + "\n");
builder.append("\t\tOnVersion\t" + OnParentVersionAction.nameFromValue(aPd.getOnParentVersion()) + "\n");
builder.append("\t\tProtected\t" + aPd.isProtected() + "\n");
builder.append("\t\tMultiple\t" + aPd.isMultiple() + "\n");
}
QNodeDefinition[] nd = ntd.getChildNodeDefs();
for (QNodeDefinition aNd : nd) {
builder.append("\tNodeDefinition\\n");
builder.append(" (declared in " + aNd.getDeclaringNodeType() + ")\\n");
builder.append("\t\tName\t\t" + (aNd.definesResidual() ? "*" : aNd.getName().toString()) + "\n");
Name[] reqPrimaryTypes = aNd.getRequiredPrimaryTypes();
if (reqPrimaryTypes != null && reqPrimaryTypes.length > 0) {
for (Name reqPrimaryType : reqPrimaryTypes) {
builder.append("\t\tRequiredPrimaryType\t" + reqPrimaryType + "\n");
}
}
Name defPrimaryType = aNd.getDefaultPrimaryType();
if (defPrimaryType != null) {
builder.append("\n\t\tDefaultPrimaryType\t" + defPrimaryType + "\n");
}
builder.append("\n\t\tAutoCreated\t" + aNd.isAutoCreated() + "\n");
builder.append("\t\tMandatory\t" + aNd.isMandatory() + "\n");
builder.append("\t\tOnVersion\t" + OnParentVersionAction.nameFromValue(aNd.getOnParentVersion()) + "\n");
builder.append("\t\tProtected\t" + aNd.isProtected() + "\n");
builder.append("\t\tAllowsSameNameSiblings\t" + aNd.allowsSameNameSiblings() + "\n");
}
}
builder.append(entCache);
return builder.toString();
}
Aggregations