Propagate @Nonnull and @Nullable annotations
[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.meta.EffectiveStatement;
14 import org.opendaylight.yangtools.yang.model.api.stmt.IdentityStatement;
15 import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement;
16 import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement.IdentityRefSpecification;
17 import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
18 import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
19 import org.opendaylight.yangtools.yang.model.util.type.IdentityrefTypeBuilder;
20 import org.opendaylight.yangtools.yang.parser.spi.IdentityNamespace;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
22 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.BaseEffectiveStatementImpl;
23 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.DeclaredEffectiveStatementBase;
24 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.UnknownEffectiveStatementImpl;
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(
33             final StmtContext<String, IdentityRefSpecification, 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 BaseEffectiveStatementImpl) {
39                 final BaseEffectiveStatementImpl base = firstEffective(BaseEffectiveStatementImpl.class);
40                 final QName identityQName = base.argument();
41                 final StmtContext<?, IdentityStatement, EffectiveStatement<QName, IdentityStatement>> identityCtx =
42                         ctx.getFromNamespace(IdentityNamespace.class, identityQName);
43                 builder.setIdentity((IdentitySchemaNode) identityCtx.buildEffective());
44             }
45             if (stmt instanceof UnknownEffectiveStatementImpl) {
46                 builder.addUnknownSchemaNode((UnknownEffectiveStatementImpl)stmt);
47             }
48         }
49
50         typeDefinition = builder.build();
51     }
52
53     @Nonnull
54     @Override
55     public IdentityrefTypeDefinition getTypeDefinition() {
56         return typeDefinition;
57     }
58 }