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.spi.meta;
10 import static com.google.common.base.Preconditions.checkArgument;
11 import static java.util.Objects.requireNonNull;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.eclipse.jdt.annotation.Nullable;
15 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
16 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
17 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
20 * Class providing necessary support for processing a YANG statement. This class is intended to be subclassed
21 * by developers who want to add semantic support for a statement to a parser reactor.
23 * @param <A> Argument type
24 * @param <D> Declared Statement representation
25 * @param <E> Effective Statement representation
27 public abstract class AbstractStatementSupport<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
28 implements StatementDefinition, StatementFactory<A, D, E>, StatementSupport<A, D, E> {
30 private final @NonNull StatementDefinition type;
32 protected AbstractStatementSupport(final StatementDefinition publicDefinition) {
33 this.type = requireNonNull(publicDefinition);
34 checkArgument(publicDefinition != this);
38 public final StatementDefinition getPublicView() {
43 public void onStatementAdded(final StmtContext.Mutable<A, D, E> stmt) {
44 // NOOP for most implementations
51 * Subclasses of this class may override this method to perform actions on this event or register a modification
52 * action using {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
55 public void onPreLinkageDeclared(final StmtContext.Mutable<A, D, E> stmt) {
56 // NOOP for most implementations
63 * Subclasses of this class may override this method to perform actions on this event or register a modification
64 * action using {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
67 public void onLinkageDeclared(final StmtContext.Mutable<A, D, E> stmt) {
68 // NOOP for most implementations
75 * Subclasses of this class may override this method to perform actions on this event or register a modification
76 * action using {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
79 public void onStatementDefinitionDeclared(final StmtContext.Mutable<A, D, E> stmt) {
80 // NOOP for most implementations
87 * Subclasses of this class may override this method to perform actions on this event or register a modification
88 * action using {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
91 public void onFullDefinitionDeclared(final StmtContext.Mutable<A, D, E> stmt) {
92 final SubstatementValidator validator = getSubstatementValidator();
93 if (validator != null) {
94 validator.validate(stmt);
99 public boolean hasArgumentSpecificSupports() {
100 // Most of statement supports don't have any argument specific
101 // supports, so return 'false'.
106 public StatementSupport<?, ?, ?> getSupportSpecificForArgument(final String argument) {
107 // Most of statement supports don't have any argument specific
108 // supports, so return null.
113 * Returns corresponding substatement validator of a statement support.
115 * @return substatement validator or null, if substatement validator is not defined
117 protected abstract @Nullable SubstatementValidator getSubstatementValidator();