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 org.opendaylight.yangtools.yang.common.QName;
13 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
14 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
15 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
16 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
20 * Class providing necessary support for processing YANG statement.
22 * This class is intended to be subclassed by developers, which want to
23 * introduce support of statement to parser.
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(StatementDefinition publicDefinition) {
38 Preconditions.checkArgument(publicDefinition != this);
39 this.type = Preconditions.checkNotNull(publicDefinition);
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 abstract A parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) throws SourceException;
74 public void onStatementAdded(StmtContext.Mutable<A, D, E> stmt) {
75 // NOOP for most implementations
82 * Subclasses of this class may override this method to perform actions on
83 * this event or register modification action using
84 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
88 public void onPreLinkageDeclared(StmtContext.Mutable<A, D, E> stmt) {
89 // NOOP for most implementations
96 * Subclasses of this class may override this method to perform actions on
97 * this event or register modification action using
98 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
102 public void onLinkageDeclared(StmtContext.Mutable<A, D, E> stmt) throws SourceException {
103 // NOOP for most implementations
110 * Subclasses of this class may override this method to perform actions on
111 * this event or register modification action using
112 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
116 public void onStatementDefinitionDeclared(StmtContext.Mutable<A, D, E> stmt) throws SourceException {
117 // NOOP for most implementations
124 * Subclasses of this class may override this method to perform actions on
125 * this event or register modification action using
126 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
130 public void onFullDefinitionDeclared(StmtContext.Mutable<A, D, E> stmt) throws SourceException {
131 // NOOP for most implementations
135 public boolean isArgumentYinElement() {
136 return getPublicView().isArgumentYinElement();