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 com.google.common.base.Preconditions;
11 import java.util.Collection;
12 import javax.annotation.Nonnull;
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
15 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
16 import org.opendaylight.yangtools.yang.model.api.stmt.BaseStatement;
17 import org.opendaylight.yangtools.yang.model.api.stmt.IdentityStatement;
18 import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
19 import org.opendaylight.yangtools.yang.parser.spi.IdentityNamespace;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
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> implements TypeStatement.IdentityRefSpecification {
28 private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(YangStmtMapping
30 .addMandatory(YangStmtMapping.BASE)
33 protected IdentityRefSpecificationImpl(
34 final StmtContext<String, TypeStatement.IdentityRefSpecification, ?> context) {
38 public static class Definition
40 AbstractStatementSupport<String, TypeStatement.IdentityRefSpecification, EffectiveStatement<String, TypeStatement.IdentityRefSpecification>> {
43 super(YangStmtMapping.TYPE);
47 public String parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
52 public TypeStatement.IdentityRefSpecification createDeclared(
53 final StmtContext<String, TypeStatement.IdentityRefSpecification, ?> ctx) {
54 return new IdentityRefSpecificationImpl(ctx);
58 public EffectiveStatement<String, TypeStatement.IdentityRefSpecification> createEffective(
59 final StmtContext<String, TypeStatement.IdentityRefSpecification, EffectiveStatement<String, TypeStatement
60 .IdentityRefSpecification>> ctx) {
61 return new IdentityRefSpecificationEffectiveStatementImpl(ctx);
65 public void onFullDefinitionDeclared(final StmtContext.Mutable<String, IdentityRefSpecification,
66 EffectiveStatement<String, IdentityRefSpecification>> stmt) {
67 super.onFullDefinitionDeclared(stmt);
69 final Collection<StmtContext<QName, BaseStatement, ?>> baseStatements =
70 StmtContextUtils.<QName, BaseStatement>findAllDeclaredSubstatements(stmt, BaseStatement.class);
72 for (StmtContext<QName, BaseStatement, ?> baseStmt : baseStatements) {
73 final QName baseIdentity = baseStmt.getStatementArgument();
74 final StmtContext<?, IdentityStatement, EffectiveStatement<QName, IdentityStatement>> stmtCtx =
75 stmt.getFromNamespace(IdentityNamespace.class, baseIdentity);
76 Preconditions.checkArgument(stmtCtx != null, "Referenced base identity '%s' doesn't exist " +
77 "in given scope (module, imported modules, submodules), source: '%s'",
78 baseIdentity.getLocalName(), stmt.getStatementSourceReference());
83 protected SubstatementValidator getSubstatementValidator() {
84 return SUBSTATEMENT_VALIDATOR;
90 public String getName() {
96 public BaseStatement getBase() {
97 return firstDeclared(BaseStatement.class);
102 public Collection<? extends BaseStatement> getBases() {
103 return allDeclared(BaseStatement.class);