/* * 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 javax.annotation.Nonnull; import javax.annotation.Nullable; import org.opendaylight.yangtools.yang.common.QName; 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 StatementDefinition type; protected AbstractStatementSupport(final StatementDefinition publicDefinition) { this.type = requireNonNull(publicDefinition); checkArgument(publicDefinition != this); } @Nonnull @Override public final QName getStatementName() { return type.getStatementName(); } @Override public final QName getArgumentName() { return type.getArgumentName(); } @Nonnull @Override public final Class> getDeclaredRepresentationClass() { return type.getDeclaredRepresentationClass(); } @Nonnull @Override public final Class> getEffectiveRepresentationClass() { return type.getEffectiveRepresentationClass(); } @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 isArgumentYinElement() { return getPublicView().isArgumentYinElement(); } @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 */ @Nullable protected abstract SubstatementValidator getSubstatementValidator(); }