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 javax.annotation.Nonnull;
12 import javax.annotation.Nullable;
13 import org.opendaylight.yangtools.yang.common.QName;
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.meta.StatementDefinition;
17 import org.opendaylight.yangtools.yang.parser.spi.SubstatementValidator;
21 * Class providing necessary support for processing YANG statement.
23 * This class is intended to be subclassed by developers, which want to
24 * introduce support of statement to parser.
29 * Declared Statement representation
31 * Effective Statement representation
33 public abstract class AbstractStatementSupport<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
34 implements StatementDefinition, StatementFactory<A, D, E>, StatementSupport<A, D, E> {
36 private final StatementDefinition type;
38 protected AbstractStatementSupport(final StatementDefinition publicDefinition) {
39 Preconditions.checkArgument(publicDefinition != this);
40 this.type = Preconditions.checkNotNull(publicDefinition);
45 public final QName getStatementName() {
46 return type.getStatementName();
50 public final QName getArgumentName() {
51 return type.getArgumentName();
56 public final Class<? extends DeclaredStatement<?>> getDeclaredRepresentationClass() {
57 return type.getDeclaredRepresentationClass();
62 public final Class<? extends EffectiveStatement<?,?>> getEffectiveRepresentationClass() {
63 return type.getEffectiveRepresentationClass();
67 public final StatementDefinition getPublicView() {
72 public void onStatementAdded(final StmtContext.Mutable<A, D, E> stmt) {
73 // NOOP for most implementations
79 * Subclasses of this class may override this method to perform actions on
80 * this event or register modification action using
81 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
84 public void onPreLinkageDeclared(final StmtContext.Mutable<A, D, E> stmt) {
85 // NOOP for most implementations
91 * Subclasses of this class may override this method to perform actions on
92 * this event or register modification action using
93 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
96 public void onLinkageDeclared(final StmtContext.Mutable<A, D, E> stmt) {
97 // NOOP for most implementations
103 * Subclasses of this class may override this method to perform actions on
104 * this event or register modification action using
105 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
108 public void onStatementDefinitionDeclared(final StmtContext.Mutable<A, D, E> stmt) {
109 // NOOP for most implementations
115 * Subclasses of this class may override this method to perform actions on
116 * this event or register modification action using
117 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
120 public void onFullDefinitionDeclared(final StmtContext.Mutable<A, D, E> stmt) {
121 final SubstatementValidator validator = getSubstatementValidator();
122 if (validator != null) {
123 validator.validate(stmt);
128 public boolean isArgumentYinElement() {
129 return getPublicView().isArgumentYinElement();
133 * Returns corresponding substatement validator of a statement support
135 * @return substatement validator or null, if substatement validator is not
139 protected abstract SubstatementValidator getSubstatementValidator();