/* * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.yangtools.yang.parser.stmt.reactor; import java.util.List; import java.util.LinkedList; import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext; import org.opendaylight.yangtools.yang.common.QNameModule; import java.util.Collection; import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement; import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement; import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.NamespaceStorageNode; import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.Registry; import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; class RootStatementContext, E extends EffectiveStatement> extends StatementContextBase { private final SourceSpecificContext sourceContext; private final A argument; RootStatementContext(ContextBuilder builder, SourceSpecificContext sourceContext) throws SourceException { super(builder); this.sourceContext = sourceContext; this.argument = builder.getDefinition().parseArgumentValue(this, builder.getRawArgument()); } RootStatementContext(RootStatementContext original, QNameModule newQNameModule) throws SourceException { super(original); sourceContext = original.sourceContext; this.argument = original.argument; copyDeclaredStmts(original, newQNameModule); copyEffectiveStmts(original, newQNameModule); } private void copyDeclaredStmts(RootStatementContext original, QNameModule newQNameModule) throws SourceException { Collection> originalDeclaredSubstatements = original .declaredSubstatements(); for (StmtContext stmtContext : originalDeclaredSubstatements) { this.addEffectiveSubstatement(stmtContext .createCopy(newQNameModule,this)); } } private void copyEffectiveStmts(RootStatementContext original, QNameModule newQNameModule) throws SourceException { Collection> originalEffectiveSubstatements = original .effectiveSubstatements(); for (StmtContext stmtContext : originalEffectiveSubstatements) { this.addEffectiveSubstatement(stmtContext .createCopy(newQNameModule,this)); } } @Override public StatementContextBase getParentContext() { return null; } @Override public NamespaceStorageNode getParentNamespaceStorage() { return sourceContext; } @Override public Registry getBehaviourRegistry() { return sourceContext; } @Override public RootStatementContext getRoot() { return this; } SourceSpecificContext getSourceContext() { return sourceContext; } @Override public A getStatementArgument() { return argument; } @Override public StatementContextBase createCopy(QNameModule newQNameModule, StatementContextBase newParent) throws SourceException { return new RootStatementContext<>(this, newQNameModule); } @Override public List getArgumentsFromRoot() { List argumentList = new LinkedList(); argumentList.add(argument); return argumentList; } }