Search in sources :

Example 21 with NodeDefinition

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));
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) NodeType(javax.jcr.nodetype.NodeType) NodeDefinition(javax.jcr.nodetype.NodeDefinition)

Example 22 with NodeDefinition

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));
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) NodeType(javax.jcr.nodetype.NodeType) NodeDefinition(javax.jcr.nodetype.NodeDefinition) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator)

Example 23 with NodeDefinition

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));
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) NodeType(javax.jcr.nodetype.NodeType) NodeDefinition(javax.jcr.nodetype.NodeDefinition)

Example 24 with NodeDefinition

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();
}
Also used : NodeType(javax.jcr.nodetype.NodeType) Value(javax.jcr.Value) QNodeDefinition(org.apache.jackrabbit.spi.QNodeDefinition) NodeDefinition(javax.jcr.nodetype.NodeDefinition) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator) RepositoryException(javax.jcr.RepositoryException) QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition)

Example 25 with NodeDefinition

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();
    }
}
Also used : JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) NodeDefinition(javax.jcr.nodetype.NodeDefinition) Session(javax.jcr.Session) Test(org.junit.Test)

Aggregations

NodeDefinition (javax.jcr.nodetype.NodeDefinition)77 NodeType (javax.jcr.nodetype.NodeType)44 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)29 Node (javax.jcr.Node)17 ItemExistsException (javax.jcr.ItemExistsException)14 NodeTypeIterator (javax.jcr.nodetype.NodeTypeIterator)13 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)13 Version (javax.jcr.version.Version)12 Test (org.junit.Test)11 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)8 RepositoryException (javax.jcr.RepositoryException)7 HashSet (java.util.HashSet)5 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)5 Name (org.apache.jackrabbit.spi.Name)5 QNodeDefinition (org.apache.jackrabbit.spi.QNodeDefinition)5 NodeDefinitionImpl (org.apache.jackrabbit.spi.commons.nodetype.NodeDefinitionImpl)5 ArrayList (java.util.ArrayList)4 NodeState (org.apache.jackrabbit.core.state.NodeState)4 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)4 Session (javax.jcr.Session)3