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.stmt.rfc6020;
10 import java.util.Collection;
11 import javax.annotation.Nonnull;
12 import org.opendaylight.yangtools.yang.common.QName;
13 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
14 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
15 import org.opendaylight.yangtools.yang.model.api.stmt.BaseStatement;
16 import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement.IdentityRefSpecification;
17 import org.opendaylight.yangtools.yang.parser.spi.IdentityNamespace;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
25 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.IdentityRefSpecificationEffectiveStatementImpl;
27 public class IdentityRefSpecificationImpl extends AbstractDeclaredStatement<String>
28 implements IdentityRefSpecification {
29 private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(YangStmtMapping
31 .addMandatory(YangStmtMapping.BASE)
34 protected IdentityRefSpecificationImpl(final StmtContext<String, IdentityRefSpecification, ?> context) {
38 public static class Definition extends AbstractStatementSupport<String, IdentityRefSpecification,
39 EffectiveStatement<String, IdentityRefSpecification>> {
42 super(YangStmtMapping.TYPE);
46 public String parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
51 public IdentityRefSpecification createDeclared(final StmtContext<String, IdentityRefSpecification, ?> ctx) {
52 return new IdentityRefSpecificationImpl(ctx);
56 public EffectiveStatement<String, IdentityRefSpecification> createEffective(
57 final StmtContext<String, IdentityRefSpecification,
58 EffectiveStatement<String, IdentityRefSpecification>> ctx) {
59 return new IdentityRefSpecificationEffectiveStatementImpl(ctx);
63 public void onFullDefinitionDeclared(final Mutable<String, IdentityRefSpecification,
64 EffectiveStatement<String, IdentityRefSpecification>> stmt) {
65 super.onFullDefinitionDeclared(stmt);
67 final Collection<StmtContext<QName, BaseStatement, ?>> baseStatements =
68 StmtContextUtils.<QName, BaseStatement>findAllDeclaredSubstatements(stmt, BaseStatement.class);
69 for (StmtContext<QName, BaseStatement, ?> baseStmt : baseStatements) {
70 final QName baseIdentity = baseStmt.getStatementArgument();
71 final StmtContext<?, ?, ?> stmtCtx = stmt.getFromNamespace(IdentityNamespace.class, baseIdentity);
72 InferenceException.throwIfNull(stmtCtx, stmt.getStatementSourceReference(),
73 "Referenced base identity '%s' doesn't exist in given scope (module, imported modules, submodules)",
74 baseIdentity.getLocalName());
79 protected SubstatementValidator getSubstatementValidator() {
80 return SUBSTATEMENT_VALIDATOR;
86 public String getName() {
92 public Collection<? extends BaseStatement> getBases() {
93 return allDeclared(BaseStatement.class);