/* * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.yangtools.yang.parser.spi.meta; import static com.google.common.base.Preconditions.checkArgument; import static java.util.Objects.requireNonNull; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement; import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement; import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition; /** * Class providing necessary support for processing a YANG statement. This class is intended to be subclassed * by developers who want to add semantic support for a statement to a parser reactor. * * @param Argument type * @param Declared Statement representation * @param Effective Statement representation */ public abstract class AbstractStatementSupport, E extends EffectiveStatement> implements StatementDefinition, StatementFactory, StatementSupport { private final @NonNull StatementDefinition type; protected AbstractStatementSupport(final StatementDefinition publicDefinition) { this.type = requireNonNull(publicDefinition); checkArgument(publicDefinition != this); } @Override public final StatementDefinition getPublicView() { return type; } @Override public void onStatementAdded(final StmtContext.Mutable stmt) { // NOOP for most implementations } /** * {@inheritDoc}. * *

* Subclasses of this class may override this method to perform actions on this event or register a modification * action using {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}. */ @Override public void onPreLinkageDeclared(final StmtContext.Mutable stmt) { // NOOP for most implementations } /** * {@inheritDoc}. * *

* Subclasses of this class may override this method to perform actions on this event or register a modification * action using {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}. */ @Override public void onLinkageDeclared(final StmtContext.Mutable stmt) { // NOOP for most implementations } /** * {@inheritDoc}. * *

* Subclasses of this class may override this method to perform actions on this event or register a modification * action using {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}. */ @Override public void onStatementDefinitionDeclared(final StmtContext.Mutable stmt) { // NOOP for most implementations } /** * {@inheritDoc}. * *

* Subclasses of this class may override this method to perform actions on this event or register a modification * action using {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}. */ @Override public void onFullDefinitionDeclared(final StmtContext.Mutable stmt) { final SubstatementValidator validator = getSubstatementValidator(); if (validator != null) { validator.validate(stmt); } } @Override public boolean hasArgumentSpecificSupports() { // Most of statement supports don't have any argument specific // supports, so return 'false'. return false; } @Override public StatementSupport getSupportSpecificForArgument(final String argument) { // Most of statement supports don't have any argument specific // supports, so return null. return null; } /** * Returns corresponding substatement validator of a statement support. * * @return substatement validator or null, if substatement validator is not defined */ protected abstract @Nullable SubstatementValidator getSubstatementValidator(); }