Eliminate superfluous onFullDefinitionDeclared overrides
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / spi / meta / AbstractStatementSupport.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.parser.spi.meta;
9
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
19 /**
20  *
21  * Class providing necessary support for processing YANG statement.
22  *
23  * This class is intended to be subclassed by developers, which want to
24  * introduce support of statement to parser.
25  *
26  * @param <A>
27  *            Argument type
28  * @param <D>
29  *            Declared Statement representation
30  * @param <E>
31  *            Effective Statement representation
32  */
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> {
35
36     private final StatementDefinition type;
37
38     protected AbstractStatementSupport(final StatementDefinition publicDefinition) {
39         Preconditions.checkArgument(publicDefinition != this);
40         this.type = Preconditions.checkNotNull(publicDefinition);
41     }
42
43     @Nonnull
44     @Override
45     public final QName getStatementName() {
46         return type.getStatementName();
47     }
48
49     @Override
50     public final QName getArgumentName() {
51         return type.getArgumentName();
52     }
53
54     @Nonnull
55     @Override
56     public final Class<? extends DeclaredStatement<?>> getDeclaredRepresentationClass() {
57         return type.getDeclaredRepresentationClass();
58     }
59
60     @Nonnull
61     @Override
62     public final Class<? extends EffectiveStatement<?,?>> getEffectiveRepresentationClass() {
63         return type.getEffectiveRepresentationClass();
64     }
65
66     @Override
67     public final StatementDefinition getPublicView() {
68         return type;
69     }
70
71     @Override
72     public void onStatementAdded(final StmtContext.Mutable<A, D, E> stmt) {
73         // NOOP for most implementations
74     }
75
76     /**
77      * {@inheritDoc}
78      *
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)}.
82      */
83     @Override
84     public void onPreLinkageDeclared(final StmtContext.Mutable<A, D, E> stmt) {
85         // NOOP for most implementations
86     }
87
88     /**
89      * {@inheritDoc}
90      *
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)}.
94      */
95     @Override
96     public void onLinkageDeclared(final StmtContext.Mutable<A, D, E> stmt) {
97         // NOOP for most implementations
98     }
99
100     /**
101      * {@inheritDoc}
102      *
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)}.
106      */
107     @Override
108     public void onStatementDefinitionDeclared(final StmtContext.Mutable<A, D, E> stmt) {
109         // NOOP for most implementations
110     }
111
112     /**
113      * {@inheritDoc}
114      *
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)}.
118      */
119     @Override
120     public void onFullDefinitionDeclared(final StmtContext.Mutable<A, D, E> stmt) {
121         final SubstatementValidator validator = getSubstatementValidator();
122         if (validator != null) {
123             validator.validate(stmt);
124         }
125     }
126
127     @Override
128     public boolean isArgumentYinElement() {
129         return getPublicView().isArgumentYinElement();
130     }
131
132     /**
133      * Returns corresponding substatement validator of a statement support
134      *
135      * @return substatement validator or null, if substatement validator is not
136      *         defined
137      */
138     @Nullable
139     protected abstract SubstatementValidator getSubstatementValidator();
140 }