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 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.IdentityStatement;
17 import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
18 import org.opendaylight.yangtools.yang.parser.spi.IdentityNamespace;
19 import org.opendaylight.yangtools.yang.parser.spi.SubstatementValidator;
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.stmt.rfc6020.effective.type.IdentityRefSpecificationEffectiveStatementImpl;
26 public class IdentityRefSpecificationImpl extends AbstractDeclaredStatement<String> implements TypeStatement.IdentityRefSpecification {
27 private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(YangStmtMapping
29 .addMandatory(YangStmtMapping.BASE)
32 protected IdentityRefSpecificationImpl(
33 final StmtContext<String, TypeStatement.IdentityRefSpecification, ?> context) {
37 public static class Definition
39 AbstractStatementSupport<String, TypeStatement.IdentityRefSpecification, EffectiveStatement<String, TypeStatement.IdentityRefSpecification>> {
42 super(YangStmtMapping.TYPE);
46 public String parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
51 public TypeStatement.IdentityRefSpecification createDeclared(
52 final StmtContext<String, TypeStatement.IdentityRefSpecification, ?> ctx) {
53 return new IdentityRefSpecificationImpl(ctx);
57 public EffectiveStatement<String, TypeStatement.IdentityRefSpecification> createEffective(
58 final StmtContext<String, TypeStatement.IdentityRefSpecification, EffectiveStatement<String, TypeStatement
59 .IdentityRefSpecification>> ctx) {
60 return new IdentityRefSpecificationEffectiveStatementImpl(ctx);
64 public void onFullDefinitionDeclared(final StmtContext.Mutable<String, IdentityRefSpecification,
65 EffectiveStatement<String, IdentityRefSpecification>> stmt) {
66 final StmtContext<QName, ?, ?> baseStmt = StmtContextUtils.findFirstDeclaredSubstatement(stmt,
68 Preconditions.checkArgument(baseStmt != null, "The \"base\" statement, which is a substatement to the " +
69 "\"type\"\n statement, MUST be present if the type is \"identityref\" in source '%s'", stmt
70 .getStatementSourceReference());
71 final QName baseIdentity = baseStmt.getStatementArgument();
72 final StmtContext<?, IdentityStatement, EffectiveStatement<QName, IdentityStatement>> stmtCtx = stmt
73 .getFromNamespace(IdentityNamespace.class, baseIdentity);
74 Preconditions.checkArgument(stmtCtx != null, "Referenced base identity '%s' doesn't exist " +
75 "in " + "given scope " + "(module, imported submodules), source: '%s'", baseIdentity
76 .getLocalName(), stmt.getStatementSourceReference());
80 public void onStatementDefinitionDeclared(final StmtContext.Mutable<String, IdentityRefSpecification,
81 EffectiveStatement<String, IdentityRefSpecification>> stmt) {
82 super.onStatementDefinitionDeclared(stmt);
83 SUBSTATEMENT_VALIDATOR.validate(stmt);
89 public String getName() {
95 public BaseStatement getBase() {
96 return firstDeclared(BaseStatement.class);