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.rfc8040.parser;
10 import com.google.common.annotations.Beta;
11 import com.google.common.collect.ImmutableList;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.opendaylight.yangtools.rfc8040.model.api.YangDataEffectiveStatement;
14 import org.opendaylight.yangtools.rfc8040.model.api.YangDataStatement;
15 import org.opendaylight.yangtools.rfc8040.model.api.YangDataStatements;
16 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
17 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
18 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
19 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
20 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractDeclaredStatement.WithRawStringArgument.WithSubstatements;
21 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseStringStatementSupport;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
27 public final class YangDataStatementSupport
28 extends BaseStringStatementSupport<YangDataStatement, YangDataEffectiveStatement> {
30 * Declared statement representation of 'yang-data' extension defined in
31 * <a href="https://tools.ietf.org/html/rfc8040#section-8">RFC 8040</a>.
33 private static final class Declared extends WithSubstatements implements YangDataStatement {
34 Declared(final String rawArgument, final ImmutableList<? extends DeclaredStatement<?>> substatements) {
35 super(rawArgument, substatements);
39 private static final YangDataStatementSupport INSTANCE = new YangDataStatementSupport(YangDataStatements.YANG_DATA);
41 private final SubstatementValidator validator;
43 private YangDataStatementSupport(final StatementDefinition definition) {
45 validator = SubstatementValidator.builder(definition)
46 .addMandatory(YangStmtMapping.CONTAINER)
47 .addOptional(YangStmtMapping.USES)
51 public static YangDataStatementSupport getInstance() {
56 public void onFullDefinitionDeclared(final Mutable<String, YangDataStatement, YangDataEffectiveStatement> ctx) {
57 // as per https://tools.ietf.org/html/rfc8040#section-8,
58 // yang-data is ignored unless it appears as a top-level statement
59 if (ctx.coerceParentContext().getParentContext() != null) {
60 ctx.setIsSupportedToBuildEffective(false);
65 public boolean isIgnoringIfFeatures() {
70 public boolean isIgnoringConfig() {
75 protected SubstatementValidator getSubstatementValidator() {
80 protected YangDataStatement createDeclared(@NonNull final StmtContext<String, YangDataStatement, ?> ctx,
81 final ImmutableList<? extends DeclaredStatement<?>> substatements) {
82 return new Declared(ctx.coerceRawStatementArgument(), substatements);
86 protected YangDataStatement createEmptyDeclared(final StmtContext<String, YangDataStatement, ?> ctx) {
87 return createDeclared(ctx, ImmutableList.of());
91 protected YangDataEffectiveStatement createEffective(
92 final StmtContext<String, YangDataStatement, YangDataEffectiveStatement> ctx,
93 final YangDataStatement declared, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
94 // in case of yang-data node we need to perform substatement validation at the point when we have
95 // effective substatement contexts already available - if the node has only a uses statement declared in it,
96 // one top-level container node may very well be added to the yang-data as an effective statement
97 validator.validate(ctx);
98 return new YangDataEffectiveStatementImpl(ctx, substatements);
102 protected YangDataEffectiveStatement createEmptyEffective(
103 final StmtContext<String, YangDataStatement, YangDataEffectiveStatement> ctx,
104 final YangDataStatement declared) {
105 return createEffective(ctx, declared, ImmutableList.of());