2 * Copyright (c) 2013 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.builder.impl;
10 import com.google.common.collect.ImmutableList;
11 import java.util.Objects;
12 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
13 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
14 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
15 import org.opendaylight.yangtools.yang.model.util.RevisionAwareXPathImpl;
16 import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationSchemaBuilder;
17 import org.opendaylight.yangtools.yang.parser.builder.api.Builder;
18 import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder;
19 import org.opendaylight.yangtools.yang.parser.builder.util.AbstractDocumentedDataNodeContainerBuilder;
22 * @deprecated Pre-Beryllium implementation, scheduled for removal.
25 public final class AugmentationSchemaBuilderImpl extends AbstractDocumentedDataNodeContainerBuilder implements AugmentationSchemaBuilder {
26 private final int order;
27 private AugmentationSchemaImpl instance;
28 private String whenCondition;
30 private final String augmentTargetStr;
31 private final SchemaPath targetPath;
33 private boolean resolved;
34 private boolean unsupportedTarget = false;
36 private AugmentationSchemaBuilder copyOf;
38 public AugmentationSchemaBuilderImpl(final String moduleName, final int line, final String augmentTargetStr,
39 final SchemaPath targetPath, final int order) {
40 super(moduleName, line, null);
42 this.augmentTargetStr = augmentTargetStr;
43 this.targetPath = targetPath;
47 protected String getStatementName() {
52 public SchemaPath getPath() {
57 public SchemaPath getTargetPath() {
62 public AugmentationSchema build() {
63 if (instance != null) {
69 instance = new AugmentationSchemaImpl(targetPath, order,this);
71 Builder parent = getParent();
72 if (parent instanceof ModuleBuilder) {
73 ModuleBuilder moduleBuilder = (ModuleBuilder) parent;
74 instance.namespace = moduleBuilder.getNamespace();
75 instance.revision = moduleBuilder.getRevision();
79 instance.setCopyOf(copyOf.build());
82 RevisionAwareXPath whenStmt;
83 if (whenCondition == null) {
86 whenStmt = new RevisionAwareXPathImpl(whenCondition, false);
88 instance.whenCondition = whenStmt;
91 for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
92 unknownNodes.add(b.build());
94 instance.unknownNodes = ImmutableList.copyOf(unknownNodes);
100 public boolean isResolved() {
105 public void setResolved(final boolean resolved) {
106 this.resolved = resolved;
110 * Set true if target of augment is unsupported (e.g. node in body of extension).
111 * In such case, augmentation is skipped and AugmentationSchema is not built.
114 public void setUnsupportedTarget(final boolean unsupportedTarget) {
115 this.unsupportedTarget = unsupportedTarget;
119 * Return true if target of augment is unsupported (e.g. node in body of extension).
120 * In such case, augmentation is skipped and AugmentationSchema is not built.
123 public boolean isUnsupportedTarget() {
124 return unsupportedTarget;
128 public String getWhenCondition() {
129 return whenCondition;
133 public void addWhenCondition(final String whenCondition) {
134 this.whenCondition = whenCondition;
138 public String getTargetPathAsString() {
139 return augmentTargetStr;
143 public int getOrder() {
148 public int hashCode() {
149 final int prime = 17;
151 result = prime * result + Objects.hashCode(augmentTargetStr);
152 result = prime * result + Objects.hashCode(whenCondition);
153 result = prime * result + getChildNodeBuilders().hashCode();
158 public boolean equals(final Object obj) {
165 if (getClass() != obj.getClass()) {
168 AugmentationSchemaBuilderImpl other = (AugmentationSchemaBuilderImpl) obj;
169 if (augmentTargetStr == null) {
170 if (other.augmentTargetStr != null) {
173 } else if (!augmentTargetStr.equals(other.augmentTargetStr)) {
176 if (whenCondition == null) {
177 if (other.whenCondition != null) {
180 } else if (!whenCondition.equals(other.whenCondition)) {
183 if (!getChildNodeBuilders().equals(other.getChildNodeBuilders())) {
190 public String toString() {
191 return "augment " + augmentTargetStr;
194 public void setCopyOf(final AugmentationSchemaBuilder old) {