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.reactor;
10 import java.util.List;
12 import java.util.LinkedList;
13 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
14 import org.opendaylight.yangtools.yang.common.QNameModule;
15 import java.util.Collection;
16 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
17 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.NamespaceStorageNode;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.Registry;
20 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
22 class RootStatementContext<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
23 extends StatementContextBase<A, D, E> {
25 private final SourceSpecificContext sourceContext;
26 private final A argument;
28 RootStatementContext(ContextBuilder<A, D, E> builder,
29 SourceSpecificContext sourceContext) throws SourceException {
31 this.sourceContext = sourceContext;
32 this.argument = builder.getDefinition().parseArgumentValue(this,
33 builder.getRawArgument());
36 RootStatementContext(RootStatementContext<A, D, E> original,
37 QNameModule newQNameModule) throws SourceException {
40 sourceContext = original.sourceContext;
41 this.argument = original.argument;
43 copyDeclaredStmts(original, newQNameModule);
45 copyEffectiveStmts(original, newQNameModule);
49 private void copyDeclaredStmts(RootStatementContext<A, D, E> original,
50 QNameModule newQNameModule) throws SourceException {
51 Collection<? extends StmtContext<?, ?, ?>> originalDeclaredSubstatements = original
52 .declaredSubstatements();
53 for (StmtContext<?, ?, ?> stmtContext : originalDeclaredSubstatements) {
54 this.addEffectiveSubstatement(stmtContext
55 .createCopy(newQNameModule,this));
59 private void copyEffectiveStmts(RootStatementContext<A, D, E> original,
60 QNameModule newQNameModule) throws SourceException {
61 Collection<? extends StmtContext<?, ?, ?>> originalEffectiveSubstatements = original
62 .effectiveSubstatements();
63 for (StmtContext<?, ?, ?> stmtContext : originalEffectiveSubstatements) {
64 this.addEffectiveSubstatement(stmtContext
65 .createCopy(newQNameModule,this));
70 public StatementContextBase<?, ?, ?> getParentContext() {
75 public NamespaceStorageNode getParentNamespaceStorage() {
80 public Registry getBehaviourRegistry() {
85 public RootStatementContext<?, ?, ?> getRoot() {
89 SourceSpecificContext getSourceContext() {
94 public A getStatementArgument() {
99 public StatementContextBase<A, D, E> createCopy(QNameModule newQNameModule, StatementContextBase<?, ?, ?> newParent)
100 throws SourceException {
102 return new RootStatementContext<>(this, newQNameModule);
106 public List<Object> getArgumentsFromRoot() {
107 List<Object> argumentList = new LinkedList<Object>();
108 argumentList.add(argument);