Package org.modeshape.jcr.value

Examples of org.modeshape.jcr.value.WorkspaceAndPath


        Set<WorkspaceAndPath> expectedWsAndPaths = new HashSet<WorkspaceAndPath>();
        for (int i = 0; i != workspaceNameAndPathPairs.length; ++i) {
            String workspaceName = workspaceNameAndPathPairs[i];
            String repoPath = workspaceNameAndPathPairs[++i];
            Path repPath = mappings.getPathFactory().create(repoPath);
            expectedWsAndPaths.add(new WorkspaceAndPath(workspaceName, repPath));
        }
        Collection<WorkspaceAndPath> wsAndPaths = mappings.resolveExternalPathToInternal(extPath);
        Set<WorkspaceAndPath> actualWsAndPaths = new HashSet<WorkspaceAndPath>(wsAndPaths);
        assertThat(actualWsAndPaths, is(expectedWsAndPaths));
    }
View Full Code Here


        assert numNew >= 1;
        assert numOld >= 1;

        // Check for the most common case (just one new location and one old location) and use a more optimal algorithm ...
        if (numNew == 1 && numOld == 1) {
            WorkspaceAndPath newWsAndPath = newWsAndPaths.iterator().next();
            WorkspaceAndPath oldWsAndPath = newWsAndPaths.iterator().next();
            String newWorkspace = newWsAndPath.getWorkspaceName();
            String oldWorkspace = oldWsAndPath.getWorkspaceName();
            if (newWorkspace.equals(oldWorkspace)) {
                // The workspaces are the same, so this is the case of a simple move
                changesFor(newWorkspace).nodeMoved(key, primaryType, mixinTypes, newParentKey, oldParentKey,
                                                   newWsAndPath.getPath(), oldWsAndPath.getPath(), queryable);
                return;
            }
            // The workspace names don't match, so treat the old as a NODE_REMOVED ...
            changesFor(oldWsAndPath.getWorkspaceName()).nodeRemoved(key, oldParentKey, oldWsAndPath.getPath(), primaryType,
                                                                    mixinTypes, queryable);
            // And the new as NODE_CREATED (in a separate workspace) ...
            // Note that we do not know the properties ...
            Map<Name, Property> properties = Collections.emptyMap();
            changesFor(newWsAndPath.getWorkspaceName()).nodeCreated(key, newParentKey, newWsAndPath.getPath(), primaryType,
                                                                    mixinTypes, properties, queryable);
            return;
        }

        assert numNew > 1 || numOld > 1;

        // Finally the general case. Here, we need to make sure that we don't lose any old locations that did not correspond
        // to at least new location. Since this is the last algorithm, we're actually going to remove all elements from
        // the 'oldWsAndPaths' collection as soon as we move them. (If multiple new locations map to a single old location,
        // then we'll have only one NODE_MOVED and one or more NODE_CREATED.)
        for (WorkspaceAndPath wsAndNewPath : newWsAndPaths) {
            // Look for the projections of the old external path in the same workspace ...
            boolean found = false;
            Iterator<WorkspaceAndPath> oldWsAndPathsIter = oldWsAndPaths.iterator();
            while (oldWsAndPathsIter.hasNext()) {
                WorkspaceAndPath wsAndOldPath = oldWsAndPathsIter.next();
                String newWorkspace = wsAndNewPath.getWorkspaceName();
                String oldWorkspace = wsAndOldPath.getWorkspaceName();
                if (newWorkspace.equals(oldWorkspace)) {
                    found = true;
                    changesFor(newWorkspace).nodeMoved(key, primaryType, mixinTypes, newParentKey, oldParentKey,
                                                       wsAndNewPath.getPath(), wsAndOldPath.getPath(), queryable);
                    oldWsAndPathsIter.remove(); // we don't want to deal with this WorkspaceAndPath as the 'from' of another move
                }
            }
            if (!found) {
                // The node appeared in one workspace, but it was moved from a node that projected into a different workspace,
View Full Code Here

        public Collection<WorkspaceAndPath> resolveExternalPathToInternal( Path externalPath ) {
            assert this.frozen;
            // Most repository configurations will project a single external node to a single path, so this
            // method is optimized for that case. We'll keep track of the first WorkspaceAndPath instance and
            // only if at least one more is created will this method instantiate a List instance ...
            WorkspaceAndPath first = null;
            Collection<WorkspaceAndPath> results = null;
            for (PathMapping mapping : mappings) {
                WorkspaceAndPath resolved = mapping.resolveExternalPathToInternal(externalPath, pathFactory);
                if (resolved != null) {
                    if (first == null) {
                        first = resolved;
                    } else {
                        if (results == null) {
View Full Code Here

        protected PathMapping( Path externalPath,
                               Path internalPath,
                               String workspaceName ) {
            this.externalPath = externalPath;
            this.internalPath = new WorkspaceAndPath(workspaceName, internalPath);
            this.hc = HashCode.compute(this.externalPath, this.internalPath);
            assert this.externalPath != null;
        }
View Full Code Here

TOP

Related Classes of org.modeshape.jcr.value.WorkspaceAndPath

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.