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.deviation;
10 import com.google.common.collect.ImmutableList;
11 import org.opendaylight.yangtools.yang.common.QNameModule;
12 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
13 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
14 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
15 import org.opendaylight.yangtools.yang.model.api.stmt.DeviationEffectiveStatement;
16 import org.opendaylight.yangtools.yang.model.api.stmt.DeviationStatement;
17 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
18 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.ArgumentUtils;
19 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseStatementSupport;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
24 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
26 public final class DeviationStatementSupport
27 extends BaseStatementSupport<SchemaNodeIdentifier, DeviationStatement, DeviationEffectiveStatement> {
28 private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(YangStmtMapping
30 .addOptional(YangStmtMapping.DESCRIPTION)
31 .addAny(YangStmtMapping.DEVIATE)
32 .addOptional(YangStmtMapping.REFERENCE)
34 private static final DeviationStatementSupport INSTANCE = new DeviationStatementSupport();
36 private DeviationStatementSupport() {
37 super(YangStmtMapping.DEVIATION);
40 public static DeviationStatementSupport getInstance() {
45 public SchemaNodeIdentifier parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
46 return ArgumentUtils.nodeIdentifierFromPath(ctx, value);
50 public void onFullDefinitionDeclared(
51 final Mutable<SchemaNodeIdentifier, DeviationStatement, DeviationEffectiveStatement> ctx) {
52 final QNameModule currentModule = ctx.getFromNamespace(ModuleCtxToModuleQName.class,
54 final QNameModule targetModule = ctx.coerceStatementArgument().getLastComponent().getModule();
56 if (currentModule.equals(targetModule)) {
57 throw new InferenceException(ctx.getStatementSourceReference(),
58 "Deviation must not target the same module as the one it is defined in: %s", currentModule);
63 protected SubstatementValidator getSubstatementValidator() {
64 return SUBSTATEMENT_VALIDATOR;
68 protected DeviationStatement createDeclared(final StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> ctx,
69 final ImmutableList<? extends DeclaredStatement<?>> substatements) {
70 return new DeviationStatementImpl(ctx, substatements);
74 protected DeviationStatement createEmptyDeclared(
75 final StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> ctx) {
76 return new DeviationStatementImpl(ctx, ImmutableList.of());
80 protected DeviationEffectiveStatement createEffective(
81 final StmtContext<SchemaNodeIdentifier, DeviationStatement, DeviationEffectiveStatement> ctx,
82 final DeviationStatement declared, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
83 return new DeviationEffectiveStatementImpl(declared, substatements);
87 protected DeviationEffectiveStatement createEmptyEffective(
88 final StmtContext<SchemaNodeIdentifier, DeviationStatement, DeviationEffectiveStatement> ctx,
89 final DeviationStatement declared) {
90 return new DeviationEffectiveStatementImpl(declared, ImmutableList.of());