2 * Copyright (c) 2017 Pantheon Technologies, s.r.o. 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.rfc7950.stmt.extension;
10 import com.google.common.collect.ImmutableList;
11 import java.util.Optional;
12 import org.opendaylight.yangtools.yang.common.QName;
13 import org.opendaylight.yangtools.yang.model.api.meta.ArgumentDefinition;
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.model.api.stmt.UnrecognizedStatement;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupport;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
26 final class UnrecognizedStatementSupport
27 extends AbstractStatementSupport<Object, UnrecognizedStatement, UnrecognizedEffectiveStatement> {
28 UnrecognizedStatementSupport(final StatementDefinition publicDefinition) {
29 // We have no idea about the statement's semantics, hence there should be noone interested in its semantics.
30 // Nevertheless it may be of interest for various hacks to understand there was an extension involved.
31 super(publicDefinition, StatementPolicy.exactReplica());
35 public String parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
40 public Optional<StatementSupport<?, ?, ?>> getUnknownStatementDefinitionOf(
41 final StatementDefinition yangStmtDef) {
42 final QName baseQName = getStatementName();
43 final QName statementName = QName.create(baseQName, yangStmtDef.getStatementName().getLocalName());
45 final ModelDefinedStatementDefinition def;
46 final Optional<ArgumentDefinition> optArgDef = yangStmtDef.getArgumentDefinition();
47 if (optArgDef.isPresent()) {
48 final ArgumentDefinition argDef = optArgDef.get();
49 def = new ModelDefinedStatementDefinition(statementName, argDef.getArgumentName(), argDef.isYinElement());
51 def = new ModelDefinedStatementDefinition(statementName);
53 return Optional.of(new UnrecognizedStatementSupport(def));
57 protected SubstatementValidator getSubstatementValidator() {
58 // We know nothing about this statement
63 protected UnrecognizedStatement createDeclared(final StmtContext<Object, UnrecognizedStatement, ?> ctx,
64 final ImmutableList<? extends DeclaredStatement<?>> substatements) {
65 return new UnrecognizedStatementImpl(ctx.rawArgument(), ctx.publicDefinition(), substatements);
68 // createEffective() should never be called, ensure that for each declared statement
71 public void onStatementAdded(final Mutable<Object, UnrecognizedStatement, UnrecognizedEffectiveStatement> stmt) {
72 stmt.setIsSupportedToBuildEffective(false);
76 protected UnrecognizedEffectiveStatement createEffective(final Current<Object, UnrecognizedStatement> stmt,
77 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
78 throw new InferenceException(stmt, "Attempted to instantiate unrecognized effective statement %s",
79 stmt.publicDefinition());