*/
package org.opendaylight.yangtools.yang.model.api;
+import com.google.common.annotations.Beta;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.xpath.api.YangXPathExpression;
+import org.opendaylight.yangtools.yang.xpath.api.YangXPathExpression.QualifiedBound;
+
/**
- * Contains methods for getting data (concrete XPath) and metadata (is XPath
- * absolute) from XPath instance.
+ * Contains methods for getting data (concrete XPath) and metadata (is XPath absolute) from XPath instance.
*/
+// FIXME: 4.0.0: find a better name for this interface
public interface RevisionAwareXPath {
-
/**
- * Returns <code>true</code> if the XPapth starts in root of Yang model,
- * otherwise returns <code>false</code>.
+ * Returns <code>true</code> if the XPapth starts in root of Yang model, otherwise returns <code>false</code>.
*
- * @return <code>true</code> if the XPapth starts in root of Yang model,
- * otherwise returns <code>false</code>
+ * @return <code>true</code> if the XPapth starts in root of Yang model, otherwise returns <code>false</code>
*/
boolean isAbsolute();
/**
- * Returns the XPath formatted string as is defined in model. <br>
- * For example:
+ * Returns the XPath formatted string as is defined in model. For example:
* /prefix:container/prefix:container::cond[when()=foo]/prefix:leaf
*
* @return the XPath formatted string as is defined in model.
*/
- @Override
- String toString();
+ @NonNull String getOriginalString();
+
+ @Beta
+ // FIXME: 4.0.0: integrate this interface into RevisionAwareXPath
+ interface WithExpression extends RevisionAwareXPath {
+ /**
+ * Return the {@link YangXPathExpression} of this XPath. The expression is required to be at least
+ * Qualified-bound.
+ *
+ * @return The location path
+ */
+ @NonNull QualifiedBound getXPathExpression();
+ }
}
*/
package org.opendaylight.yangtools.yang.model.util;
+import static java.util.Objects.requireNonNull;
+
import java.util.Objects;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
/**
- * The <code>helper</code> implementation of Instance Rewision Aware XPath
- * interface.
+ * The <code>helper</code> implementation of Instance Revision Aware XPath interface.
*
* @see RevisionAwareXPath
*/
public class RevisionAwareXPathImpl implements RevisionAwareXPath {
-
- private final String xpath;
+ private final @NonNull String xpath;
private final boolean absolute;
public RevisionAwareXPathImpl(final String xpath, final boolean absolute) {
- this.xpath = xpath;
+ this.xpath = requireNonNull(xpath);
this.absolute = absolute;
}
}
@Override
- public String toString() {
+ public String getOriginalString() {
return xpath;
}
}
@Override
public String toString() {
- return xpath.toString();
+ return xpath.getOriginalString();
}
}
for (final AugmentationSchemaNode as : augmentations) {
if (!as.getWhenCondition().isPresent()) {
augment3 = as;
- } else if ("if:ifType='ds0'".equals(as.getWhenCondition().get().toString())) {
+ } else if ("if:ifType='ds0'".equals(as.getWhenCondition().get().getOriginalString())) {
augment1 = as;
- } else if ("if:ifType='ds2'".equals(as.getWhenCondition().get().toString())) {
+ } else if ("if:ifType='ds2'".equals(as.getWhenCondition().get().getOriginalString())) {
augment2 = as;
}
}
final Collection<MustDefinition> mustConstraints = root.getMustConstraints();
assertEquals(1, mustConstraints.size());
final MustDefinition must = mustConstraints.iterator().next();
- assertEquals("not(deref(.)/../same-pass)", must.getXpath().toString());
+ assertEquals("not(deref(.)/../same-pass)", must.getXpath().getOriginalString());
}
}
assertTrue(dataNodeBar instanceof ContainerSchemaNode);
final ContainerSchemaNode bar = (ContainerSchemaNode) dataNodeBar;
final RevisionAwareXPath whenCondition = bar.getWhenCondition().get();
- assertEquals("/foo != \"bar\"", whenCondition.toString());
+ assertEquals("/foo != \"bar\"", whenCondition.getOriginalString());
final Set<TypeDefinition<?>> typeDefinitions = schemaContext.getTypeDefinitions();
assertEquals(1, typeDefinitions.size());
assertTrue(dataNodeBar instanceof ContainerSchemaNode);
final ContainerSchemaNode bar = (ContainerSchemaNode) dataNodeBar;
final RevisionAwareXPath whenCondition = bar.getWhenCondition().get();
- assertEquals("/foo != 'bar'", whenCondition.toString());
+ assertEquals("/foo != 'bar'", whenCondition.getOriginalString());
final Set<TypeDefinition<?>> typeDefinitions = schemaContext.getTypeDefinitions();
assertEquals(1, typeDefinitions.size());
final Iterator<MustDefinition> mustsIterator = musts.iterator();
MustDefinition mustStmt = mustsIterator.next();
- assertThat(mustStmt.getXpath().toString(), anyOf(is("ifType != 'ethernet' or (ifType = 'ethernet' and "
+ assertThat(mustStmt.getXpath().getOriginalString(), anyOf(is("ifType != 'ethernet' or (ifType = 'ethernet' and "
+ "ifMTU = 1500)"), is("ifType != 'atm' or (ifType = 'atm' and ifMTU <= 17966 and ifMTU >= 64)")));
assertThat(mustStmt.getErrorMessage(), anyOf(is(Optional.of("An ethernet MTU must be 1500")),
is(Optional.of("An atm MTU must be 64 .. 17966"))));
assertThat(mustStmt.getErrorAppTag(), anyOf(is(Optional.of("An ethernet error")),
is(Optional.of("An atm error"))));
mustStmt = mustsIterator.next();
- assertThat(mustStmt.getXpath().toString(), anyOf(
+ assertThat(mustStmt.getXpath().getOriginalString(), anyOf(
is("ifType != 'ethernet' or (ifType = 'ethernet' and ifMTU = 1500)"),
is("ifType != 'atm' or (ifType = 'atm' and ifMTU <= 17966 and ifMTU >= 64)")));
assertThat(mustStmt.getErrorMessage(), anyOf(is(Optional.of("An ethernet MTU must be 1500")),
final ContainerSchemaNode container = (ContainerSchemaNode) testModule.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-container"));
assertNotNull(container);
- assertEquals("conditional-leaf = 'autumn-leaf'", container.getWhenCondition().get().toString());
+ assertEquals("conditional-leaf = 'autumn-leaf'", container.getWhenCondition().get().getOriginalString());
}
}
assertFalse(data.isConfiguration());
assertTrue(data.isMandatory());
- assertEquals("class != 'wheel'", data.getWhenCondition().get().toString());
+ assertEquals("class != 'wheel'", data.getWhenCondition().get().getOriginalString());
final Collection<MustDefinition> mustConstraints = data.getMustConstraints();
assertEquals(2, mustConstraints.size());
assertFalse(nodes.isConfiguration());
// constraints
- assertEquals("class != 'wheel'", nodes.getWhenCondition().get().toString());
+ assertEquals("class != 'wheel'", nodes.getWhenCondition().get().getOriginalString());
final Collection<MustDefinition> mustConstraints = nodes.getMustConstraints();
assertEquals(2, mustConstraints.size());