Search in sources :

Example 76 with NodeDefinition

use of javax.jcr.nodetype.NodeDefinition in project sling by apache.

the class VltNodeTypeFactory method initAllowedPrimaryChildNodeTypes.

private void initAllowedPrimaryChildNodeTypes(VltNodeType nt0) throws RepositoryException {
    NodeDefinition[] declaredCihldNodeDefinitions = nt0.getDeclaredChildNodeDefinitions();
    Set<String> allowedChildNodeTypes = new HashSet<>();
    if (declaredCihldNodeDefinitions != null) {
        for (int i = 0; i < declaredCihldNodeDefinitions.length; i++) {
            NodeDefinition nodeDefinition = declaredCihldNodeDefinitions[i];
            NodeType[] requiredPrimaryTypes = nodeDefinition.getRequiredPrimaryTypes();
            if (requiredPrimaryTypes != null) {
                for (int j = 0; j < requiredPrimaryTypes.length; j++) {
                    VltNodeType aRequiredPrimaryType = (VltNodeType) requiredPrimaryTypes[j];
                    if (aRequiredPrimaryType == null) {
                        System.out.println("this can not be");
                    }
                    Set<VltNodeType> allKnownChildTypes = aRequiredPrimaryType.getAllKnownChildTypes();
                    for (Iterator<VltNodeType> it = allKnownChildTypes.iterator(); it.hasNext(); ) {
                        VltNodeType aChildType = it.next();
                        VltNodeType nt2 = getNodeType(aChildType.getName());
                        if (!nt2.isMixin()) {
                            // mixins cannot be primary node types!
                            allowedChildNodeTypes.add(nt2.getName());
                        }
                    }
                }
            }
        }
    }
    nt0.setAllowedPrimaryChildNodeTypes(allowedChildNodeTypes);
}
Also used : NodeType(javax.jcr.nodetype.NodeType) NodeDefinition(javax.jcr.nodetype.NodeDefinition) HashSet(java.util.HashSet)

Example 77 with NodeDefinition

use of javax.jcr.nodetype.NodeDefinition in project sling by apache.

the class VltNodeTypeFactory method initDeclaredFields.

private void initDeclaredFields(VltNodeType nt) {
    final ResourceProxy child = nt.getResourceProxy();
    String[] superTypeNamess = (String[]) child.getProperties().get("jcr:supertypes");
    nt.setDeclaredSupertypeNames(superTypeNamess);
    if (superTypeNamess != null) {
        NodeType[] superTypes = new NodeType[superTypeNamess.length];
        for (int i = 0; i < superTypeNamess.length; i++) {
            superTypes[i] = getNodeType(superTypeNamess[i]);
        }
        nt.setDeclaredSupertypes(superTypes);
    }
    Set<VltNodeDefinition> nds = new HashSet<>();
    for (ResourceProxy ntChild : child.getChildren()) {
        String ntChildName = PathUtil.getName(ntChild.getPath());
        if (ntChildName.startsWith("jcr:childNodeDefinition")) {
            VltNodeDefinition nd = handleChildNodeDefinition(ntChild);
            nds.add(nd);
        } else if (ntChildName.startsWith("rep:residualChildNodeDefinitions")) {
            // go through children
            for (ResourceProxy residualChild : ntChild.getChildren()) {
                nds.add(handleChildNodeDefinition(residualChild));
            }
        }
    }
    nt.setDeclaredChildNodeDefinitions(nds.toArray(new NodeDefinition[0]));
    initDeclaredPropertyDefinitions(nt, child);
}
Also used : NodeType(javax.jcr.nodetype.NodeType) NodeDefinition(javax.jcr.nodetype.NodeDefinition) ResourceProxy(org.apache.sling.ide.transport.ResourceProxy) HashSet(java.util.HashSet)

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