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.meta;
10 import com.google.common.collect.ImmutableList;
11 import org.opendaylight.yangtools.yang.common.QName;
12 import org.opendaylight.yangtools.yang.model.api.Status;
13 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
14 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
15 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
16 import org.opendaylight.yangtools.yang.model.api.stmt.FeatureEffectiveStatement;
17 import org.opendaylight.yangtools.yang.model.api.stmt.FeatureStatement;
18 import org.opendaylight.yangtools.yang.model.api.stmt.StatusEffectiveStatement;
19 import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatements;
20 import org.opendaylight.yangtools.yang.model.ri.stmt.EffectiveStatements;
21 import org.opendaylight.yangtools.yang.model.spi.meta.EffectiveStatementMixins.EffectiveStatementWithFlags.FlagsBuilder;
22 import org.opendaylight.yangtools.yang.parser.spi.FeatureNamespace;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractQNameStatementSupport;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
25 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
26 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
27 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
28 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
30 public final class FeatureStatementSupport
31 extends AbstractQNameStatementSupport<FeatureStatement, FeatureEffectiveStatement> {
32 private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(
33 YangStmtMapping.FEATURE)
34 .addOptional(YangStmtMapping.DESCRIPTION)
35 .addAny(YangStmtMapping.IF_FEATURE)
36 .addOptional(YangStmtMapping.STATUS)
37 .addOptional(YangStmtMapping.REFERENCE)
39 private static final FeatureStatementSupport INSTANCE = new FeatureStatementSupport();
41 private FeatureStatementSupport() {
42 super(YangStmtMapping.FEATURE, StatementPolicy.reject());
45 public static FeatureStatementSupport getInstance() {
50 public QName parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
51 return StmtContextUtils.parseIdentifier(ctx, value);
55 public void onFullDefinitionDeclared(final Mutable<QName, FeatureStatement, FeatureEffectiveStatement> stmt) {
56 super.onFullDefinitionDeclared(stmt);
57 stmt.addContext(FeatureNamespace.class, stmt.getArgument(), stmt);
61 protected SubstatementValidator getSubstatementValidator() {
62 return SUBSTATEMENT_VALIDATOR;
66 protected FeatureStatement createDeclared(final StmtContext<QName, FeatureStatement, ?> ctx,
67 final ImmutableList<? extends DeclaredStatement<?>> substatements) {
68 return DeclaredStatements.createFeature(ctx.getArgument(), substatements);
72 protected FeatureEffectiveStatement createEffective(final Current<QName, FeatureStatement> stmt,
73 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
74 return EffectiveStatements.createFeature(stmt.declared(), stmt.effectivePath(), computeFlags(substatements),
78 private static int computeFlags(final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
79 return new FlagsBuilder()
80 .setStatus(findFirstArgument(substatements, StatusEffectiveStatement.class, Status.CURRENT))