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 com.google.common.collect.Iterables;
12 import org.opendaylight.yangtools.yang.common.QNameModule;
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.DeviationEffectiveStatement;
17 import org.opendaylight.yangtools.yang.model.api.stmt.DeviationStatement;
18 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
19 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.ArgumentUtils;
20 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseStatementSupport;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
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;
25 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
27 public final class DeviationStatementSupport
28 extends BaseStatementSupport<SchemaNodeIdentifier, DeviationStatement, DeviationEffectiveStatement> {
29 private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(YangStmtMapping
31 .addOptional(YangStmtMapping.DESCRIPTION)
32 .addAny(YangStmtMapping.DEVIATE)
33 .addOptional(YangStmtMapping.REFERENCE)
35 private static final DeviationStatementSupport INSTANCE = new DeviationStatementSupport();
37 private DeviationStatementSupport() {
38 super(YangStmtMapping.DEVIATION);
41 public static DeviationStatementSupport getInstance() {
46 public SchemaNodeIdentifier parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
47 return ArgumentUtils.nodeIdentifierFromPath(ctx, value);
51 public void onFullDefinitionDeclared(
52 final Mutable<SchemaNodeIdentifier, DeviationStatement, DeviationEffectiveStatement> ctx) {
53 final QNameModule currentModule = ctx.getFromNamespace(ModuleCtxToModuleQName.class,
55 final QNameModule targetModule = Iterables.getLast(ctx.coerceStatementArgument().getNodeIdentifiers())
58 if (currentModule.equals(targetModule)) {
59 throw new InferenceException(ctx.getStatementSourceReference(),
60 "Deviation must not target the same module as the one it is defined in: %s", currentModule);
65 protected SubstatementValidator getSubstatementValidator() {
66 return SUBSTATEMENT_VALIDATOR;
70 protected DeviationStatement createDeclared(final StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> ctx,
71 final ImmutableList<? extends DeclaredStatement<?>> substatements) {
72 return new DeviationStatementImpl(ctx, substatements);
76 protected DeviationStatement createEmptyDeclared(
77 final StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> ctx) {
78 return new DeviationStatementImpl(ctx, ImmutableList.of());
82 protected DeviationEffectiveStatement createEffective(
83 final StmtContext<SchemaNodeIdentifier, DeviationStatement, DeviationEffectiveStatement> ctx,
84 final DeviationStatement declared, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
85 return new DeviationEffectiveStatementImpl(declared, substatements);
89 protected DeviationEffectiveStatement createEmptyEffective(
90 final StmtContext<SchemaNodeIdentifier, DeviationStatement, DeviationEffectiveStatement> ctx,
91 final DeviationStatement declared) {
92 return new DeviationEffectiveStatementImpl(declared, ImmutableList.of());