Bug 4640: Change semantic-version to openconfig-version
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / effective / type / LeafrefSpecificationEffectiveStatementImpl.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.model.api.meta.EffectiveStatement;
12 import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement;
13 import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement.LeafrefSpecification;
14 import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
15 import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
16 import org.opendaylight.yangtools.yang.model.util.type.LeafrefTypeBuilder;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
18 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.DeclaredEffectiveStatementBase;
19 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.PathEffectiveStatementImpl;
20 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.RequireInstanceEffectiveStatementImpl;
21 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.UnknownEffectiveStatementImpl;
22
23 public final class LeafrefSpecificationEffectiveStatementImpl extends DeclaredEffectiveStatementBase<String, LeafrefSpecification>
24         implements TypeEffectiveStatement<LeafrefSpecification> {
25
26     private final LeafrefTypeDefinition typeDefinition;
27
28     public LeafrefSpecificationEffectiveStatementImpl(final StmtContext<String, LeafrefSpecification, EffectiveStatement<String, LeafrefSpecification>> ctx) {
29         super(ctx);
30
31         final LeafrefTypeBuilder builder = BaseTypes.leafrefTypeBuilder(ctx.getSchemaPath().get());
32
33         for (final EffectiveStatement<?, ?> stmt : effectiveSubstatements()) {
34             if (stmt instanceof PathEffectiveStatementImpl) {
35                 builder.setPathStatement(((PathEffectiveStatementImpl) stmt).argument());
36             } else if(stmt instanceof RequireInstanceEffectiveStatementImpl) {
37                 builder.setRequireInstance(((RequireInstanceEffectiveStatementImpl)stmt).argument());
38             } else if (stmt instanceof UnknownEffectiveStatementImpl) {
39                 builder.addUnknownSchemaNode((UnknownEffectiveStatementImpl)stmt);
40             }
41         }
42
43         typeDefinition = builder.build();
44     }
45
46     @Nonnull
47     @Override
48     public LeafrefTypeDefinition getTypeDefinition() {
49         return typeDefinition;
50     }
51 }