Package org.modeshape.jcr.value.Path

Examples of org.modeshape.jcr.value.Path.Segment


    final AbstractJcrItem findItem( AbstractJcrNode node,
                                    Path relativePath ) throws RepositoryException {
        assert !relativePath.isAbsolute();
        if (relativePath.size() == 1) {
            Segment last = relativePath.getLastSegment();
            if (last.isSelfReference()) return node;
            if (last.isParentReference()) return node.getParent();
        }
        // Find the path to the referenced node ...
        Path nodePath = node.path();
        Path absolutePath = nodePath.resolve(relativePath);
        if (absolutePath.isAtOrBelow(nodePath)) {
View Full Code Here


        }
        if (path.isIdentifier()) {
            throw new PathNotFoundException(JcrI18n.identifierPathNeverReferencesProperty.text());
        }

        Segment lastSegment = path.getLastSegment();
        if (lastSegment.hasIndex()) {
            throw new RepositoryException(JcrI18n.pathCannotHaveSameNameSiblingIndex.text(absPath));
        }

        // This will throw a PNFE if the parent path does not exist
        AbstractJcrNode parentNode = node(path.getParent());
        AbstractJcrProperty property = parentNode.getProperty(lastSegment.getName());

        if (property == null) {
            throw new PathNotFoundException(GraphI18n.pathNotFoundExceptionLowestExistingLocationFound.text(absPath,
                                                                                                            parentNode.getPath()));
        }
View Full Code Here

            // These are not properties ...
            return false;
        }

        // There is at least one segment ...
        Segment lastSegment = path.getLastSegment();
        if (lastSegment.hasIndex()) {
            throw new RepositoryException(JcrI18n.pathCannotHaveSameNameSiblingIndex.text(absPath));
        }

        try {
            // This will throw a PNFE if the parent path does not exist
            CachedNode parentNode = cachedNode(path.getParent(), true);
            return parentNode != null && parentNode.hasProperty(lastSegment.getName(), cache());
        } catch (PathNotFoundException e) {
            return false;
        }
    }
View Full Code Here

            // 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);
                }
            } else if (newUri.length() > 0) {
View Full Code Here

                                       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

    @Override
    public String create( Path value ) {
        if (value == null) return null;
        if (value.isIdentifier()) {
            // Get the identifier segment ...
            Segment segment = value.getLastSegment();
            assert segment.isIdentifier();
            try {
                // The local part of the segment's name should be the identifier ...
                return segment.getString(getEncoder());
            } catch (IllegalArgumentException err) {
                throw new ValueFormatException(value, PropertyType.STRING,
                                               GraphI18n.unableToCreateValue.text(getPropertyType().getName(),
                                                                                  Path.class.getSimpleName(),
                                                                                  value));
View Full Code Here

            for (String childSegment : childSegments) {
                segments.add(segment(childSegment));
            }
            Iterator<Segment> expectedIter = segments.iterator();
            for (ChildReference childRef : node.getChildReferences(cache)) {
                Segment actual = childRef.getSegment();
                if (!expectedIter.hasNext()) {
                    fail("Found child \"" + string(actual) + "\" but expected no more children");
                }
                Segment expected = expectedIter.next();
                if (!actual.equals(expected)) {
                    Path path = node.getPath(cache);
                    String msg = "Expected \"" + string(expected) + "\" but found \"" + string(actual) + "\" in children of \""
                                 + string(path) + "\"";
                    assertThat(msg, actual, is(expected));
View Full Code Here

        while (actualIter.hasNext()) {
            ChildReference childRef = workspaceCache.translator().childReferenceFrom(actualIter.next());
            if (!expectedIter.hasNext()) {
                fail("Found \"" + childRef + "\" but not expecting any children");
            }
            Segment expectedName = expectedIter.next();
            assertThat("Expecting child \"" + expectedName + "\" but found \"" + childRef.toString() + "\"",
                       childRef.getSegment(), is(expectedName));
        }
        if (expectedIter.hasNext()) {
            fail("Expected \"" + expectedIter.next() + "\" but found no such child");
View Full Code Here

    public Iterable<Path> getPaths( CachedNode node ) {
        NodeKey key = node.getKey();
        List<Path> pathList = paths.get(key);
        if (pathList == null) {
            // Compute the node's path ...
            Segment nodeSegment = node.getSegment(cache);
            NodeKey parentKey = node.getParentKey(cache);
            if (parentKey == null) {
                // This is the root node ...
                pathList = Collections.singletonList(node.getPath(cache));
            } else {
View Full Code Here

    }

    protected List<Segment> segmentsFrom( List<?> segmentValues ) {
        List<Segment> segments = new ArrayList<Segment>(segmentValues.size());
        for (Object value : segmentValues) {
            Segment segment = paths.createSegment(value.toString(), decoder);
            segments.add(segment);
        }
        return segments;
    }
View Full Code Here

TOP

Related Classes of org.modeshape.jcr.value.Path.Segment

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.