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 java.util.Optional;
14 import javax.annotation.Nonnull;
15 import javax.annotation.Nullable;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
18 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
19 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
22 * Class providing necessary support for processing a YANG statement. This class is intended to be subclassed
23 * by developers who want to add semantic support for a statement to a parser reactor.
28 * Declared Statement representation
30 * Effective Statement representation
32 public abstract class AbstractStatementSupport<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
33 implements StatementDefinition, StatementFactory<A, D, E>, StatementSupport<A, D, E> {
35 private final StatementDefinition type;
37 protected AbstractStatementSupport(final StatementDefinition publicDefinition) {
38 this.type = requireNonNull(publicDefinition);
39 checkArgument(publicDefinition != this);
44 public final QName getStatementName() {
45 return type.getStatementName();
49 public final QName getArgumentName() {
50 return type.getArgumentName();
55 public final Class<? extends DeclaredStatement<?>> getDeclaredRepresentationClass() {
56 return type.getDeclaredRepresentationClass();
61 public final Class<? extends EffectiveStatement<?,?>> getEffectiveRepresentationClass() {
62 return type.getEffectiveRepresentationClass();
66 public final StatementDefinition getPublicView() {
71 public Optional<StatementSupport<?, ?, ?>> getImplicitParentFor(final StatementDefinition stmtDef) {
72 // NOOP for most implementations and also no implicit parent
73 return Optional.empty();
77 public void onStatementAdded(final StmtContext.Mutable<A, D, E> stmt) {
78 // NOOP for most implementations
85 * Subclasses of this class may override this method to perform actions on this event or register a modification
86 * action using {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
89 public void onPreLinkageDeclared(final StmtContext.Mutable<A, D, E> stmt) {
90 // NOOP for most implementations
97 * Subclasses of this class may override this method to perform actions on this event or register a modification
98 * action using {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
101 public void onLinkageDeclared(final StmtContext.Mutable<A, D, E> stmt) {
102 // NOOP for most implementations
109 * Subclasses of this class may override this method to perform actions on this event or register a modification
110 * action using {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
113 public void onStatementDefinitionDeclared(final StmtContext.Mutable<A, D, E> stmt) {
114 // NOOP for most implementations
121 * Subclasses of this class may override this method to perform actions on this event or register a modification
122 * action using {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
125 public void onFullDefinitionDeclared(final StmtContext.Mutable<A, D, E> stmt) {
126 final SubstatementValidator validator = getSubstatementValidator();
127 if (validator != null) {
128 validator.validate(stmt);
133 public boolean isArgumentYinElement() {
134 return getPublicView().isArgumentYinElement();
138 public boolean hasArgumentSpecificSupports() {
139 // Most of statement supports don't have any argument specific
140 // supports, so return 'false'.
145 public StatementSupport<?, ?, ?> getSupportSpecificForArgument(final String argument) {
146 // Most of statement supports don't have any argument specific
147 // supports, so return null.
152 * Returns corresponding substatement validator of a statement support.
154 * @return substatement validator or null, if substatement validator is not
158 protected abstract SubstatementValidator getSubstatementValidator();