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 org.opendaylight.yangtools.yang.parser.stmt.rfc6020.GroupingUtils;
12 import org.opendaylight.yangtools.yang.common.QNameModule;
13 import java.util.Collection;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import com.google.common.base.Preconditions;
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 SubstatementContext<A,D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
23 extends StatementContextBase<A,D,E> {
25 private final StatementContextBase<?,?,?> parent;
26 private final A argument;
28 SubstatementContext(StatementContextBase<?,?,?> parent,ContextBuilder<A,D,E> builder) throws SourceException {
29 //super(builder, builder.getDefinition().parseArgumentValue(parent, builder.getRawArgument()));
31 this.parent = Preconditions.checkNotNull(parent, "Parent must not be null");
32 this.argument = builder.getDefinition().parseArgumentValue(this, builder.getRawArgument());
35 SubstatementContext(SubstatementContext<A,D,E> original, QNameModule newQNameModule, StatementContextBase<?, ?, ?> newParent) throws SourceException {
37 this.parent = newParent;
39 if(newQNameModule != null && original.argument instanceof QName) {
40 QName originalQName = (QName) original.argument;
41 this.argument = (A) QName.create(newQNameModule,originalQName.getLocalName());
43 this.argument = original.argument;
46 copyDeclaredStmts(original, newQNameModule);
48 copyEffectiveStmts(original, newQNameModule);
51 private void copyDeclaredStmts(SubstatementContext<A, D, E> original,
52 QNameModule newQNameModule) throws SourceException {
53 Collection<? extends StatementContextBase<?, ?, ?>> originalDeclaredSubstatements = original
54 .declaredSubstatements();
55 for (StatementContextBase<?, ?, ?> stmtContext : originalDeclaredSubstatements) {
56 if (GroupingUtils.needToCopyByUses(stmtContext)) {
57 StatementContextBase<?, ?, ?> copy = stmtContext
58 .createCopy(newQNameModule,this);
59 this.addEffectiveSubstatement(copy);
60 } else if (GroupingUtils.isReusedByUses(stmtContext)) {
61 this.addEffectiveSubstatement(stmtContext);
66 private void copyEffectiveStmts(SubstatementContext<A, D, E> original,
67 QNameModule newQNameModule) throws SourceException {
68 Collection<? extends StatementContextBase<?, ?, ?>> originalEffectiveSubstatements = original
69 .effectiveSubstatements();
70 for (StatementContextBase<?, ?, ?> stmtContext : originalEffectiveSubstatements) {
71 if (GroupingUtils.needToCopyByUses(stmtContext)) {
72 StatementContextBase<?, ?, ?> copy = stmtContext
73 .createCopy(newQNameModule,this);
74 this.addEffectiveSubstatement(copy);
75 } else if (GroupingUtils.isReusedByUses(stmtContext)) {
76 this.addEffectiveSubstatement(stmtContext);
82 public StatementContextBase<?,?,?> getParentContext() {
87 public NamespaceStorageNode getParentNamespaceStorage() {
92 public Registry getBehaviourRegistry() {
93 return parent.getBehaviourRegistry();
97 public RootStatementContext<?, ?, ?> getRoot() {
98 return parent.getRoot();
103 public A getStatementArgument() {
108 public StatementContextBase<A, D, E> createCopy(QNameModule newQNameModule, StatementContextBase<?, ?, ?> newParent) throws SourceException {
109 StatementContextBase<A,D,E> copy = new SubstatementContext<A,D,E>(this,newQNameModule, newParent);