2 * Copyright (c) 2017 Pantheon Technologies, s.r.o. 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.rfc7950.stmt.type;
10 import com.google.common.collect.ImmutableList;
11 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
12 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
13 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
14 import org.opendaylight.yangtools.yang.model.api.stmt.PathEffectiveStatement;
15 import org.opendaylight.yangtools.yang.model.api.stmt.RequireInstanceEffectiveStatement;
16 import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement.LeafrefSpecification;
17 import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
18 import org.opendaylight.yangtools.yang.model.util.type.LeafrefTypeBuilder;
19 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseStatementSupport;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.CommonStmtCtx;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
23 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
25 abstract class AbstractLeafrefSpecificationSupport
26 extends BaseStatementSupport<String, LeafrefSpecification, EffectiveStatement<String, LeafrefSpecification>> {
27 AbstractLeafrefSpecificationSupport() {
28 super(YangStmtMapping.TYPE);
32 public final String parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
37 protected final LeafrefSpecification createDeclared(final StmtContext<String, LeafrefSpecification, ?> ctx,
38 final ImmutableList<? extends DeclaredStatement<?>> substatements) {
39 return new LeafrefSpecificationImpl(ctx.getRawArgument(), substatements);
43 protected final LeafrefSpecification createEmptyDeclared(final StmtContext<String, LeafrefSpecification, ?> ctx) {
48 protected EffectiveStatement<String, LeafrefSpecification> createEffective(
49 final Current<String, LeafrefSpecification> stmt,
50 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
51 if (substatements.isEmpty()) {
55 final LeafrefTypeBuilder builder = BaseTypes.leafrefTypeBuilder(stmt.wrapSchemaPath());
57 for (final EffectiveStatement<?, ?> subStmt : substatements) {
58 if (subStmt instanceof PathEffectiveStatement) {
59 builder.setPathStatement(((PathEffectiveStatement) subStmt).argument());
60 } else if (subStmt instanceof RequireInstanceEffectiveStatement) {
61 builder.setRequireInstance(((RequireInstanceEffectiveStatement)subStmt).argument());
65 return new TypeEffectiveStatementImpl<>(stmt.declared(), substatements, builder);
68 private static SourceException noPath(final CommonStmtCtx stmt) {
70 * https://tools.ietf.org/html/rfc7950#section-9.12
72 * When the type is "union", the "type" statement (Section 7.4) MUST be
75 return new SourceException("A path statement has to be present", stmt);