2 * Copyright (c) 2017 Pantheon Technologies, s.r.o. and others. 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.parser.rfc7950.stmt.must;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.collect.ImmutableList;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
15 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
16 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
17 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
18 import org.opendaylight.yangtools.yang.model.api.stmt.MustEffectiveStatement;
19 import org.opendaylight.yangtools.yang.model.api.stmt.MustStatement;
20 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseStatementSupport;
21 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.XPathSupport;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
25 public final class MustStatementSupport
26 extends BaseStatementSupport<RevisionAwareXPath, MustStatement, MustEffectiveStatement> {
27 private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(YangStmtMapping
29 .addOptional(YangStmtMapping.DESCRIPTION)
30 .addOptional(YangStmtMapping.ERROR_APP_TAG)
31 .addOptional(YangStmtMapping.ERROR_MESSAGE)
32 .addOptional(YangStmtMapping.REFERENCE)
35 private final @NonNull XPathSupport xpathSupport;
37 private MustStatementSupport(final XPathSupport xpathSupport) {
38 super(YangStmtMapping.MUST);
39 this.xpathSupport = requireNonNull(xpathSupport);
42 public static MustStatementSupport createInstance(final XPathSupport xpathSupport) {
43 return new MustStatementSupport(xpathSupport);
47 public RevisionAwareXPath parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
48 return xpathSupport.parseXPath(ctx, value);
52 protected SubstatementValidator getSubstatementValidator() {
53 return SUBSTATEMENT_VALIDATOR;
57 protected MustStatement createDeclared(final StmtContext<RevisionAwareXPath, MustStatement, ?> ctx,
58 final ImmutableList<? extends DeclaredStatement<?>> substatements) {
59 return new RegularMustStatement(ctx, substatements);
63 protected MustStatement createEmptyDeclared(final StmtContext<RevisionAwareXPath, MustStatement, ?> ctx) {
64 return new EmptyMustStatement(ctx);
68 protected MustEffectiveStatement createEffective(
69 final StmtContext<RevisionAwareXPath, MustStatement, MustEffectiveStatement> ctx,
70 final MustStatement declared, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
71 return new RegularMustEffectiveStatement(declared, substatements);
75 protected MustEffectiveStatement createEmptyEffective(
76 final StmtContext<RevisionAwareXPath, MustStatement, MustEffectiveStatement> ctx,
77 final MustStatement declared) {
78 return new EmptyMustEffectiveStatement(declared);