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}.


                this.properties = cache.NO_PROPERTIES;
                return;
            }

            // Check authorization before reading ...
            Path path = getPath();
            cache.authorizer.checkPermissions(path, Action.READ);
            int depth = cache.getDepthForLoadingNodes();
            if (depth == 1) {
                // Then read the node from the store ...
                org.jboss.dna.graph.Node persistentNode = cache.store.getNodeAt(getLocation());
                // Check the actual location ...
                Location actualLocation = persistentNode.getLocation();
                if (!this.location.isSame(actualLocation)) {
                    // The actual location is changed, so update it ...
                    this.location = actualLocation;
                }
                // Update the persistent information ...
                cache.nodeOperations.materialize(persistentNode, this);
            } else {
                // Then read the node from the store ...
                Subgraph subgraph = cache.store.getSubgraphOfDepth(depth).at(getLocation());
                Location actualLocation = subgraph.getLocation();
                if (!this.location.isSame(actualLocation)) {
                    // The actual location is changed, so update it ...
                    this.location = actualLocation;
                }
                // Update the persistent information ...
                cache.nodeOperations.materialize(subgraph.getRoot(), this);
                // Now update any nodes below this node ...
                for (org.jboss.dna.graph.Node persistentNode : subgraph) {
                    // Find the node at the path ...
                    Path relativePath = persistentNode.getLocation().getPath().relativeTo(path);
                    Node<Payload, PropertyPayload> node = cache.findNodeRelativeTo(this, relativePath);
                    if (!node.isLoaded()) {
                        // Update the persistent information ...
                        cache.nodeOperations.materialize(persistentNode, node);
                    }
View Full Code Here


         *
         * @param segment the path segment for this node; may be null only when this node is the root node
         */
        protected void updateLocation( Path.Segment segment ) {
            assert !isStale();
            Path newPath = null;
            Path currentPath = getPath();
            if (segment != null) {
                if (segment.equals(currentPath.getLastSegment())) return;
                // Recompute the path based upon the parent path ...
                Path parentPath = getParent().getPath();
                newPath = cache.pathFactory.create(parentPath, segment);
            } else {
                if (this.isRoot()) return;
                // This must be the root ...
                newPath = cache.pathFactory.createRootPath();
View Full Code Here

         *
         * @param newChild the new child that was added
         */
        protected void synchronizeWithNewlyPersistedNode( Location newChild ) {
            if (!this.isLoaded()) return;
            Path childPath = newChild.getPath();
            Name childName = childPath.getLastSegment().getName();
            if (this.childrenByName.isEmpty()) {
                // Just have to add the child ...
                this.childrenByName = LinkedListMultimap.create();
                if (childPath.getLastSegment().hasIndex()) {
                    // The child has a SNS index, but this is an only child ...
                    newChild = newChild.with(cache.pathFactory.create(childPath.getParent(), childName));
                }
                Node<Payload, PropertyPayload> child = cache.createNode(this, cache.idFactory.create(), newChild);
                this.childrenByName.put(childName, child);
                return;
            }
View Full Code Here

     * {@inheritDoc}
     */
    public Path getCommonAncestor( Path that ) {
        CheckArg.isNotNull(that, "that");
        if (that.isRoot()) return that;
        Path normalizedPath = this.getNormalizedPath();
        int lastIndex = 0;
        Iterator<Segment> thisIter = normalizedPath.iterator();
        Iterator<Segment> thatIter = that.getNormalizedPath().iterator();
        while (thisIter.hasNext() && thatIter.hasNext()) {
            Segment thisSeg = thisIter.next();
            Segment thatSeg = thatIter.next();
            if (thisSeg.equals(thatSeg)) {
                ++lastIndex;
            } else {
                break;
            }
        }
        if (lastIndex == 0) return RootPath.INSTANCE;
        return normalizedPath.subpath(0, lastIndex);
    }
View Full Code Here

     *
     * @see org.jboss.dna.graph.property.Path#pathsFromRoot()
     */
    public Iterator<Path> pathsFromRoot() {
        LinkedList<Path> paths = new LinkedList<Path>();
        Path path = this;
        while (path != null) {
            paths.addFirst(path);
            if (path.isRoot()) break;
            path = path.getParent();
        }
        return paths.iterator();
    }
View Full Code Here

     */
    @Override
    public boolean equals( Object obj ) {
        if (obj == this) return true;
        if (obj instanceof Path) {
            Path that = (Path)obj;
            // First check whether the paths are roots ...
            if (this.isRoot()) return that.isRoot();
            else if (that.isRoot()) return false;
            // Now check the hash code and size ...
            if (this.hashCode() != that.hashCode()) return false;
            if (this.size() != that.size()) return false;
            // Check the last segments, since these will often differ anyway ...
            if (!this.getLastSegment().equals(that.getLastSegment())) return false;
            if (this.size() == 1) return true;
            // Check the rest of the names ...
            Iterator<Segment> thisIter = that instanceof AbstractPath ? this.getSegmentsOfParent() : this.iterator();
            Iterator<Segment> thatIter = that instanceof AbstractPath ? ((AbstractPath)that).getSegmentsOfParent() : that.iterator();
            while (thisIter.hasNext()) {
                Segment thisSegment = thisIter.next();
                Segment thatSegment = thatIter.next();
                if (!thisSegment.equals(thatSegment)) return false;
            }
View Full Code Here

                                                              Collection<Property> idProperties,
                                                              Property[] remainingProperties ) throws ValidationException {
            assert !isStale();

            // Check permission here ...
            Path path = getPath();
            cache.authorizer.checkPermissions(path, Action.ADD_NODE);

            // Now load if required ...
            load();

            // Figure out the name and SNS of the new copy ...
            List<Node<Payload, PropertyPayload>> currentChildren = childrenByName.get(name);
            Path newPath = cache.pathFactory.create(path, name, currentChildren.size() + 1);
            Location newChild = idProperties != null && !idProperties.isEmpty() ? Location.create(newPath, idProperties) : Location.create(newPath);

            // Create the properties ...
            Map<Name, PropertyInfo<PropertyPayload>> newProperties = new HashMap<Name, PropertyInfo<PropertyPayload>>();
            if (idProperties != null) {
                for (Property idProp : idProperties) {
                    PropertyInfo<PropertyPayload> info = new PropertyInfo<PropertyPayload>(idProp, idProp.isMultiple(),
                                                                                           Status.NEW, null);
                    newProperties.put(info.getName(), info);
                }
            }
            if (remainingProperties != null) {
                for (Property property : remainingProperties) {
                    PropertyInfo<PropertyPayload> info2 = new PropertyInfo<PropertyPayload>(property, property.isMultiple(),
                                                                                            Status.NEW, null);
                    newProperties.put(info2.getName(), info2);
                }
            }

            // Notify before the addition ...
            cache.nodeOperations.preCreateChild(this, newPath.getLastSegment(), newProperties);

            // Record the current state before any changes ...
            Status statusBefore = this.status;
            boolean changedBelowBefore = this.changedBelow;
View Full Code Here

            load();
            List<Node<Payload, PropertyPayload>> children = childrenByName.get(name); // never null
            try {
                return children.get(sns - 1); // SNS is 1-based, index is 0-based
            } catch (IndexOutOfBoundsException e) {
                Path missingPath = cache.pathFactory.create(getPath(), name, sns);
                throw new PathNotFoundException(Location.create(missingPath), getPath());
            }
        }
View Full Code Here

            // if both have same path they are equal
            if (requireSameNameSiblingIndexes) {
                if (this.hasPath() && that.hasPath()) return (this.getPath().equals(that.getPath()));
            } else {
                Path thisPath = this.getPath();
                Path thatPath = that.getPath();
                if (thisPath.isRoot()) return thatPath.isRoot();
                if (thatPath.isRoot()) return thisPath.isRoot();
                // The parents must match ...
                if (!thisPath.hasSameAncestor(thatPath)) return false;
                // And the names of the last segments must match ...
                if (!thisPath.getLastSegment().getName().equals(thatPath.getLastSegment().getName())) return false;
            }

            // one or both is/are missing path so check properties instead
            if (this.hasIdProperties()) return (this.getIdProperties().equals(that.getIdProperties()));
        }
View Full Code Here

        public T to( Location desiredLocation ) {
            if (!desiredLocation.hasPath()) {
                throw new IllegalArgumentException(GraphI18n.unableToCopyToLocationWithoutAPath.text(this.from, desiredLocation));
            }
            Path desiredPath = desiredLocation.getPath();
            if (desiredPath.isRoot()) {
                throw new IllegalArgumentException(GraphI18n.unableToCopyToTheRoot.text(this.from, desiredLocation));
            }
            Path parent = desiredPath.getParent();
            return submit(this.fromWorkspaceName, this.from, Location.create(parent), desiredPath.getLastSegment().getName());
        }
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.