Package org.jboss.dna.graph.property

Examples of org.jboss.dna.graph.property.Path

This class simplifies working with paths and using a Path is often more efficient that processing and manipulating the equivalent String. This class can easily {@link #iterator() iterate} over the segments, returnthe {@link #size() number of segments}, {@link #compareTo(Path) compare} with other paths, {@link #resolve(Path) resolve}relative paths, return the {@link #getParent() ancestor (or parent)}, determine whether one path is an {@link #isAncestorOf(Path) ancestor} or {@link #isDecendantOf(Path) decendent} of another path, and{@link #getCommonAncestor(Path) finding a common ancestor}.


        public T to( Path desiredPath ) {
            if (desiredPath.isRoot()) {
                throw new IllegalArgumentException(GraphI18n.unableToCopyToTheRoot.text(this.from, desiredPath));
            }
            Path parent = desiredPath.getParent();
            return submit(this.fromWorkspaceName, this.from, Location.create(parent), desiredPath.getLastSegment().getName());
        }
View Full Code Here


                }

                public Object evaluate( Object[] tuple ) {
                    Location location = (Location)tuple[locationIndex];
                    if (location == null) return null;
                    Path path = location.getPath();
                    assert path != null;
                    return new Long(path.size());
                }
            };
        }
        if (operand instanceof NodePath) {
            NodePath nodePath = (NodePath)operand;
            final int locationIndex = columns.getLocationIndex(nodePath.getSelectorName().getName());
            return new DynamicOperation() {
                public String getExpectedType() {
                    return stringFactory.getTypeName();
                }

                public Object evaluate( Object[] tuple ) {
                    Location location = (Location)tuple[locationIndex];
                    if (location == null) return null;
                    assert location.getPath() != null;
                    return stringFactory.create(location.getPath());
                }
            };
        }
        if (operand instanceof NodeName) {
            NodeName nodeName = (NodeName)operand;
            final int locationIndex = columns.getLocationIndex(nodeName.getSelectorName().getName());
            return new DynamicOperation() {
                public String getExpectedType() {
                    return stringFactory.getTypeName();
                }

                public Object evaluate( Object[] tuple ) {
                    Location location = (Location)tuple[locationIndex];
                    if (location == null) return null;
                    Path path = location.getPath();
                    assert path != null;
                    return path.isRoot() ? "" : stringFactory.create(location.getPath().getLastSegment().getName());
                }
            };
        }
        if (operand instanceof NodeLocalName) {
            NodeLocalName nodeName = (NodeLocalName)operand;
            final int locationIndex = columns.getLocationIndex(nodeName.getSelectorName().getName());
            return new DynamicOperation() {
                public String getExpectedType() {
                    return stringFactory.getTypeName();
                }

                public Object evaluate( Object[] tuple ) {
                    Location location = (Location)tuple[locationIndex];
                    if (location == null) return null;
                    Path path = location.getPath();
                    assert path != null;
                    return path.isRoot() ? "" : location.getPath().getLastSegment().getName().getLocalName();
                }
            };
        }
        if (operand instanceof FullTextSearchScore) {
            FullTextSearchScore score = (FullTextSearchScore)operand;
View Full Code Here

            if (left.getColumns().hasSelector(childSelectorName)) {
                // The child is on the left ...
                return new Joinable() {
                    public boolean evaluate( Object childLocation,
                                             Object parentLocation ) {
                        Path childPath = ((Location)childLocation).getPath();
                        Path parentPath = ((Location)parentLocation).getPath();
                        return childPath.getParent().isSameAs(parentPath);
                    }
                };
            }
            // The child is on the right ...
            return new Joinable() {
                public boolean evaluate( Object parentLocation,
                                         Object childLocation ) {
                    Path childPath = ((Location)childLocation).getPath();
                    Path parentPath = ((Location)parentLocation).getPath();
                    return childPath.getParent().isSameAs(parentPath);
                }
            };
        } else if (condition instanceof DescendantNodeJoinCondition) {
            DescendantNodeJoinCondition joinCondition = (DescendantNodeJoinCondition)condition;
            String ancestorSelectorName = joinCondition.getAncestorSelectorName().getName();
            if (left.getColumns().hasSelector(ancestorSelectorName)) {
                // The ancestor is on the left ...
                return new Joinable() {
                    public boolean evaluate( Object ancestorLocation,
                                             Object descendantLocation ) {
                        Path ancestorPath = ((Location)ancestorLocation).getPath();
                        Path descendantPath = ((Location)descendantLocation).getPath();
                        return ancestorPath.isAncestorOf(descendantPath);
                    }
                };
            }
            // The ancestor is on the right ...
            return new Joinable() {
                public boolean evaluate( Object descendantLocation,
                                         Object ancestorLocation ) {
                    Path ancestorPath = ((Location)ancestorLocation).getPath();
                    Path descendantPath = ((Location)descendantLocation).getPath();
                    return ancestorPath.isAncestorOf(descendantPath);
                }
            };
        }
        throw new IllegalArgumentException();
View Full Code Here

        final Comparator<Path> pathComparator = ValueComparators.PATH_COMPARATOR;
        if (condition instanceof SameNodeJoinCondition) {
            return new Comparator<Object>() {
                public int compare( Object location1,
                                    Object location2 ) {
                    Path path1 = ((Location)location1).getPath();
                    Path path2 = ((Location)location2).getPath();
                    return pathComparator.compare(path1, path2);
                }
            };
        }
        if (condition instanceof ChildNodeJoinCondition) {
            ChildNodeJoinCondition joinCondition = (ChildNodeJoinCondition)condition;
            String childSelectorName = joinCondition.getChildSelectorName().getName();
            if (left.getColumns().hasSelector(childSelectorName)) {
                // The child is on the left ...
                return new Comparator<Object>() {
                    public int compare( Object childLocation,
                                        Object parentLocation ) {
                        Path childPath = ((Location)childLocation).getPath();
                        Path parentPath = ((Location)parentLocation).getPath();
                        if (childPath.isRoot()) return parentPath.isRoot() ? 0 : -1;
                        Path parentOfChild = childPath.getParent();
                        return pathComparator.compare(parentPath, parentOfChild);
                    }
                };
            }
            // The child is on the right ...
            return new Comparator<Object>() {
                public int compare( Object parentLocation,
                                    Object childLocation ) {
                    Path childPath = ((Location)childLocation).getPath();
                    Path parentPath = ((Location)parentLocation).getPath();
                    if (childPath.isRoot()) return parentPath.isRoot() ? 0 : -1;
                    Path parentOfChild = childPath.getParent();
                    return pathComparator.compare(parentPath, parentOfChild);
                }
            };
        }
        if (condition instanceof EquiJoinCondition) {
View Full Code Here

            boolean first = true;
            for (Object value : this) {
                if (first) first = false;
                else sb.append(",");
                if (value instanceof Path) {
                    Path path = (Path)value;
                    sb.append(path.getString(namespaceRegistry, encoder, delimiterEncoder));
                } else if (value instanceof Name) {
                    Name name = (Name)value;
                    sb.append(name.getString(namespaceRegistry, encoder, delimiterEncoder));
                } else {
                    sb.append(value);
View Full Code Here

    @Override
    public void process( VerifyWorkspaceRequest request ) {
        PathWorkspace original = getWorkspace(request, request.workspaceName());
        if (original != null) {
            Path path = getExecutionContext().getValueFactories().getPathFactory().createRootPath();
            request.setActualRootLocation(Location.create(path, repository.getRootNodeUuid()));
            request.setActualWorkspaceName(original.getName());
        }
    }
View Full Code Here

        }

        WritablePathWorkspace newWorkspace = (WritablePathWorkspace)intoWorkspace;

        // Look up the new parent, which must exist ...
        Path newParentPath = request.into().getPath();
        PathNode newParent = newWorkspace.getNode(newParentPath);
        Set<Location> removedExistingNodes = new HashSet<Location>();
        Name desiredName = request.desiredName();
        PathNode newNode = newWorkspace.copyNode(getExecutionContext(), node, workspace, newParent, desiredName, true);
View Full Code Here

        }

        WritablePathWorkspace newWorkspace = (WritablePathWorkspace)intoWorkspace;

        // Look up the new parent, which must exist ...
        Path newParentPath = request.into().getPath();
        Name desiredName = request.desiredName();
        PathNode newParent = newWorkspace.getNode(newParentPath);
        PathNode newNode = newWorkspace.copyNode(getExecutionContext(), node, workspace, newParent, desiredName, true);
        Location oldLocation = Location.create(node.getPath(), node.getUuid());
        Location newLocation = Location.create(newNode.getPath(), newNode.getUuid());
View Full Code Here

    public void process( CreateNodeRequest request ) {
        if (!updatesAllowed(request)) return;

        PathWorkspace workspace = getWorkspace(request, request.inWorkspace());
        if (workspace == null) return;
        Path parent = request.under().getPath();
        CheckArg.isNotNull(parent, "request.under().getPath()");
        PathNode node = null;
        // Look up the parent node, which must exist ...

        PathNode parentNode = workspace.getNode(parent);
        if (parentNode == null) {
            Path lowestExisting = workspace.getLowestExistingPath(parent);
            request.setError(new PathNotFoundException(request.under(), lowestExisting, GraphI18n.nodeDoesNotExist.text(parent)));
            return;
        }

        if (!(workspace instanceof WritablePathWorkspace)) {
            I18n msg = GraphI18n.workspaceIsReadOnly;
            request.setError(new InvalidRequestException(msg.text(repository.getSourceName(), workspace.getName())));
            return;
        }

        WritablePathWorkspace newWorkspace = (WritablePathWorkspace)workspace;

        // Make a list of the properties that we will store: all props except dna:uuid and jcr:uuid
        Map<Name, Property> propsToStore = new HashMap<Name, Property>(request.properties().size());
        for (Property property : request.properties()) {
            if (property.size() > 0) propsToStore.put(property.getName(), property);
        }

        NodeConflictBehavior conflictBehavior = request.conflictBehavior();
        switch (conflictBehavior) {
            case APPEND:
                node = newWorkspace.createNode(getExecutionContext(), parentNode, request.named(), propsToStore, conflictBehavior);
                break;
            case DO_NOT_REPLACE:
                for (Segment childSegment : parentNode.getChildSegments()) {
                    if (request.named().equals(childSegment.getName())) {
                        Path childPath = pathFactory.create(parent, childSegment);
                        node = newWorkspace.getNode(childPath);
                        break;
                    }
                }
                if (node == null) {
View Full Code Here

        PathNode beforeNode = request.before() != null ? getTargetNode(workspace, request, request.before()) : null;
        PathNode node = getTargetNode(workspace, request, request.from());
        if (node == null) return;
        if (request.hasError()) return; // if beforeNode could not be found
        // Look up the new parent, which must exist ...
        Path newParentPath;

        if (request.into() != null) {
            newParentPath = request.into().getPath();
        } else {
            // into or before cannot both be null
            assert beforeNode != null;
            newParentPath = beforeNode.getPath().getParent();
        }

        PathNode newParent = workspace.getNode(newParentPath);
        if (newParent == null) {
            Path lowestExisting = workspace.getLowestExistingPath(newParentPath);
            request.setError(new PathNotFoundException(request.into(), lowestExisting,
                                                       GraphI18n.nodeDoesNotExist.text(newParentPath)));
            return;
        }
View Full Code Here

TOP

Related Classes of org.jboss.dna.graph.property.Path

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.