2 * Copyright (c) 2019 Pantheon Technologies, s.r.o. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.xpath.impl;
10 import javax.xml.xpath.XPathExpressionException;
11 import org.opendaylight.yangtools.yang.common.QName;
12 import org.opendaylight.yangtools.yang.common.YangNamespaceContext;
13 import org.opendaylight.yangtools.yang.xpath.api.YangLiteralExpr;
14 import org.opendaylight.yangtools.yang.xpath.api.YangLocationPath;
15 import org.opendaylight.yangtools.yang.xpath.api.YangQNameExpr;
18 * Utilities for interpreting {@link YangLiteralExpr}s as {@link YangQNameExpr}s and {@link YangLocationPath}s.
20 final class LiteralExprUtils {
21 private LiteralExprUtils() {
25 static YangQNameExpr interpretAsQName(final YangNamespaceContext namespaceContext, final YangLiteralExpr expr)
26 throws XPathExpressionException {
27 final String text = expr.getLiteral();
28 final int colon = text.indexOf(':');
32 qname = namespaceContext.createQName(text.substring(0, colon), text.substring(colon + 1));
33 } catch (IllegalArgumentException e) {
34 throw new XPathExpressionException(e);
38 // Deal with UnprefixedNames by interpreting them in implicit namespace
39 qname = namespaceContext.createQName(expr.getLiteral());
40 } catch (IllegalArgumentException | IllegalStateException e) {
41 throw new XPathExpressionException(e);
45 return YangQNameExpr.of(qname);