2 * Copyright (c) 2015 Cisco Systems, Inc. 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.stmt.rfc6020;
10 import java.util.Collection;
11 import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
13 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.InferenceAction;
14 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.Prerequisite;
15 import org.opendaylight.yangtools.yang.parser.spi.IdentityNamespace;
16 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.DerivedIdentitiesNamespace;
19 import java.util.LinkedList;
20 import java.util.List;
21 import org.opendaylight.yangtools.yang.model.api.stmt.IdentityStatement;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
24 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
25 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.BaseEffectiveStatementImpl;
26 import org.opendaylight.yangtools.yang.common.QName;
27 import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
28 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
29 import org.opendaylight.yangtools.yang.model.api.stmt.BaseStatement;
30 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
31 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
32 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
34 public class BaseStatementImpl extends AbstractDeclaredStatement<QName>
35 implements BaseStatement {
37 protected BaseStatementImpl(StmtContext<QName, BaseStatement, ?> context) {
41 public static class Definition
43 AbstractStatementSupport<QName, BaseStatement, EffectiveStatement<QName, BaseStatement>> {
46 super(Rfc6020Mapping.BASE);
50 public QName parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
51 return Utils.qNameFromArgument(ctx, value);
55 public BaseStatement createDeclared(
56 StmtContext<QName, BaseStatement, ?> ctx) {
57 return new BaseStatementImpl(ctx);
61 public EffectiveStatement<QName, BaseStatement> createEffective(
62 StmtContext<QName, BaseStatement, EffectiveStatement<QName, BaseStatement>> ctx) {
63 return new BaseEffectiveStatementImpl(ctx);
67 public void onStatementDefinitionDeclared(
68 final Mutable<QName, BaseStatement, EffectiveStatement<QName, BaseStatement>> baseStmtCtx)
69 throws SourceException {
70 final Mutable<?, ?, ?> baseParentCtx = baseStmtCtx.getParentContext();
71 if(StmtContextUtils.producesDeclared(baseParentCtx, IdentityStatement.class)) {
73 final QName baseIdentityQName = baseStmtCtx.getStatementArgument();
74 ModelActionBuilder baseIdentityAction = baseStmtCtx.newInferenceAction(ModelProcessingPhase.STATEMENT_DEFINITION);
75 final Prerequisite<StmtContext<?, ?, ?>> requiresPrereq = baseIdentityAction.requiresCtx(baseStmtCtx, IdentityNamespace.class, baseIdentityQName, ModelProcessingPhase.STATEMENT_DEFINITION);
76 final Prerequisite<?> mutatesPrereq = baseIdentityAction.mutatesCtx(baseParentCtx, ModelProcessingPhase.STATEMENT_DEFINITION);
78 baseIdentityAction.apply( new InferenceAction() {
81 public void apply() throws InferenceException {
82 List<StmtContext<?, ?, ?>> derivedIdentities = baseStmtCtx.getFromNamespace(DerivedIdentitiesNamespace.class, baseStmtCtx.getStatementArgument());
83 if(derivedIdentities == null) {
84 derivedIdentities = new LinkedList<>();
85 baseStmtCtx.addToNs(DerivedIdentitiesNamespace.class, baseIdentityQName, derivedIdentities);
87 derivedIdentities.add(baseParentCtx);
91 public void prerequisiteFailed(
92 Collection<? extends Prerequisite<?>> failed)
93 throws InferenceException {
94 throw new InferenceException("Unable to resolve identity "+baseParentCtx.getStatementArgument()+" and base identity " + baseStmtCtx.getStatementArgument(), baseStmtCtx
95 .getStatementSourceReference());
104 public QName getName() {