2 * Copyright (c) 2015 Cisco Systems, Inc. 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.stmt.rfc6020;
10 import java.util.Collection;
11 import javax.annotation.Nonnull;
12 import javax.annotation.Nullable;
13 import org.opendaylight.yangtools.yang.common.QNameModule;
14 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
15 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
16 import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
17 import org.opendaylight.yangtools.yang.model.api.stmt.DeviateStatement;
18 import org.opendaylight.yangtools.yang.model.api.stmt.DeviationStatement;
19 import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
20 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
25 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
26 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
27 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.DeviationEffectiveStatementImpl;
29 public class DeviationStatementImpl extends AbstractDeclaredStatement<SchemaNodeIdentifier>
30 implements DeviationStatement {
31 private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(YangStmtMapping
33 .addOptional(YangStmtMapping.DESCRIPTION)
34 .addAny(YangStmtMapping.DEVIATE)
35 .addOptional(YangStmtMapping.REFERENCE)
38 protected DeviationStatementImpl(final StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> context) {
42 public static class Definition extends AbstractStatementSupport<SchemaNodeIdentifier, DeviationStatement,
43 EffectiveStatement<SchemaNodeIdentifier, DeviationStatement>> {
46 super(YangStmtMapping.DEVIATION);
50 public SchemaNodeIdentifier parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
51 return Utils.nodeIdentifierFromPath(ctx, value);
55 public DeviationStatement createDeclared(final StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> ctx) {
56 return new DeviationStatementImpl(ctx);
60 public EffectiveStatement<SchemaNodeIdentifier, DeviationStatement> createEffective(
61 final StmtContext<SchemaNodeIdentifier, DeviationStatement,
62 EffectiveStatement<SchemaNodeIdentifier, DeviationStatement>> ctx) {
63 return new DeviationEffectiveStatementImpl(ctx);
67 public void onFullDefinitionDeclared(final StmtContext.Mutable<SchemaNodeIdentifier, DeviationStatement,
68 EffectiveStatement<SchemaNodeIdentifier, DeviationStatement>> ctx) {
69 final QNameModule currentModule = ctx.getFromNamespace(ModuleCtxToModuleQName.class,
71 final QNameModule targetModule = ctx.getStatementArgument().getLastComponent().getModule();
73 if (currentModule.equals(targetModule)) {
74 throw new InferenceException(ctx.getStatementSourceReference(),
75 "Deviation must not target the same module as the one it is defined in: %s", currentModule);
80 protected SubstatementValidator getSubstatementValidator() {
81 return SUBSTATEMENT_VALIDATOR;
87 public SchemaNodeIdentifier getTargetNode() {
93 public DescriptionStatement getDescription() {
94 return firstDeclared(DescriptionStatement.class);
99 public ReferenceStatement getReference() {
100 return firstDeclared(ReferenceStatement.class);
105 public Collection<? extends DeviateStatement> getDeviateStatements() {
106 return allDeclared(DeviateStatement.class);