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;
21 public final class AugmentationSchemaBuilderImpl extends AbstractDocumentedDataNodeContainerBuilder implements AugmentationSchemaBuilder {
22 private final int order;
23 private AugmentationSchemaImpl instance;
24 private String whenCondition;
26 private final String augmentTargetStr;
27 private final SchemaPath targetPath;
29 private boolean resolved;
30 private boolean unsupportedTarget = false;
32 private AugmentationSchemaBuilder copyOf;
34 public AugmentationSchemaBuilderImpl(final String moduleName, final int line, final String augmentTargetStr,
35 final SchemaPath targetPath, final int order) {
36 super(moduleName, line, null);
38 this.augmentTargetStr = augmentTargetStr;
39 this.targetPath = targetPath;
43 protected String getStatementName() {
48 public SchemaPath getPath() {
53 public SchemaPath getTargetPath() {
58 public AugmentationSchema build() {
59 if (instance != null) {
65 instance = new AugmentationSchemaImpl(targetPath, order,this);
67 Builder parent = getParent();
68 if (parent instanceof ModuleBuilder) {
69 ModuleBuilder moduleBuilder = (ModuleBuilder) parent;
70 instance.namespace = moduleBuilder.getNamespace();
71 instance.revision = moduleBuilder.getRevision();
75 instance.setCopyOf(copyOf.build());
78 RevisionAwareXPath whenStmt;
79 if (whenCondition == null) {
82 whenStmt = new RevisionAwareXPathImpl(whenCondition, false);
84 instance.whenCondition = whenStmt;
87 for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
88 unknownNodes.add(b.build());
90 instance.unknownNodes = ImmutableList.copyOf(unknownNodes);
96 public boolean isResolved() {
101 public void setResolved(final boolean resolved) {
102 this.resolved = resolved;
106 * Set true if target of augment is unsupported (e.g. node in body of extension).
107 * In such case, augmentation is skipped and AugmentationSchema is not built.
110 public void setUnsupportedTarget(boolean unsupportedTarget) {
111 this.unsupportedTarget = unsupportedTarget;
115 * Return true if target of augment is unsupported (e.g. node in body of extension).
116 * In such case, augmentation is skipped and AugmentationSchema is not built.
119 public boolean isUnsupportedTarget() {
120 return unsupportedTarget;
124 public String getWhenCondition() {
125 return whenCondition;
129 public void addWhenCondition(final String whenCondition) {
130 this.whenCondition = whenCondition;
134 public String getTargetPathAsString() {
135 return augmentTargetStr;
139 public int getOrder() {
144 public int hashCode() {
145 final int prime = 17;
147 result = prime * result + Objects.hashCode(augmentTargetStr);
148 result = prime * result + Objects.hashCode(whenCondition);
149 result = prime * result + getChildNodeBuilders().hashCode();
154 public boolean equals(final Object obj) {
161 if (getClass() != obj.getClass()) {
164 AugmentationSchemaBuilderImpl other = (AugmentationSchemaBuilderImpl) obj;
165 if (augmentTargetStr == null) {
166 if (other.augmentTargetStr != null) {
169 } else if (!augmentTargetStr.equals(other.augmentTargetStr)) {
172 if (whenCondition == null) {
173 if (other.whenCondition != null) {
176 } else if (!whenCondition.equals(other.whenCondition)) {
179 if (!getChildNodeBuilders().equals(other.getChildNodeBuilders())) {
186 public String toString() {
187 return "augment " + augmentTargetStr;
190 public void setCopyOf(final AugmentationSchemaBuilder old) {