import java.util.Collection;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
-import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
-import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
import org.opendaylight.yangtools.yang.model.api.stmt.AugmentStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.GroupingStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.IfFeatureStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.RefineStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.Prerequisite;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
-import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.UsesEffectiveStatementImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
public class UsesStatementImpl extends AbstractDeclaredStatement<QName> implements UsesStatement {
- protected UsesStatementImpl(StmtContext<QName, UsesStatement, ?> context) {
+ private static final Logger LOG = LoggerFactory.getLogger(UsesStatementImpl.class);
+
+ protected UsesStatementImpl(final StmtContext<QName, UsesStatement, ?> context) {
super(context);
}
AbstractStatementSupport<QName, UsesStatement, EffectiveStatement<QName, UsesStatement>> {
public Definition() {
- super(Rfc6020Mapping.Uses);
+ super(Rfc6020Mapping.USES);
}
@Override
- public QName parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
+ public QName parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
return Utils.qNameFromArgument(ctx, value);
}
- public void onStatementDeclared(Mutable<QName, UsesStatement, ?> usesNode) throws InferenceException {
- ModelActionBuilder modifier = usesNode.newInferenceAction(ModelProcessingPhase.EffectiveModel);
+ @Override
+ public void onFullDefinitionDeclared(
+ final StmtContext.Mutable<QName, UsesStatement, EffectiveStatement<QName, UsesStatement>> usesNode)
+ throws SourceException {
+
+ if(StmtContextUtils.isInExtensionBody(usesNode)) {
+ return;
+ }
+
+ ModelActionBuilder usesAction = usesNode.newInferenceAction(ModelProcessingPhase.EFFECTIVE_MODEL);
final QName groupingName = usesNode.getStatementArgument();
- final StatementSourceReference usesSource = usesNode.getStatementSourceReference();
- final Prerequisite<?> targetPre = modifier.mutatesEffectiveCtx(usesNode.getParentContext());
- final Prerequisite<EffectiveStatement<QName, GroupingStatement>> sourcePre = modifier.requiresEffective(
- usesNode, GroupingNamespace.class, groupingName);
- modifier.apply(new InferenceAction() {
+ final Prerequisite<StmtContext<?, ?, ?>> sourceGroupingPre = usesAction.requiresCtx(usesNode,
+ GroupingNamespace.class, groupingName, ModelProcessingPhase.EFFECTIVE_MODEL);
+ final Prerequisite<? extends StmtContext.Mutable<?, ?, ?>> targetNodePre = usesAction.mutatesEffectiveCtx(
+ usesNode.getParentContext());
+
+ usesAction.apply(new InferenceAction() {
@Override
public void apply() throws InferenceException {
- Mutable<?, ?, ?> targetCtx = (Mutable<?, ?, ?>) targetPre.get();
- EffectiveStatement<QName, GroupingStatement> source = sourcePre.get();
-
- throw new UnsupportedOperationException("Copy of not not yet implemented.");
+ StatementContextBase<?, ?, ?> targetNodeStmtCtx = (StatementContextBase<?, ?, ?>) targetNodePre.get();
+ StatementContextBase<?, ?, ?> sourceGrpStmtCtx = (StatementContextBase<?, ?, ?>) sourceGroupingPre.get();
+
+ try {
+ GroupingUtils.copyFromSourceToTarget(sourceGrpStmtCtx, targetNodeStmtCtx, usesNode);
+ GroupingUtils.resolveUsesNode(usesNode, targetNodeStmtCtx);
+ } catch (SourceException e) {
+ LOG.warn(e.getMessage(), e);
+ throw e;
+ }
}
@Override
- public void prerequisiteFailed(Collection<? extends Prerequisite<?>> failed) throws InferenceException {
- if(failed.contains(sourcePre)) {
- throw new InferenceException("Grouping " + groupingName + "was not found.", usesSource);
+ public void prerequisiteFailed(final Collection<? extends Prerequisite<?>> failed) throws InferenceException {
+ if (failed.contains(sourceGroupingPre)) {
+ throw new InferenceException("Grouping " + groupingName + " was not resolved.", usesNode
+ .getStatementSourceReference());
}
- throw new InferenceException("Unknown error occured.", usesSource);
+ throw new InferenceException("Unknown error occurred.", usesNode.getStatementSourceReference());
}
-
});
-
}
@Override
- public UsesStatement createDeclared(StmtContext<QName, UsesStatement, ?> ctx) {
+ public UsesStatement createDeclared(final StmtContext<QName, UsesStatement, ?> ctx) {
return new UsesStatementImpl(ctx);
}
@Override
public EffectiveStatement<QName, UsesStatement> createEffective(
- StmtContext<QName, UsesStatement, EffectiveStatement<QName, UsesStatement>> ctx) {
- throw new UnsupportedOperationException("Not implemented yet.");
+ final StmtContext<QName, UsesStatement, EffectiveStatement<QName, UsesStatement>> ctx) {
+ return new UsesEffectiveStatementImpl(ctx);
}
}
public Collection<? extends RefineStatement> getRefines() {
return allDeclared(RefineStatement.class);
}
-
- @Override
- public QName argument() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public String rawArgument() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public Collection<? extends DeclaredStatement<?>> declaredSubstatements() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public StatementDefinition statementDefinition() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public StatementSource getStatementSource() {
- // TODO Auto-generated method stub
- return null;
- }
-
}