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.RequireInstanceEffectiveStatement;
15 import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement.InstanceIdentifierSpecification;
16 import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
17 import org.opendaylight.yangtools.yang.model.util.type.InstanceIdentifierTypeBuilder;
18 import org.opendaylight.yangtools.yang.model.util.type.RestrictedTypes;
19 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseStatementSupport;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
23 final class InstanceIdentifierSpecificationSupport extends BaseStatementSupport<String,
24 InstanceIdentifierSpecification, EffectiveStatement<String, InstanceIdentifierSpecification>> {
25 private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(
27 .addOptional(YangStmtMapping.REQUIRE_INSTANCE)
30 InstanceIdentifierSpecificationSupport() {
31 super(YangStmtMapping.TYPE);
35 public String parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
40 protected SubstatementValidator getSubstatementValidator() {
41 return SUBSTATEMENT_VALIDATOR;
45 protected InstanceIdentifierSpecification createDeclared(
46 final StmtContext<String, InstanceIdentifierSpecification, ?> ctx,
47 final ImmutableList<? extends DeclaredStatement<?>> substatements) {
48 return new RegularInstanceIdentifierSpecification(ctx, substatements);
52 protected InstanceIdentifierSpecification createEmptyDeclared(
53 final StmtContext<String, InstanceIdentifierSpecification, ?> ctx) {
54 return new EmptyIdentifierSpecification(ctx);
58 protected EffectiveStatement<String, InstanceIdentifierSpecification> createEffective(
59 final StmtContext<String, InstanceIdentifierSpecification,
60 EffectiveStatement<String, InstanceIdentifierSpecification>> ctx,
61 final InstanceIdentifierSpecification declared,
62 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
63 final InstanceIdentifierTypeBuilder builder = RestrictedTypes.newInstanceIdentifierBuilder(
64 BaseTypes.instanceIdentifierType(), ctx.getSchemaPath().get());
66 for (EffectiveStatement<?, ?> stmt : substatements) {
67 if (stmt instanceof RequireInstanceEffectiveStatement) {
68 builder.setRequireInstance(((RequireInstanceEffectiveStatement)stmt).argument());
72 return new TypeEffectiveStatementImpl<>(declared, substatements, builder);
76 protected EffectiveStatement<String, InstanceIdentifierSpecification> createEmptyEffective(
77 final StmtContext<String, InstanceIdentifierSpecification,
78 EffectiveStatement<String, InstanceIdentifierSpecification>> ctx,
79 final InstanceIdentifierSpecification declared) {
80 // TODO: we could do better here, but its really splitting hairs
81 return createEffective(ctx, declared, ImmutableList.of());