c376d7d71404b85e4911ab4fecaba358b19d00eb
[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 org.opendaylight.yangtools.yang.common.QName;
11 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
12 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
13 import org.opendaylight.yangtools.yang.model.api.stmt.IdentityStatement;
14 import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement;
15 import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement.IdentityRefSpecification;
16 import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
17 import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
18 import org.opendaylight.yangtools.yang.model.util.type.IdentityrefTypeBuilder;
19 import org.opendaylight.yangtools.yang.parser.spi.IdentityNamespace;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
21 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.BaseEffectiveStatementImpl;
22 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.DeclaredEffectiveStatementBase;
23 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.UnknownEffectiveStatementImpl;
24
25 public final class IdentityRefSpecificationEffectiveStatementImpl extends
26         DeclaredEffectiveStatementBase<String, IdentityRefSpecification> implements
27         TypeEffectiveStatement<IdentityRefSpecification> {
28
29     private final IdentityrefTypeDefinition typeDefinition;
30
31     public IdentityRefSpecificationEffectiveStatementImpl(
32             final StmtContext<String, IdentityRefSpecification, EffectiveStatement<String, IdentityRefSpecification>> ctx) {
33         super(ctx);
34
35         final IdentityrefTypeBuilder builder = BaseTypes.identityrefTypeBuilder(ctx.getSchemaPath().get());
36         for (final EffectiveStatement<?, ?> stmt : effectiveSubstatements()) {
37             if (stmt instanceof BaseEffectiveStatementImpl) {
38                 final BaseEffectiveStatementImpl base = firstEffective(BaseEffectiveStatementImpl.class);
39                 final QName identityQName = base.argument();
40                 final StmtContext<?, IdentityStatement, EffectiveStatement<QName, IdentityStatement>> identityCtx =
41                         ctx.getFromNamespace(IdentityNamespace.class, identityQName);
42                 builder.setIdentity((IdentitySchemaNode) identityCtx.buildEffective());
43             }
44             if (stmt instanceof UnknownEffectiveStatementImpl) {
45                 builder.addUnknownSchemaNode((UnknownEffectiveStatementImpl)stmt);
46             }
47         }
48
49         typeDefinition = builder.build();
50     }
51
52     @Override
53     public IdentityrefTypeDefinition getTypeDefinition() {
54         return typeDefinition;
55     }
56 }