FilterParameter now has a YangXPathExpression 93/98093/3
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 23 Oct 2021 22:25:36 +0000 (00:25 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 24 Oct 2021 07:54:32 +0000 (09:54 +0200)
We have the infrastructure to understand the structure of a YANG XPath
expression. Use it to perform additional checks, so that we can rely on
it being syntactically valid.

JIRA: NETCONF-773
Change-Id: I37a0ddb1e4d5a6c115eb479ba550686c1a3c3fcd
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/FilterParameter.java

index 2c2777081ee5b5520c49e189164dc68a28067d74..5c6aed3efeebec0504e471ed505c099fe6092a73 100644 (file)
@@ -10,8 +10,12 @@ package org.opendaylight.restconf.nb.rfc8040;
 import static java.util.Objects.requireNonNull;
 
 import java.net.URI;
+import javax.xml.xpath.XPathExpressionException;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.opendaylight.yangtools.concepts.Immutable;
+import org.opendaylight.yangtools.yang.xpath.api.YangXPathExpression;
+import org.opendaylight.yangtools.yang.xpath.api.YangXPathMathMode;
+import org.opendaylight.yangtools.yang.xpath.api.YangXPathParserFactory;
 
 /**
  * This class represents a {@code filter} parameter as defined in
@@ -21,23 +25,23 @@ import org.opendaylight.yangtools.concepts.Immutable;
 public final class FilterParameter implements Immutable {
     private static final URI CAPABILITY = URI.create("urn:ietf:params:restconf:capability:filter:1.0");
 
-    // FIXME: can we have a parsed, but not bound version of an XPath, please?
-    private final String value;
+    private final YangXPathExpression value;
 
-    private FilterParameter(final String value) {
+    private FilterParameter(final YangXPathExpression value) {
         this.value = requireNonNull(value);
     }
 
-    public static FilterParameter forUriValue(final String uriValue) {
-        return new FilterParameter(uriValue);
+    public static FilterParameter forUriValue(final YangXPathParserFactory parserFactory, final String uriValue)
+            throws XPathExpressionException {
+        return new FilterParameter(parserFactory.newParser(YangXPathMathMode.EXACT).parseExpression(uriValue));
     }
 
-    public static String uriName() {
-        return "filter";
+    public YangXPathExpression value() {
+        return value;
     }
 
-    public String uriValue() {
-        return value;
+    public static String uriName() {
+        return "filter";
     }
 
     public static URI capabilityUri() {