Package javax.jcr.nodetype

Examples of javax.jcr.nodetype.NodeDefinition


     * child node.
     */
    public void testRemovableChildNode()
            throws NotExecutableException, RepositoryException {

        NodeDefinition nodeDef =
                NodeTypeUtil.locateChildNodeDef(session, false, false);

        if (nodeDef == null) {
            throw new NotExecutableException("No mandatory property def found.");
        }

        NodeType type = nodeDef.getDeclaringNodeType();

        assertTrue("NodeType.canRemoveIten(String itemName) must return true " +
                "if itemName is nor a protected nor a mandatory child node def.",
                type.canRemoveItem(nodeDef.getName()));
    }
View Full Code Here


     * false if <code>itemName</code> is a protected child node.
     */
    public void testProtectedChildNode()
            throws NotExecutableException, RepositoryException {

        NodeDefinition nodeDef =
                NodeTypeUtil.locateChildNodeDef(session, true, false);

        if (nodeDef == null) {
            throw new NotExecutableException("No mandatory property def found.");
        }

        NodeType type = nodeDef.getDeclaringNodeType();

        assertFalse("NodeType.canRemoveIten(String itemName) must return false " +
                "if itemName is a protected child node def.",
                type.canRemoveItem(nodeDef.getName()));
    }
View Full Code Here

     * false if <code>itemName</code> is a mandatory child node.
     */
    public void testMandatoryChildNode()
            throws NotExecutableException, RepositoryException {

        NodeDefinition nodeDef =
                NodeTypeUtil.locateChildNodeDef(session, true, false);

        if (nodeDef == null) {
            throw new NotExecutableException("No mandatory property def found.");
        }

        NodeType type = nodeDef.getDeclaringNodeType();

        assertFalse("NodeType.canRemoveIten(String itemName) must return false " +
                "if itemName is a mandatory child node def.",
                type.canRemoveItem(nodeDef.getName()));
    }
View Full Code Here

        NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
        NodeTypeIterator types = manager.getAllNodeTypes();

        while (types.hasNext()) {
            NodeType type = types.nextNodeType();
            NodeDefinition nodeDefs[] = type.getDeclaredChildNodeDefinitions();

            for (int i = 0; i < nodeDefs.length; i++) {
                NodeDefinition nodeDef = nodeDefs[i];

                if (nodeDef.getName().equals("*")) {
                    continue;
                }

                if (isProtected && !nodeDef.isProtected()) {
                    continue;
                }
                if (!isProtected && nodeDef.isProtected()) {
                    continue;
                }

                if (mandatory && !nodeDef.isMandatory()) {
                    continue;
                }
                if (!mandatory && nodeDef.isMandatory()) {
                    continue;
                }

                return nodeDef;
            }
View Full Code Here

    /**
     * Returns a name that is not defined by the nodeType's child node def
     */
    public static String getUndefinedChildNodeName(NodeType nodeType) {

        NodeDefinition nodeDefs[] = nodeType.getChildNodeDefinitions();
        StringBuffer s = new StringBuffer("X");

        for (int i = 0; i < nodeDefs.length; i++) {
            s.append(nodeDefs[i].getName());
        }
View Full Code Here

                pnImporter.startChildInfo(nodeInfo, propInfos);
            }
            return;
        }

        NodeDefinition parentDef = getDefinition(parent);
        if (parentDef.isProtected()) {
            // skip protected node
            parents.push(null);
            log.debug("Skipping protected node: " + nodeName);

            if (pnImporter != null) {
                // pnImporter was already started (current nodeInfo is a sibling)
                // notify it about this child node.
                pnImporter.startChildInfo(nodeInfo, propInfos);
            } else {
                // no importer defined yet:
                // test if there is a ProtectedNodeImporter among the configured
                // importers that can handle this.
                // if there is one, notify the ProtectedNodeImporter about the
                // start of a item tree that is protected by this parent. If it
                // potentially is able to deal with it, notify it about the child node.
                for (ProtectedItemImporter pni : pItemImporters) {
                    if (pni instanceof ProtectedNodeImporter && ((ProtectedNodeImporter) pni).start(parent)) {
                        log.debug("Protected node -> delegated to ProtectedNodeImporter");
                        pnImporter = (ProtectedNodeImporter) pni;
                        pnImporter.startChildInfo(nodeInfo, propInfos);
                        break;
                    } /* else: p-i-Importer isn't able to deal with the protected tree.
                     try next. and if none can handle the passed parent the
                     tree below will be skipped */
                }
            }
            return;
        }

        if (parent.hasChild(nodeName)) {
            // a node with that name already exists...
            Tree existing = parent.getChild(nodeName);
            NodeDefinition def = getDefinition(existing);
            if (!def.allowsSameNameSiblings()) {
                // existing doesn't allow same-name siblings,
                // check for potential conflicts
                if (def.isProtected() && isNodeType(existing, ntName)) {
                    /*
                     use the existing node as parent for the possible subsequent
                     import of a protected tree, that the protected node importer
                     may or may not be able to deal with.
                     -> upon the next 'startNode' the check for the parent being
                        protected will notify the protected node importer.
                     -> if the importer is able to deal with that node it needs
                        to care of the complete subtree until it is notified
                        during the 'endNode' call.
                     -> if the import can't deal with that node or if that node
                        is the a leaf in the tree to be imported 'end' will
                        not have an effect on the importer, that was never started.
                    */
                    log.debug("Skipping protected node: " + existing);
                    parents.push(existing);
                    return;
                }
                if (def.isAutoCreated() && isNodeType(existing, ntName)) {
                    // this node has already been auto-created, no need to create it
                    tree = existing;
                } else {
                    // edge case: colliding node does have same uuid
                    // (see http://issues.apache.org/jira/browse/JCR-1128)
                    String existingIdentifier = IdentifierManager.getIdentifier(existing);
                    if (!(existingIdentifier.equals(id)
                            && (uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING
                            || uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING))) {
                        throw new ItemExistsException(
                                "Node with the same UUID exists:" + existing);
                    }
                    // fall through
                }
            }
        }

        if (tree == null) {
            // create node
            if (id == null) {
                // no potential uuid conflict, always add new node
                tree = createTree(parent, nodeInfo, id);
            } else {

                //1. First check from base state that tree corresponding to
                //this id exist
                Tree conflicting = baseStateIdManager.getTree(id);

                if(conflicting == null){
                    //1.a. Check if id is found in newly created nodes
                    if(uuids.contains(id)){
                        conflicting = currentStateIdManager.getTree(id);
                    }
                }else{
                    //1.b Re obtain the conflicting tree from Id Manager
                    //associated with current root. Such that any operation
                    //on it gets reflected in later operations
                    //In case a tree with same id was removed earlier then it
                    //would return null
                    conflicting = currentStateIdManager.getTree(id);
                }

                // resolve conflict if there is one or force
                // conflict resolution when behavior is IMPORT_UUID_CREATE_NEW.
                // the latter will always create a new UUID even if no
                // conflicting node exists. see OAK-1244
                if ((conflicting != null && conflicting.exists())
                        || uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW) {
                    // resolve uuid conflict
                    tree = resolveUUIDConflict(parent, conflicting, id, nodeInfo);
                    if (tree == null) {
                        // no new node has been created, so skip this node
                        parents.push(null); // push null onto stack for skipped node
                        log.debug("Skipping existing node " + nodeInfo.getName());
                        return;
                    }
                } else {
                    // create new with given uuid
                    tree = createTree(parent, nodeInfo, id);
                }
            }
        }

        // process properties
        for (PropInfo pi : propInfos) {
            // find applicable definition
            //TODO find better heuristics?
            PropertyDefinition def = pi.getPropertyDef(effectiveNodeTypeProvider.getEffectiveNodeType(tree));

            if (def.isProtected()) {
                // skip protected property
                log.debug("Skipping protected property " + pi.getName());

                // notify the ProtectedPropertyImporter.
                for (ProtectedItemImporter ppi : pItemImporters) {
View Full Code Here

     * @throws Exception on errors
     */
    public void testNodeDef() throws Exception {
        prepareTests(NodeDefinition.class);

        NodeDefinition def = (NodeDefinition) mock;
        RemoteNodeDefinition remote = remoteFactory.getRemoteNodeDefinition(def);
        NodeDefinition local = localFactory.getNodeDef(remote);

        runTests(local);
    }
View Full Code Here

        paths.add(testRoot + "/b");
        paths.add("/oak:index");

        for (String path : paths) {
            Node n = superuser.getNode(path);
            NodeDefinition def = n.getDefinition();
            def.getRequiredPrimaryTypes();
        }
    }
View Full Code Here

        }

        if (parent.hasNode(nodeName)) {
            // a node with that name already exists...
            Node existing = parent.getNode(nodeName);
            NodeDefinition def = existing.getDefinition();
            if (!def.allowsSameNameSiblings()) {
                // existing doesn't allow same-name siblings,
                // check for potential conflicts
                if (def.isProtected() && existing.isNodeType(ntName)) {
                    /*
                     use the existing node as parent for the possible subsequent
                     import of a protected tree, that the protected node importer
                     may or may not be able to deal with.
                     -> upon the next 'startNode' the check for the parent being
                        protected will notify the protected node importer.
                     -> if the importer is able to deal with that node it needs
                        to care of the complete subtree until it is notified
                        during the 'endNode' call.
                     -> if the import can't deal with that node or if that node
                        is the a leaf in the tree to be imported 'end' will
                        not have an effect on the importer, that was never started.
                    */
                    log.debug("Skipping protected node: " + existing);
                    parents.push(existing);
                    return;
                }
                if (def.isAutoCreated() && existing.isNodeType(ntName)) {
                    // this node has already been auto-created, no need to create it
                    node = existing;
                } else {
                    // edge case: colliding node does have same uuid
                    // (see http://issues.apache.org/jira/browse/JCR-1128)
                    if (!(existing.getIdentifier().equals(id)
                            && (uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING
                            || uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING))) {
                        throw new ItemExistsException(
                                "Node with the same UUID exists:" + existing);
                    }
                    // fall through
                }
            }
        }

        if (node == null) {
            // create node
            if (id == null) {
                // no potential uuid conflict, always add new node
                node = createNode(parent, nodeName, ntName, mixins, id);
            } else {
                // potential uuid conflict
                boolean isConflicting;
                try {
                    // the following is a fail-fast test whether
                    // an item exists (regardless of access control)
                    session.getNodeByIdentifier(id);
                    isConflicting = true;
                } catch (ItemNotFoundException e) {
                    isConflicting = false;
                } catch (RepositoryException e) {
                    log.warn("Access Control Issues?", e);
                    isConflicting = true;
                }

                if (isConflicting) {
                    // resolve uuid conflict
                    node = resolveUUIDConflict(parent, id, nodeInfo);
                    if (node == null) {
                        // no new node has been created, so skip this node
                        parents.push(null); // push null onto stack for skipped node
                        log.debug("Skipping existing node " + nodeInfo.getName());
                        return;
                    }
                } else {
                    // create new with given uuid
                    node = createNode(parent, nodeName, ntName, mixins, id);
                }
            }
        }

        // process properties

        //TODO remove hack that processes principal name first
        int principalNameIndex = -1;
        for (int k = 0; k < propInfos.size(); k++) {
            PropInfo propInfo = propInfos.get(k);
            if ("rep:principalName".equals(propInfo.getName())) {
                principalNameIndex = k;
                break;
            }
        }
        if (principalNameIndex >= 0) {
            propInfos.add(0, propInfos.remove(principalNameIndex));
        }
        for (PropInfo pi : propInfos) {
            // find applicable definition
            //TODO find a proper way to get the EffectiveNodeTypeProvider
            NodeTypeManager nodeTypeManager = session.getWorkspace().getNodeTypeManager();
            if (nodeTypeManager instanceof EffectiveNodeTypeProvider) {
                EffectiveNodeTypeProvider entp = (EffectiveNodeTypeProvider) nodeTypeManager;

                //TODO find better heuristics?
                PropertyDefinition def = pi.getPropertyDef(entp.getEffectiveNodeType(node));
                if (def.isProtected()) {
                    // skip protected property
                    log.debug("Skipping protected property " + pi.getName());

                    // notify the ProtectedPropertyImporter.
                    for (ProtectedItemImporter ppi : pItemImporters) {
View Full Code Here

    public NodeDefinition getDefinition() throws RepositoryException {
        checkStatus();


        // TODO
        return new NodeDefinition() {
            // This is a workaround to make AbstractJCRTest.cleanup happy
           
            @Override
            public boolean isProtected() {
View Full Code Here

TOP

Related Classes of javax.jcr.nodetype.NodeDefinition

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.