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 com.google.common.base.Optional;
11 import java.util.Collection;
12 import org.opendaylight.yangtools.yang.common.QNameModule;
13 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
14 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
15 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
16 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.NamespaceStorageNode;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.Registry;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.StorageNodeType;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
22 * root statement class for a Yang source
24 public class RootStatementContext<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>> extends
25 StatementContextBase<A, D, E> {
27 private final SourceSpecificContext sourceContext;
28 private final A argument;
30 RootStatementContext(final ContextBuilder<A, D, E> builder, final SourceSpecificContext sourceContext) {
32 this.sourceContext = sourceContext;
33 this.argument = builder.getDefinition().parseArgumentValue(this, builder.getRawArgument());
36 RootStatementContext(final RootStatementContext<A, D, E> original, final QNameModule newQNameModule,
37 final TypeOfCopy typeOfCopy) {
40 sourceContext = original.sourceContext;
41 this.argument = original.argument;
43 copyDeclaredStmts(original, newQNameModule, typeOfCopy);
45 copyEffectiveStmts(original, newQNameModule, typeOfCopy);
50 * copies declared statements from original to this' substatements
53 * determines whether copy is used by augmentation or uses
54 * @throws org.opendaylight.yangtools.yang.parser.spi.source.SourceException
56 private void copyDeclaredStmts(final RootStatementContext<A, D, E> original, final QNameModule newQNameModule,
57 final TypeOfCopy typeOfCopy) {
58 Collection<? extends StmtContext<?, ?, ?>> originalDeclaredSubstatements = original.declaredSubstatements();
59 for (StmtContext<?, ?, ?> stmtContext : originalDeclaredSubstatements) {
60 this.addEffectiveSubstatement(stmtContext.createCopy(newQNameModule, this, typeOfCopy));
65 * copies effective statements from original to this' substatements
68 * determines whether copy is used by augmentation or uses
69 * @throws org.opendaylight.yangtools.yang.parser.spi.source.SourceException
71 private void copyEffectiveStmts(final RootStatementContext<A, D, E> original, final QNameModule newQNameModule,
72 final TypeOfCopy typeOfCopy) {
73 Collection<? extends StmtContext<?, ?, ?>> originalEffectiveSubstatements = original.effectiveSubstatements();
74 for (StmtContext<?, ?, ?> stmtContext : originalEffectiveSubstatements) {
75 this.addEffectiveSubstatement(stmtContext.createCopy(newQNameModule, this, typeOfCopy));
80 * @return null as root cannot have parent
83 public StatementContextBase<?, ?, ?> getParentContext() {
88 * @return namespace storage of source context
91 public NamespaceStorageNode getParentNamespaceStorage() {
96 * @return registry of source context
99 public Registry getBehaviourRegistry() {
100 return sourceContext;
104 public StorageNodeType getStorageNodeType() {
105 return StorageNodeType.ROOT_STATEMENT_LOCAL;
108 * @return this as its own root
111 public RootStatementContext<?, ?, ?> getRoot() {
115 SourceSpecificContext getSourceContext() {
116 return sourceContext;
120 public A getStatementArgument() {
125 * @return copy of this considering {@link TypeOfCopy} (augment, uses)
127 * @throws org.opendaylight.yangtools.yang.parser.spi.source.SourceException instance of SourceException
130 public StatementContextBase<?, ?, ?> createCopy(final StatementContextBase<?, ?, ?> newParent,
131 final TypeOfCopy typeOfCopy) {
132 return createCopy(null, newParent, typeOfCopy);
136 * @return copy of this considering {@link TypeOfCopy} (augment, uses)
138 * @throws org.opendaylight.yangtools.yang.parser.spi.source.SourceException instance of SourceException
141 public StatementContextBase<A, D, E> createCopy(final QNameModule newQNameModule,
142 final StatementContextBase<?, ?, ?> newParent, final TypeOfCopy typeOfCopy) {
143 RootStatementContext<A, D, E> copy = new RootStatementContext<>(this, newQNameModule, typeOfCopy);
145 copy.addAllToCopyHistory(this.getCopyHistory());
146 copy.addToCopyHistory(typeOfCopy);
148 if(this.getOriginalCtx() != null) {
149 copy.setOriginalCtx(this.getOriginalCtx());
151 copy.setOriginalCtx(this);
153 definition().onStatementAdded(copy);
158 public Optional<SchemaPath> getSchemaPath() {
159 return Optional.of(SchemaPath.ROOT);
166 public boolean isRootContext() {
171 public boolean isConfiguration() {