YANGTOOLS-706: Split up base utility classes into rfc6020.util
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / effective / type / IdentityRefSpecificationEffectiveStatementImpl.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type;
9
10 import javax.annotation.Nonnull;
11 import org.opendaylight.yangtools.yang.common.QName;
12 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
13 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
14 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
15 import org.opendaylight.yangtools.yang.model.api.stmt.BaseEffectiveStatement;
16 import org.opendaylight.yangtools.yang.model.api.stmt.IdentityStatement;
17 import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement;
18 import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement.IdentityRefSpecification;
19 import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
20 import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
21 import org.opendaylight.yangtools.yang.model.util.type.IdentityrefTypeBuilder;
22 import org.opendaylight.yangtools.yang.parser.rfc6020.util.DeclaredEffectiveStatementBase;
23 import org.opendaylight.yangtools.yang.parser.spi.IdentityNamespace;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
25
26 public final class IdentityRefSpecificationEffectiveStatementImpl extends
27         DeclaredEffectiveStatementBase<String, IdentityRefSpecification> implements
28         TypeEffectiveStatement<IdentityRefSpecification> {
29
30     private final IdentityrefTypeDefinition typeDefinition;
31
32     public IdentityRefSpecificationEffectiveStatementImpl(final StmtContext<String, IdentityRefSpecification,
33             EffectiveStatement<String, IdentityRefSpecification>> ctx) {
34         super(ctx);
35
36         final IdentityrefTypeBuilder builder = BaseTypes.identityrefTypeBuilder(ctx.getSchemaPath().get());
37         for (final EffectiveStatement<?, ?> stmt : effectiveSubstatements()) {
38             if (stmt instanceof BaseEffectiveStatement) {
39                 final QName identityQName = ((BaseEffectiveStatement) stmt).argument();
40                 final StmtContext<?, IdentityStatement, EffectiveStatement<QName, IdentityStatement>> identityCtx =
41                         ctx.getFromNamespace(IdentityNamespace.class, identityQName);
42                 builder.addIdentity((IdentitySchemaNode) identityCtx.buildEffective());
43             }
44             if (stmt instanceof UnknownSchemaNode) {
45                 builder.addUnknownSchemaNode((UnknownSchemaNode)stmt);
46             }
47         }
48
49         typeDefinition = builder.build();
50     }
51
52     @Nonnull
53     @Override
54     public IdentityrefTypeDefinition getTypeDefinition() {
55         return typeDefinition;
56     }
57 }