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 com.google.common.base.Preconditions;
11 import java.util.Optional;
12 import javax.annotation.Nonnull;
13 import javax.annotation.Nullable;
14 import org.opendaylight.yangtools.yang.common.QName;
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.
26 * Declared Statement representation
28 * Effective Statement representation
30 public abstract class AbstractStatementSupport<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
31 implements StatementDefinition, StatementFactory<A, D, E>, StatementSupport<A, D, E> {
33 private final StatementDefinition type;
35 protected AbstractStatementSupport(final StatementDefinition publicDefinition) {
36 Preconditions.checkArgument(publicDefinition != this);
37 this.type = Preconditions.checkNotNull(publicDefinition);
42 public final QName getStatementName() {
43 return type.getStatementName();
47 public final QName getArgumentName() {
48 return type.getArgumentName();
53 public final Class<? extends DeclaredStatement<?>> getDeclaredRepresentationClass() {
54 return type.getDeclaredRepresentationClass();
59 public final Class<? extends EffectiveStatement<?,?>> getEffectiveRepresentationClass() {
60 return type.getEffectiveRepresentationClass();
64 public final StatementDefinition getPublicView() {
69 public Optional<StatementSupport<?, ?, ?>> getImplicitParentFor(final StatementDefinition stmtDef) {
70 // NOOP for most implementations and also no implicit parent
71 return Optional.empty();
75 public void onStatementAdded(final StmtContext.Mutable<A, D, E> stmt) {
76 // NOOP for most implementations
83 * Subclasses of this class may override this method to perform actions on this event or register a modification
84 * action using {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
87 public void onPreLinkageDeclared(final StmtContext.Mutable<A, D, E> stmt) {
88 // NOOP for most implementations
95 * Subclasses of this class may override this method to perform actions on this event or register a modification
96 * action using {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
99 public void onLinkageDeclared(final StmtContext.Mutable<A, D, E> stmt) {
100 // NOOP for most implementations
107 * Subclasses of this class may override this method to perform actions on this event or register a modification
108 * action using {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
111 public void onStatementDefinitionDeclared(final StmtContext.Mutable<A, D, E> stmt) {
112 // NOOP for most implementations
119 * Subclasses of this class may override this method to perform actions on this event or register a modification
120 * action using {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
123 public void onFullDefinitionDeclared(final StmtContext.Mutable<A, D, E> stmt) {
124 final SubstatementValidator validator = getSubstatementValidator();
125 if (validator != null) {
126 validator.validate(stmt);
131 public boolean isArgumentYinElement() {
132 return getPublicView().isArgumentYinElement();
136 public boolean hasArgumentSpecificSupports() {
137 // Most of statement supports don't have any argument specific
138 // supports, so return 'false'.
143 public StatementSupport<?, ?, ?> getSupportSpecificForArgument(final String argument) {
144 // Most of statement supports don't have any argument specific
145 // supports, so return null.
150 * Returns corresponding substatement validator of a statement support.
152 * @return substatement validator or null, if substatement validator is not
156 protected abstract SubstatementValidator getSubstatementValidator();