Package org.modeshape.jcr.cache

Examples of org.modeshape.jcr.cache.CachedNode


            // Verify that the prefix is not already used ...
            Name newPrefixName = nameForPrefix(newPrefix);
            ChildReference ref = childRefs.getChild(newPrefixName);
            if (ref != null) {
                // There's an existing node with the same prefix/name ...
                CachedNode existingNode = system.getNode(ref);
                String existingUri = strings.create(existingNode.getProperty(ModeShapeLexicon.URI, system).getFirstValue());
                if (newUri.equals(existingUri)) {
                    // The URI also matches, so nothing to do ...
                    continue;
                }
                // Otherwise, the prefix was bound to another URI, so this means we're taking an existing prefix already bound
                // to one URI and assigning it to another URI. Per the JavaDoc for javax.jcr.Namespace#register(String,String)
                // the old URI is to be unregistered -- meaning we should delete it ...
                namespaces.removeChild(system, ref.getKey());
                system.destroy(ref.getKey());
                continue;
            }

            // Look for an existing namespace node that uses the same URI ...
            NodeKey key = keyForNamespaceUri(newUri);
            CachedNode existingNode = system.getNode(key);
            if (existingNode != null) {
                // Get the prefix for the existing namespace node ...
                Segment segment = existingNode.getSegment(system);
                String existingPrefix = prefixFor(segment);
                if (GENERATED_NAMESPACE_NODE_NAME.equals(segment.getName()) || !existingPrefix.equals(newPrefix)) {
                    // The prefix but was not used elsewhere, so we know we can just change it ...
                    namespaces.renameChild(system, key, names.create(newPrefix));
                    removedPrefixes.add(existingPrefix);
View Full Code Here


    }

    public String readNamespacePrefix( String namespaceUri,
                                       boolean generateIfMissing ) {
        NodeKey key = keyForNamespaceUri(namespaceUri);
        CachedNode nsNode = system.getNode(key);
        if (nsNode != null) {
            // There's an existing node, so just read the prefix (e.g., the name) ...
            Segment segment = nsNode.getSegment(system);
            return prefixFor(segment);
        }
        if (!generateIfMissing) return null;

        // Create a new namespace node that uses this URI ...
View Full Code Here

    }

    protected boolean unregisterNamespace( String namespaceUri ) {
        MutableCachedNode namespaces = mutableNamespacesNode();
        NodeKey key = keyForNamespaceUri(namespaceUri);
        CachedNode nsNode = system.getNode(key);
        if (nsNode != null) {
            namespaces.removeChild(system, key);
            system.destroy(key);
            return true;
        }
View Full Code Here

     * @return true if the lock "held" status was successfully changed to the desired value, or false otherwise
     * @throws LockException if there is no such lock with the supplied token
     */
    boolean changeLockHeldBySession( String lockToken,
                                     boolean value ) throws LockException {
        CachedNode locksNode = locksNode();
        ChildReferences childRefs = locksNode.getChildReferences(system);
        Name name = names.create(lockToken);
        ChildReference ref = childRefs.getChild(name);
        if (ref == null) {
            throw new LockException(JcrI18n.invalidLockToken.text(lockToken));
        }
View Full Code Here

                                                          NodeKey originalVersionKey,
                                                          DateTime now ) {
        assert versionHistoryPath != null;
        assert versionHistoryPath.size() == 6;

        CachedNode node = versionStorageNode();
        MutableCachedNode mutable = null;

        // Find the parent of the version history node by walking the path and creating any missing intermediate folders ...
        Path parentPathInStorage = versionHistoryPath.getParent().subpath(2);
        Property primaryType = null;
        for (Segment segment : parentPathInStorage) {
            ChildReferences childRefs = node.getChildReferences(system);
            ChildReference ref = childRefs.getChild(segment);
            if (ref != null) {
                // Look up the child node ...
                node = system.getNode(ref);
            } else {
                // Create the intermediate node ...
                MutableCachedNode mutableNode = system.mutable(node.getKey());
                NodeKey key = systemKey().withRandomId();
                if (primaryType == null) {
                    primaryType = propertyFactory.create(JcrLexicon.PRIMARY_TYPE, ModeShapeLexicon.VERSION_HISTORY_FOLDER);
                }
                mutable = mutableNode.createChild(system, key, segment.getName(), primaryType);
                node = mutable;
            }
        }

        // See if the version history exists ...
        MutableCachedNode historyParent = mutable != null ? mutable : system.mutable(node.getKey());

        // Now create the version history node itself ...
        List<Property> historyProps = new ArrayList<Property>();
        historyProps.add(propertyFactory.create(JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.VERSION_HISTORY));
        historyProps.add(propertyFactory.create(JcrLexicon.VERSIONABLE_UUID, versionableNodeKey.getIdentifier()));
View Full Code Here

        // Now update the predecessor nodes to have the new version node be included as one of their successors ...
        Property successors = null;
        final Set<Reference> successorReferences = new HashSet<Reference>();
        for (Object value : predecessors) {
            NodeKey predecessorKey = ((NodeKeyReference)value).getNodeKey();
            CachedNode predecessor = system.getNode(predecessorKey);

            // Look up the 'jcr:successors' property on the predecessor ...
            successors = predecessor.getProperty(JcrLexicon.SUCCESSORS, system);
            if (successors != null) {
                // There were already successors, so we need to add our new version node the list ...
                successorReferences.clear();
                for (Object successorValue : successors) {
                    NodeKey successorKey = ((NodeKeyReference)successorValue).getNodeKey();
View Full Code Here

     * @return the next name
     */
    protected Name nextNameForVersionNode( Property predecessors,
                                           ChildReferences historyChildren ) {
        String proposedName = null;
        CachedNode versionNode = null;

        // Try to find the versions in the history that are considered predecessors ...
        if (predecessors != null) {
            for (Object predecessor : predecessors) {
                if (predecessor == null) continue;
                NodeKey key = ((NodeKeyReference)predecessor).getNodeKey();
                CachedNode predecessorNode = system.getNode(key);
                Name predecessorName = predecessorNode.getName(system);
                if (proposedName == null || predecessorName.getLocalName().length() < proposedName.length()) {
                    proposedName = predecessorName.getLocalName();
                    versionNode = predecessorNode;
                }
            }
View Full Code Here

        if (!acl.isEmpty()
            && !acl.hasPrivileges(securityContext(), new Privilege[] {privileges.forName(Privilege.JCR_READ_ACCESS_CONTROL)})) {
            throw new AccessDeniedException();
        }

        CachedNode node = session.cachedNode(session.pathFactory().create(absPath), false);
        if (node.hasACL(session.cache())) {
            // we only support 1 ACL per node; therefore if the node already has an ACL, we don't want to allow any additional
            // ones
            return AccessControlPolicyIteratorImpl.EMPTY;
        }
        // the node doesn't have an ACL yet, so return a new, empty ACL which can be used by clients to set privileges
View Full Code Here

                                             + policy.getClass().getSimpleName());
        }
        JcrAccessControlList acl = (JcrAccessControlList)policy;
        Map<String, Set<String>> privilegesByPrincipalName = privilegesByPrincipalName(acl);
        try {
            CachedNode cacheNode = session.cachedNode(session.pathFactory().create(absPath), false);
            SessionCache cache = session.cache();
            MutableCachedNode mutableNode = cache.mutable(cacheNode.getKey());
            MutableCachedNode.PermissionChanges permissionChanges = mutableNode.setPermissions(cache, privilegesByPrincipalName);
            session.aclAdded(permissionChanges.addedPrincipalsCount());
            session.aclRemoved(permissionChanges.removedPrincipalsCount());
        } catch (UnsupportedOperationException e) {
            throw new RepositoryException(e);
View Full Code Here

        if (!hasPrivileges(absPath, new Privilege[] {privileges.forName(Privilege.JCR_MODIFY_ACCESS_CONTROL)})) {
            throw new AccessDeniedException();
        }

        try {
            CachedNode cacheNode = session.cachedNode(session.pathFactory().create(absPath), false);
            SessionCache cache = session.cache();
            MutableCachedNode mutableNode = cache.mutable(cacheNode.getKey());
            MutableCachedNode.PermissionChanges permissionChanges = mutableNode.removeACL(cache);
            session.aclRemoved(permissionChanges.removedPrincipalsCount());
        } catch (UnsupportedOperationException e) {
            throw new RepositoryException(e);
        }
View Full Code Here

TOP

Related Classes of org.modeshape.jcr.cache.CachedNode

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.