use of javax.jcr.nodetype.NodeDefinition in project jackrabbit by apache.
the class CanAddChildNodeCallWithNodeTypeTest method testDefinedAndLegalType.
/**
* Tests if <code>NodeType.canAddChildNode(String childNodeName, String nodeTypeName)</code>
* returns true if <code>childNodeName</code> and <code>nodeTypeName</code>
* match the <code>NodeDef</code>.
*/
public void testDefinedAndLegalType() throws NotExecutableException, RepositoryException {
NodeDefinition nodeDef = NodeTypeUtil.locateChildNodeDef(session, false, false, false);
if (nodeDef == null) {
throw new NotExecutableException("No child node def with " + "defaultPrimaryType found");
}
NodeType nodeType = nodeDef.getDeclaringNodeType();
String childNodeName = nodeDef.getName();
String nodeTypeName = nodeDef.getRequiredPrimaryTypes()[0].getName();
if (nodeTypeName.equals(ntBase)) {
// nt:base is abstract and can never be added, upgrade for check below
nodeTypeName = ntUnstructured;
}
assertTrue("NodeType.canAddChildNode(String childNodeName, String nodeTypeName) " + "must return true if childNodeName and nodeTypeName match the " + "child node def of NodeType.", nodeType.canAddChildNode(childNodeName, nodeTypeName));
}
use of javax.jcr.nodetype.NodeDefinition in project jackrabbit by apache.
the class CanAddChildNodeCallWithNodeTypeTest method testCanAddMixinType.
/**
* Tests if <code>NodeType.canAddChildNode(String childNodeName, String nodeTypeName)</code>
* returns false if <code>nodeTypeName</code> represents a mixin.
*/
public void testCanAddMixinType() throws NotExecutableException, RepositoryException {
NodeDefinition nodeDef = NodeTypeUtil.locateChildNodeDef(session, false, false, false);
if (nodeDef == null) {
throw new NotExecutableException("No testable node type found.");
}
NodeType nodeType = nodeDef.getDeclaringNodeType();
String childNodeName = nodeDef.getName();
String mixinName;
NodeTypeIterator it = manager.getMixinNodeTypes();
if (it.hasNext()) {
mixinName = it.nextNodeType().getName();
} else {
throw new NotExecutableException("No mixin type found.");
}
assertFalse("NodeType.canAddChildNode(String childNodeName, String nodeTypeName) " + "must return false if nodeTypeName represents a mixin type.", nodeType.canAddChildNode(childNodeName, mixinName));
}
use of javax.jcr.nodetype.NodeDefinition in project jackrabbit by apache.
the class CanAddChildNodeCallWithNodeTypeTest method testDefinedAndIllegalType.
/**
* Tests if <code>NodeType.canAddChildNode(String childNodeName, String nodeTypeName)</code>
* returns false if <code>childNodeName</code> does and <code>nodeTypeName</code>
* does not match the <code>NodeDef</code>.
*/
public void testDefinedAndIllegalType() throws NotExecutableException, RepositoryException {
NodeDefinition nodeDef = NodeTypeUtil.locateChildNodeDef(session, false, false, false);
if (nodeDef == null) {
throw new NotExecutableException("No testable node type found.");
}
NodeType nodeType = nodeDef.getDeclaringNodeType();
String childNodeName = nodeDef.getName();
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 if childNodeName does and nodeTypeName does not " + "match the child node def of NodeType.", nodeType.canAddChildNode(childNodeName, illegalType));
}
use of javax.jcr.nodetype.NodeDefinition in project jackrabbit by apache.
the class NodeTypeManagerImpl method toString.
//-------------------------------------------------------------< Object >---
/**
* Returns the the state of this instance in a human readable format.
*/
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("NodeTypeManager (" + super.toString() + ")\n");
builder.append("All NodeTypes:\n");
try {
NodeTypeIterator iter = this.getAllNodeTypes();
while (iter.hasNext()) {
NodeType nt = iter.nextNodeType();
builder.append(nt.getName());
builder.append("\n\tSupertypes");
for (NodeType supertype : nt.getSupertypes()) {
builder.append("\n\t\t" + supertype.getName());
}
builder.append("\n\tMixin\t" + nt.isMixin());
builder.append("\n\tOrderableChildNodes\t" + nt.hasOrderableChildNodes());
builder.append("\n\tPrimaryItemName\t" + (nt.getPrimaryItemName() == null ? "<null>" : nt.getPrimaryItemName()));
for (PropertyDefinition aPd : nt.getPropertyDefinitions()) {
builder.append("\n\tPropertyDefinition");
builder.append(" (declared in " + aPd.getDeclaringNodeType().getName() + ") ");
builder.append("\n\t\tName\t\t" + (aPd.getName()));
String type = aPd.getRequiredType() == 0 ? "null" : PropertyType.nameFromValue(aPd.getRequiredType());
builder.append("\n\t\tRequiredType\t" + type);
String[] vca = aPd.getValueConstraints();
StringBuffer constraints = new StringBuffer();
if (vca == null) {
constraints.append("<null>");
} else {
for (String aVca : vca) {
if (constraints.length() > 0) {
constraints.append(", ");
}
constraints.append(aVca);
}
}
builder.append("\n\t\tValueConstraints\t" + constraints.toString());
Value[] defVals = aPd.getDefaultValues();
StringBuffer defaultValues = new StringBuffer();
if (defVals == null) {
defaultValues.append("<null>");
} else {
for (Value defVal : defVals) {
if (defaultValues.length() > 0) {
defaultValues.append(", ");
}
defaultValues.append(defVal.getString());
}
}
builder.append("\n\t\tDefaultValue\t" + defaultValues.toString());
builder.append("\n\t\tAutoCreated\t" + aPd.isAutoCreated());
builder.append("\n\t\tMandatory\t" + aPd.isMandatory());
builder.append("\n\t\tOnVersion\t" + OnParentVersionAction.nameFromValue(aPd.getOnParentVersion()));
builder.append("\n\t\tProtected\t" + aPd.isProtected());
builder.append("\n\t\tMultiple\t" + aPd.isMultiple());
}
for (NodeDefinition aNd : nt.getChildNodeDefinitions()) {
builder.append("\n\tNodeDefinition");
builder.append(" (declared in " + aNd.getDeclaringNodeType() + ") ");
builder.append("\n\t\tName\t\t" + aNd.getName());
NodeType[] reqPrimaryTypes = aNd.getRequiredPrimaryTypes();
if (reqPrimaryTypes != null && reqPrimaryTypes.length > 0) {
for (NodeType reqPrimaryType : reqPrimaryTypes) {
builder.append("\n\t\tRequiredPrimaryType\t" + reqPrimaryType.getName());
}
}
NodeType defPrimaryType = aNd.getDefaultPrimaryType();
if (defPrimaryType != null) {
builder.append("\n\t\tDefaultPrimaryType\t" + defPrimaryType.getName());
}
builder.append("\n\t\tAutoCreated\t" + aNd.isAutoCreated());
builder.append("\n\t\tMandatory\t" + aNd.isMandatory());
builder.append("\n\t\tOnVersion\t" + OnParentVersionAction.nameFromValue(aNd.getOnParentVersion()));
builder.append("\n\t\tProtected\t" + aNd.isProtected());
builder.append("\n\t\tAllowsSameNameSiblings\t" + aNd.allowsSameNameSiblings());
}
}
} catch (RepositoryException e) {
builder.append(e.getMessage());
}
return builder.toString();
}
use of javax.jcr.nodetype.NodeDefinition in project jackrabbit-oak by apache.
the class RepositoryTest method testGetDefinitionWithSNS.
@Test
public void testGetDefinitionWithSNS() throws RepositoryException, IOException {
Session session = getAdminSession();
Node node = session.getNode("/jcr:system/jcr:nodeTypes/nt:file");
// TODO: use getNode("jcr:childNodeDefinition[1]") once that works
for (Node child : getChildNodes(node, "jcr:childNodeDefinition")) {
// OAK-829
NodeDefinition definition = child.getDefinition();
// OAK-826
definition.getDefaultPrimaryType();
// OAK-826
definition.getRequiredPrimaryTypes();
}
}
Aggregations