public int compare( Name o1, Name o2 ) { if (o1 == o2) return 0; if (o1 == null) return -1; if (o2 == null) return 1; return o1.compareTo(o2); } };
/** * {@inheritDoc} */ public boolean isSelfReference() { return this.name.getLocalName().equals(Path.SELF) && this.name.getNamespaceUri().length() == 0; }
@Test public void shouldCreateNameFromSingleStringInStandardFullNamespaceFormat() { name = factory.create("{http://www.modeshape.org/namespace}something"); assertThat(name.getLocalName(), is("something")); assertThat(name.getNamespaceUri(), is("http://www.modeshape.org/namespace")); assertThat(name.getString(NO_OP_ENCODER), is("{http://www.modeshape.org/namespace}something")); }
@Test public void shouldConsiderNamesEqualIfTheyHaveTheSameNamespaceUriAndLocalPart() { Name other = new BasicName(name.getNamespaceUri(), name.getLocalName()); assertThat(name.equals(other), is(true)); assertThat(name.compareTo(other), is(0)); }
@Override public Property getProperty( Name name ) { // Check the "standard" names that should be prefixed with 'dna:' if (name.getLocalName().equals(ModeShapeLexicon.RETRY_LIMIT.getLocalName())) name = ModeShapeLexicon.RETRY_LIMIT; if (name.getLocalName().equals(ModeShapeLexicon.DESCRIPTION.getLocalName())) name = ModeShapeLexicon.DESCRIPTION; return super.getProperty(name); } }
if (workspacesNode == null) { I18n msg = GraphI18n.requiredNodeDoesNotExistRelativeToNode; throw new RepositorySourceException(msg.text(ModeShapeLexicon.WORKSPACES.getString(registry), repositories.getLocation().getPath().getString(registry), repositories.getGraph().getCurrentWorkspaceName(), workspaceName = workspace.getPath().getLastSegment().getName().getLocalName(); if (projectionsNode == null) { I18n msg = GraphI18n.requiredNodeDoesNotExistRelativeToNode; throw new RepositorySourceException(getName(), msg.text(ModeShapeLexicon.PROJECTIONS.getString(registry), workspaceNode.getLocation() .getPath()
@Test public void shouldTrimNamespaceUriInConstructor() { name = new BasicName(" " + validNamespaceUri + "\t \t", validLocalName); assertThat(name.getNamespaceUri(), is(validNamespaceUri.trim())); name = new BasicName(" \t \t", validLocalName); assertThat(name.getNamespaceUri(), is("")); }
atts.addAttribute(name.getNamespaceUri(), name.getLocalName(), name.getString(registry), "string", buff.toString()); nodeName = node.getLocation().getPath().getLastSegment().getName(); String uri = nodeName.getNamespaceUri(); String localName = nodeName.getLocalName(); String qName = nodeName.getString(registry); handler.startElement(uri, localName, qName, atts);
@Override public RepositorySourceDefinition<ReturnType> setProperty( String propertyName, Object value ) { Name name = context.getValueFactories().getNameFactory().create(propertyName); // Check the "standard" names that should be prefixed with 'dna:' if (name.getLocalName().equals(ModeShapeLexicon.RETRY_LIMIT.getLocalName())) name = ModeShapeLexicon.RETRY_LIMIT; if (name.getLocalName().equals(ModeShapeLexicon.DESCRIPTION.getLocalName())) name = ModeShapeLexicon.DESCRIPTION; return super.setProperty(name, value); }
@Test public void shouldAllowEmptyNamespaceUriInConstructor() { name = new BasicName("", validLocalName); assertThat(name.getNamespaceUri(), is("")); }
/** * {@inheritDoc} */ public boolean isParentReference() { return this.name.getLocalName().equals(Path.PARENT) && this.name.getNamespaceUri().length() == 0; }
@Test public void shouldCreateNameFromSingleStringInPrefixedNamespaceFormat() { name = factory.create("dna:something"); assertThat(name.getLocalName(), is("something")); assertThat(name.getNamespaceUri(), is("http://www.modeshape.org/namespace")); assertThat(name.getString(NO_OP_ENCODER), is("{http://www.modeshape.org/namespace}something")); }
/** * {@inheritDoc} */ @Override public String getString( TextEncoder encoder ) { if (encoder == null) encoder = Path.DEFAULT_ENCODER; StringBuilder sb = new StringBuilder(); sb.append('[').append(this.getName().getString(encoder)).append(']'); return sb.toString(); }
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)); } }
/** * {@inheritDoc} */ @Override public int compareTo( PropertyValue that ) { if (this == that) return 0; if (this.name.equals(JcrLexicon.PRIMARY_TYPE)) return -1; if (that.name.equals(JcrLexicon.PRIMARY_TYPE)) return 1; return this.name.compareTo(that.name); }
@Test public void shouldAllowNullNamespaceUriInConstructorAndConvertToEmptyString() { name = new BasicName(null, validLocalName); assertThat(name.getNamespaceUri(), is("")); }
/** * {@inheritDoc} */ public int compareTo( Name that ) { if (that == this) return 0; int diff = this.getLocalName().compareTo(that.getLocalName()); if (diff != 0) return diff; diff = this.getNamespaceUri().compareTo(that.getNamespaceUri()); return diff; }
@Test public void shouldCreateNameFromSingleEncodedStringInPrefixedNamespaceFormat() { name = factory.create(encoder.encode("dna") + ":" + encoder.encode("some/thing")); assertThat(name.getLocalName(), is("some/thing")); assertThat(name.getNamespaceUri(), is("http://www.modeshape.org/namespace")); assertThat(name.getString(NO_OP_ENCODER), is("{http://www.modeshape.org/namespace}some/thing")); }
/** * {@inheritDoc} */ public URI create( Name value ) { if (value == null) return null; return create("./" + value.getString(this.namespaceRegistry)); }