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;
18 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
22 * Class providing necessary support for processing YANG statement.
24 * This class is intended to be subclassed by developers, which want to
25 * introduce support of statement to parser.
30 * Declared Statement representation
32 * Effective Statement representation
34 public abstract class AbstractStatementSupport<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
35 implements StatementDefinition, StatementFactory<A, D, E>, StatementSupport<A, D, E> {
37 private final StatementDefinition type;
39 protected AbstractStatementSupport(final StatementDefinition publicDefinition) {
40 Preconditions.checkArgument(publicDefinition != this);
41 this.type = Preconditions.checkNotNull(publicDefinition);
46 public final QName getStatementName() {
47 return type.getStatementName();
51 public final QName getArgumentName() {
52 return type.getArgumentName();
57 public final Class<? extends DeclaredStatement<?>> getDeclaredRepresentationClass() {
58 return type.getDeclaredRepresentationClass();
63 public final Class<? extends EffectiveStatement<?,?>> getEffectiveRepresentationClass() {
64 return type.getEffectiveRepresentationClass();
68 public final StatementDefinition getPublicView() {
73 public abstract A parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) throws SourceException;
76 public void onStatementAdded(final StmtContext.Mutable<A, D, E> stmt) {
77 // NOOP for most implementations
84 * Subclasses of this class may override this method to perform actions on
85 * this event or register modification action using
86 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
90 public void onPreLinkageDeclared(final StmtContext.Mutable<A, D, E> stmt) {
91 // NOOP for most implementations
98 * Subclasses of this class may override this method to perform actions on
99 * this event or register modification action using
100 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
104 public void onLinkageDeclared(final StmtContext.Mutable<A, D, E> stmt) throws SourceException {
105 // NOOP for most implementations
112 * Subclasses of this class may override this method to perform actions on
113 * this event or register modification action using
114 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
118 public void onStatementDefinitionDeclared(final StmtContext.Mutable<A, D, E> stmt) throws SourceException {
119 // NOOP for most implementations
126 * Subclasses of this class may override this method to perform actions on
127 * this event or register modification action using
128 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
132 public void onFullDefinitionDeclared(final StmtContext.Mutable<A, D, E> stmt) throws SourceException {
133 // NOOP for most implementations
137 public boolean isArgumentYinElement() {
138 return getPublicView().isArgumentYinElement();
142 * Returns corresponding substatement validator of a statement support
144 * @return substatement validator or null, if substatement validator is not
148 protected abstract SubstatementValidator getSubstatementValidator();