/** * {@inheritDoc} * * @see org.modeshape.graph.property.PathFactory#createRelativePath(java.lang.Iterable) */ public Path createRelativePath( Iterable<Segment> segments ) { List<Segment> segmentsList = new LinkedList<Segment>(); for (Segment segment : segments) { if (segment == null) { CheckArg.containsNoNulls(segments, "segments"); } assert segment != null; if (segment.isIdentifier()) { throw new InvalidPathException( GraphI18n.unableToCreateRelativePathWithIdentifierSegment.text(segments.toString())); } segmentsList.add(segment); } if (segmentsList.isEmpty()) return BasicPath.EMPTY_RELATIVE; return new BasicPath(segmentsList, false); }
/** * {@inheritDoc} * * @see org.modeshape.graph.property.PathFactory#create(org.modeshape.graph.property.Path, java.lang.Iterable) */ public Path create( Path parentPath, Iterable<Segment> segments ) { CheckArg.isNotNull(parentPath, "parent path"); if (parentPath.isIdentifier()) { throw new InvalidPathException(GraphI18n.unableToCreatePathBasedUponIdentifierPath.text(parentPath, segments.toString())); } List<Segment> segmentsList = new LinkedList<Segment>(); segmentsList.addAll(parentPath.getSegmentsList()); for (Segment segment : segments) { if (segment == null) { CheckArg.containsNoNulls(segments, "segments"); } assert segment != null; if (segment.isIdentifier()) { throw new InvalidPathException( GraphI18n.unableToCreatePathUsingIdentifierPathAndAnotherPath.text(parentPath, segments.toString())); } segmentsList.add(segment); } if (segmentsList.isEmpty()) return RootPath.INSTANCE; if (segmentsList.size() == 0) return new ChildPath(parentPath, segmentsList.get(0)); return new BasicPath(segmentsList, parentPath.isAbsolute()); }
/** * {@inheritDoc} */ public Path createRelativePath( Segment... segments ) { if (segments == null || segments.length == 0) return BasicPath.EMPTY_RELATIVE; List<Segment> segmentsList = new ArrayList<Segment>(segments.length); for (Segment segment : segments) { if (segment == null) { CheckArg.containsNoNulls(segments, "segments"); } assert segment != null; if (segment.isIdentifier()) { throw new InvalidPathException( GraphI18n.unableToCreateRelativePathWithIdentifierSegment.text(segments.toString())); } segmentsList.add(segment); } return new BasicPath(segmentsList, false); }
segments.toString())); if (segments[0].isIdentifier()) { throw new InvalidPathException( GraphI18n.unableToCreatePathUsingIdentifierPathAndAnotherPath.text(parentPath, if (segment.isIdentifier()) { throw new InvalidPathException( GraphI18n.unableToCreatePathUsingIdentifierPathAndAnotherPath.text(parentPath,
try { Path.Segment childSegment = createSegment(subpath); if (childSegment.isIdentifier()) { throw new InvalidPathException(GraphI18n.unableToCreatePathUsingIdentifierPathAndAnotherPath.text(parentPath, subpath));
/** * {@inheritDoc} */ public UUID create( Path value ) { 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, though it may not be a UUID ... String id = segment.getName().getLocalName(); return UUID.fromString(id); } catch (IllegalArgumentException err) { throw new ValueFormatException(value, PropertyType.UUID, GraphI18n.unableToCreateValue.text(getPropertyType().getName(), Path.class.getSimpleName(), value)); } } throw new ValueFormatException(value, PropertyType.UUID, GraphI18n.unableToCreateValue.text(getPropertyType().getName(), Path.class.getSimpleName(), value)); }
/** * {@inheritDoc} */ public UUID create( Path.Segment value ) { if (value.isIdentifier()) { try { // The local part of the segment's name should be the identifier, though it may not be a UUID ... String id = value.getName().getLocalName(); return UUID.fromString(id); } catch (IllegalArgumentException err) { throw new ValueFormatException(value, PropertyType.UUID, GraphI18n.unableToCreateValue.text(getPropertyType().getName(), Path.Segment.class.getSimpleName(), value)); } } throw new ValueFormatException(value, PropertyType.UUID, GraphI18n.unableToCreateValue.text(getPropertyType().getName(), Path.Segment.class.getSimpleName(), value)); }
protected static UUID identifierFor( Path identifierPath ) { if (!identifierPath.isIdentifier()) return null; // Get the identifier segment ... Segment segment = identifierPath.getLastSegment(); assert segment.isIdentifier(); String id = segment.getName().getLocalName(); try { // The local part of the segment's name should be the identifier, though it may not be a UUID ... return UUID.fromString(id); } catch (IllegalArgumentException err) { String pathStr = "[" + id + "]"; throw new IllegalArgumentException(GraphI18n.identifierPathContainedUnsupportedIdentifierFormat.text(pathStr)); } }
@Test public void shouldParsePathFromStringWithoutRootSegmentAndIdentifierSegment() { path = paths.create("[f81d4fae-7dec-11d0-a765-00a0c91e6bf6]"); assertThat(path.isAbsolute(), is(true)); assertThat(path.isIdentifier(), is(true)); assertThat(path.size(), is(1)); assertThat(path.getSegment(0), is(segment("[f81d4fae-7dec-11d0-a765-00a0c91e6bf6]"))); assertThat(path.getSegment(0).getName(), is(name("f81d4fae-7dec-11d0-a765-00a0c91e6bf6"))); assertThat(path.getSegment(0).getIndex(), is(1)); assertThat(path.getSegment(0).isIdentifier(), is(true)); }