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 static org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase.FULL_DECLARATION;
12 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.UsesEffectiveStatementImpl;
13 import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
14 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
15 import java.util.Collection;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
18 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
19 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
20 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
21 import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
22 import org.opendaylight.yangtools.yang.model.api.stmt.AugmentStatement;
23 import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
24 import org.opendaylight.yangtools.yang.model.api.stmt.IfFeatureStatement;
25 import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
26 import org.opendaylight.yangtools.yang.model.api.stmt.RefineStatement;
27 import org.opendaylight.yangtools.yang.model.api.stmt.StatusStatement;
28 import org.opendaylight.yangtools.yang.model.api.stmt.UsesStatement;
29 import org.opendaylight.yangtools.yang.model.api.stmt.WhenStatement;
30 import org.opendaylight.yangtools.yang.parser.spi.GroupingNamespace;
31 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
32 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
33 import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
34 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder;
35 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.InferenceAction;
36 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.Prerequisite;
37 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
39 public class UsesStatementImpl extends AbstractDeclaredStatement<QName>
40 implements UsesStatement {
42 protected UsesStatementImpl(StmtContext<QName, UsesStatement, ?> context) {
46 public static class Definition
48 AbstractStatementSupport<QName, UsesStatement, EffectiveStatement<QName, UsesStatement>> {
51 super(Rfc6020Mapping.USES);
55 public QName parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
56 return Utils.qNameFromArgument(ctx, value);
60 public void onFullDefinitionDeclared(final StmtContext.Mutable<QName,UsesStatement,EffectiveStatement<QName,UsesStatement>> usesNode) throws InferenceException ,SourceException {
62 ModelActionBuilder usesAction = usesNode.newInferenceAction(FULL_DECLARATION);
63 final QName groupingName = usesNode.getStatementArgument();
65 final Prerequisite<StmtContext<?, ?, ?>> sourceGroupingPre = usesAction.requiresCtx(usesNode, GroupingNamespace.class, groupingName, FULL_DECLARATION);
66 final Prerequisite< ?extends StmtContext.Mutable<?,?,?>> targetNodePre = usesAction.mutatesCtx(usesNode.getParentContext(), FULL_DECLARATION);
68 usesAction.apply(new InferenceAction() {
71 public void apply() throws InferenceException {
72 StatementContextBase<?, ?, ?> targetNodeStmtCtx = (StatementContextBase<?, ?, ?>) targetNodePre.get();
73 StatementContextBase<?, ?, ?> sourceGrpStmtCtx = (StatementContextBase<?, ?, ?>) sourceGroupingPre.get();
76 GroupingUtils.copyFromSourceToTarget(sourceGrpStmtCtx,targetNodeStmtCtx);
77 GroupingUtils.resolveUsesNode(usesNode, targetNodeStmtCtx);
78 } catch (SourceException e) {
79 // TODO Auto-generated catch block
85 public void prerequisiteFailed(Collection<? extends Prerequisite<?>> failed) throws InferenceException {
86 if(failed.contains(sourceGroupingPre)) {
87 throw new InferenceException("Grouping " + groupingName + " was not resoled.", usesNode.getStatementSourceReference());
89 throw new InferenceException("Unknown error occured.", usesNode.getStatementSourceReference());
97 public UsesStatement createDeclared(
98 StmtContext<QName, UsesStatement, ?> ctx) {
99 return new UsesStatementImpl(ctx);
103 public EffectiveStatement<QName, UsesStatement> createEffective(
104 StmtContext<QName, UsesStatement, EffectiveStatement<QName, UsesStatement>> ctx) {
105 return new UsesEffectiveStatementImpl(ctx);
111 public QName getName() {
116 public WhenStatement getWhenStatement() {
117 return firstDeclared(WhenStatement.class);
121 public Collection<? extends IfFeatureStatement> getIfFeatures() {
122 return allDeclared(IfFeatureStatement.class);
126 public StatusStatement getStatus() {
127 return firstDeclared(StatusStatement.class);
131 public DescriptionStatement getDescription() {
132 return firstDeclared(DescriptionStatement.class);
136 public ReferenceStatement getReference() {
137 return firstDeclared(ReferenceStatement.class);
141 public Collection<? extends AugmentStatement> getAugments() {
142 return allDeclared(AugmentStatement.class);
146 public Collection<? extends RefineStatement> getRefines() {
147 return allDeclared(RefineStatement.class);
151 public QName argument() {
152 // TODO Auto-generated method stub
157 public String rawArgument() {
158 // TODO Auto-generated method stub
163 public Collection<? extends DeclaredStatement<?>> declaredSubstatements() {
164 // TODO Auto-generated method stub
169 public StatementDefinition statementDefinition() {
170 // TODO Auto-generated method stub
175 public StatementSource getStatementSource() {
176 // TODO Auto-generated method stub