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;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
23 * root statement class for a Yang source
25 public class RootStatementContext<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>> extends
26 StatementContextBase<A, D, E> {
28 private final SourceSpecificContext sourceContext;
29 private final A argument;
31 RootStatementContext(final ContextBuilder<A, D, E> builder, final SourceSpecificContext sourceContext) {
33 this.sourceContext = sourceContext;
34 this.argument = builder.getDefinition().parseArgumentValue(this, builder.getRawArgument());
37 RootStatementContext(final RootStatementContext<A, D, E> original, final QNameModule newQNameModule,
38 final TypeOfCopy typeOfCopy) {
41 sourceContext = original.sourceContext;
42 this.argument = original.argument;
44 copyDeclaredStmts(original, newQNameModule, typeOfCopy);
46 copyEffectiveStmts(original, newQNameModule, typeOfCopy);
51 * copies declared statements from original to this' substatements
54 * determines whether copy is used by augmentation or uses
55 * @throws org.opendaylight.yangtools.yang.parser.spi.source.SourceException
57 private void copyDeclaredStmts(final RootStatementContext<A, D, E> original, final QNameModule newQNameModule,
58 final TypeOfCopy typeOfCopy) {
59 final Collection<StatementContextBase<?, ?, ?>> originalDeclaredSubstatements = original.declaredSubstatements();
60 for (final StatementContextBase<?, ?, ?> stmtContext : originalDeclaredSubstatements) {
61 if (!StmtContextUtils.areFeaturesSupported(stmtContext)) {
64 this.addEffectiveSubstatement(stmtContext.createCopy(newQNameModule, this, typeOfCopy));
69 * copies effective statements from original to this' substatements
72 * determines whether copy is used by augmentation or uses
73 * @throws org.opendaylight.yangtools.yang.parser.spi.source.SourceException
75 private void copyEffectiveStmts(final RootStatementContext<A, D, E> original, final QNameModule newQNameModule,
76 final TypeOfCopy typeOfCopy) {
77 final Collection<? extends StmtContext<?, ?, ?>> originalEffectiveSubstatements = original.effectiveSubstatements();
78 for (final StmtContext<?, ?, ?> stmtContext : originalEffectiveSubstatements) {
79 this.addEffectiveSubstatement(stmtContext.createCopy(newQNameModule, this, typeOfCopy));
84 * @return null as root cannot have parent
87 public StatementContextBase<?, ?, ?> getParentContext() {
92 * @return namespace storage of source context
95 public NamespaceStorageNode getParentNamespaceStorage() {
100 * @return registry of source context
103 public Registry getBehaviourRegistry() {
104 return sourceContext;
108 public StorageNodeType getStorageNodeType() {
109 return StorageNodeType.ROOT_STATEMENT_LOCAL;
112 * @return this as its own root
115 public RootStatementContext<?, ?, ?> getRoot() {
119 SourceSpecificContext getSourceContext() {
120 return sourceContext;
124 public A getStatementArgument() {
129 * @return copy of this considering {@link TypeOfCopy} (augment, uses)
131 * @throws org.opendaylight.yangtools.yang.parser.spi.source.SourceException instance of SourceException
134 public StatementContextBase<?, ?, ?> createCopy(final StatementContextBase<?, ?, ?> newParent,
135 final TypeOfCopy typeOfCopy) {
136 return createCopy(null, newParent, typeOfCopy);
140 * @return copy of this considering {@link TypeOfCopy} (augment, uses)
142 * @throws org.opendaylight.yangtools.yang.parser.spi.source.SourceException instance of SourceException
145 public StatementContextBase<A, D, E> createCopy(final QNameModule newQNameModule,
146 final StatementContextBase<?, ?, ?> newParent, final TypeOfCopy typeOfCopy) {
147 final RootStatementContext<A, D, E> copy = new RootStatementContext<>(this, newQNameModule, typeOfCopy);
149 copy.addAllToCopyHistory(this.getCopyHistory());
150 copy.addToCopyHistory(typeOfCopy);
152 if (this.getOriginalCtx() != null) {
153 copy.setOriginalCtx(this.getOriginalCtx());
155 copy.setOriginalCtx(this);
157 definition().onStatementAdded(copy);
162 public Optional<SchemaPath> getSchemaPath() {
163 return Optional.of(SchemaPath.ROOT);
170 public boolean isRootContext() {
175 public boolean isConfiguration() {
180 public boolean isEnabledSemanticVersioning() {
181 return sourceContext.isEnabledSemanticVersioning();