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.Rfc6020Mapping;
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.spi.source.SourceException;
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(Rfc6020Mapping
30 .add(Rfc6020Mapping.BASE, 1, 1)
33 protected IdentityRefSpecificationImpl(
34 StmtContext<String, TypeStatement.IdentityRefSpecification, ?> context) {
38 public static class Definition
40 AbstractStatementSupport<String, TypeStatement.IdentityRefSpecification, EffectiveStatement<String, TypeStatement.IdentityRefSpecification>> {
43 super(Rfc6020Mapping.TYPE);
47 public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value)
48 throws SourceException {
53 public TypeStatement.IdentityRefSpecification createDeclared(
54 StmtContext<String, TypeStatement.IdentityRefSpecification, ?> ctx) {
55 return new IdentityRefSpecificationImpl(ctx);
59 public EffectiveStatement<String, TypeStatement.IdentityRefSpecification> createEffective(
60 StmtContext<String, TypeStatement.IdentityRefSpecification, EffectiveStatement<String, TypeStatement
61 .IdentityRefSpecification>> ctx) {
62 return new IdentityRefSpecificationEffectiveStatementImpl(ctx);
66 public void onFullDefinitionDeclared(StmtContext.Mutable<String, IdentityRefSpecification,
67 EffectiveStatement<String, IdentityRefSpecification>> stmt) throws SourceException {
68 final StmtContext<QName, ?, ?> baseStmt = StmtContextUtils.findFirstDeclaredSubstatement(stmt,
70 Preconditions.checkArgument(baseStmt != null, "The \"base\" statement, which is a substatement to the " +
71 "\"type\"\n statement, MUST be present if the type is \"identityref\" in source '%s'", stmt
72 .getStatementSourceReference());
73 final QName baseIdentity = baseStmt.getStatementArgument();
74 final StmtContext<?, IdentityStatement, EffectiveStatement<QName, IdentityStatement>> stmtCtx = stmt
75 .getFromNamespace(IdentityNamespace.class, baseIdentity);
76 Preconditions.checkArgument(stmtCtx != null, "Referenced base identity '%s' doesn't exist " +
77 "in " + "given scope " + "(module, imported submodules), source: '%s'", baseIdentity
78 .getLocalName(), stmt.getStatementSourceReference());
82 public void onStatementDefinitionDeclared(StmtContext.Mutable<String, IdentityRefSpecification,
83 EffectiveStatement<String, IdentityRefSpecification>> stmt) throws SourceException {
84 super.onStatementDefinitionDeclared(stmt);
85 SUBSTATEMENT_VALIDATOR.validate(stmt);
90 public String getName() {
96 public BaseStatement getBase() {
97 return firstDeclared(BaseStatement.class);