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, TypeOfCopy typeOfCopy)
38 throws SourceException {
41 sourceContext = original.sourceContext;
42 this.argument = original.argument;
44 copyDeclaredStmts(original, newQNameModule, typeOfCopy);
46 copyEffectiveStmts(original, newQNameModule, typeOfCopy);
50 private void copyDeclaredStmts(RootStatementContext<A, D, E> original,
51 QNameModule newQNameModule, TypeOfCopy typeOfCopy)
52 throws SourceException {
53 Collection<? extends StmtContext<?, ?, ?>> originalDeclaredSubstatements = original
54 .declaredSubstatements();
55 for (StmtContext<?, ?, ?> stmtContext : originalDeclaredSubstatements) {
56 this.addEffectiveSubstatement(stmtContext.createCopy(
57 newQNameModule, this, typeOfCopy));
61 private void copyEffectiveStmts(RootStatementContext<A, D, E> original,
62 QNameModule newQNameModule, TypeOfCopy typeOfCopy)
63 throws SourceException {
64 Collection<? extends StmtContext<?, ?, ?>> originalEffectiveSubstatements = original
65 .effectiveSubstatements();
66 for (StmtContext<?, ?, ?> stmtContext : originalEffectiveSubstatements) {
67 this.addEffectiveSubstatement(stmtContext.createCopy(
68 newQNameModule, this, typeOfCopy));
73 public StatementContextBase<?, ?, ?> getParentContext() {
78 public NamespaceStorageNode getParentNamespaceStorage() {
83 public Registry getBehaviourRegistry() {
88 public RootStatementContext<?, ?, ?> getRoot() {
92 SourceSpecificContext getSourceContext() {
97 public A getStatementArgument() {
102 public StatementContextBase<A, D, E> createCopy(QNameModule newQNameModule,
103 StatementContextBase<?, ?, ?> newParent, TypeOfCopy typeOfCopy)
104 throws SourceException {
105 RootStatementContext<A, D, E> copy = new RootStatementContext<>(this,
106 newQNameModule, typeOfCopy);
107 copy.setTypeOfCopy(typeOfCopy);
108 copy.setOriginalCtx(this);
113 public List<Object> getArgumentsFromRoot() {
114 List<Object> argumentList = new LinkedList<Object>();
115 argumentList.add(argument);
120 public boolean isRootContext() {