/** * {@inheritDoc} */ public boolean isParentReference() { return this.name.getLocalName().equals(Path.PARENT) && this.name.getNamespaceUri().length() == 0; }
/** * {@inheritDoc} */ public boolean isSelfReference() { return this.name.getLocalName().equals(Path.SELF) && this.name.getNamespaceUri().length() == 0; }
/** * {@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; }
/** * {@inheritDoc} */ @Override public boolean equals( Object obj ) { if (obj == this) return true; if (obj instanceof Name) { Name that = (Name)obj; if (!this.getLocalName().equals(that.getLocalName())) return false; if (!this.getNamespaceUri().equals(that.getNamespaceUri())) return false; return true; } return false; }
@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("")); }
for (Property property : clusterNode.getProperties()) { Name propertyName = property.getName(); if (skipNamespaces.contains(propertyName.getNamespaceUri())) continue; if (skipProperties.contains(propertyName)) continue; if (property.isSingle()) {
@Test public void shouldReturnSameHashCodeForNamesWithSameNamespaceUriAndLocalPart() { Name other = new BasicName(name.getNamespaceUri(), name.getLocalName()); assertThat(name.hashCode(), is(other.hashCode())); }
for (Property property : node.getProperties()) { Name propertyName = property.getName(); if (skipNamespaces.contains(propertyName.getNamespaceUri())) continue; if (skipProperties.contains(propertyName)) continue; if (property.isSingle()) {
for (Property property : node.getProperties()) { Name propertyName = property.getName(); if (skipNamespaces.contains(propertyName.getNamespaceUri())) continue; if (skipProperties.contains(propertyName)) continue; if (property.isSingle()) {
@Test public void shouldAllowNullNamespaceUriInConstructorAndConvertToEmptyString() { name = new BasicName(null, validLocalName); assertThat(name.getNamespaceUri(), is("")); }
@Test public void shouldAllowEmptyNamespaceUriInConstructor() { name = new BasicName("", 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);
@Test public void shouldConsiderNamesEqualIfTheyHaveTheSameNamespaceUriAndLocalPart() { Name other = new BasicName(name.getNamespaceUri(), name.getLocalName()); assertThat(name.equals(other), is(true)); assertThat(name.compareTo(other), is(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 shouldCreateNameFromSingleStringInPrefixedNamespaceFormatWithoutPrefix() { name = factory.create("a"); assertThat(name.getLocalName(), is("a")); assertThat(name.getNamespaceUri(), is(this.registry.getNamespaceForPrefix(""))); }
@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")); }
@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")); }
@Test public void shouldCreateNameFromSingleEncodedStringInStandardFullNamespaceFormat() { name = factory.create("{" + encoder.encode("http://www.modeshape.org/namespace") + "}" + 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")); }
@Test public void shouldCreateParentReferenceSegmentIfPassedParentReferenceStringRegardlessOfIndex() { segment = factory.createSegment(Path.PARENT); assertThat(segment.getIndex(), is(Path.DEFAULT_INDEX)); assertThat(segment.hasIndex(), is(false)); assertThat(segment.isSelfReference(), is(false)); assertThat(segment.isParentReference(), is(true)); assertThat(segment.getName().getLocalName(), is(Path.PARENT)); assertThat(segment.getName().getNamespaceUri().length(), is(0)); segment = factory.createSegment(Path.PARENT, 1); assertThat(segment.getIndex(), is(Path.DEFAULT_INDEX)); assertThat(segment.hasIndex(), is(false)); assertThat(segment.isSelfReference(), is(false)); assertThat(segment.isParentReference(), is(true)); assertThat(segment.getName().getLocalName(), is(Path.PARENT)); assertThat(segment.getName().getNamespaceUri().length(), is(0)); }
@Test public void shouldCreateSelfReferenceSegmentIfPassedSelfReferenceStringRegardlessOfIndex() { segment = factory.createSegment(Path.SELF); assertThat(segment.getIndex(), is(Path.DEFAULT_INDEX)); assertThat(segment.hasIndex(), is(false)); assertThat(segment.isSelfReference(), is(true)); assertThat(segment.isParentReference(), is(false)); assertThat(segment.getName().getLocalName(), is(Path.SELF)); assertThat(segment.getName().getNamespaceUri().length(), is(0)); segment = factory.createSegment(Path.SELF, 1); assertThat(segment.getIndex(), is(Path.DEFAULT_INDEX)); assertThat(segment.hasIndex(), is(false)); assertThat(segment.isSelfReference(), is(true)); assertThat(segment.isParentReference(), is(false)); assertThat(segment.getName().getLocalName(), is(Path.SELF)); assertThat(segment.getName().getNamespaceUri().length(), is(0)); }