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 org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
12 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
13 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
14 import org.opendaylight.yangtools.yang.model.util.RevisionAwareXPathImpl;
15 import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationSchemaBuilder;
16 import org.opendaylight.yangtools.yang.parser.builder.api.Builder;
17 import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder;
18 import org.opendaylight.yangtools.yang.parser.builder.util.AbstractDocumentedDataNodeContainerBuilder;
20 public final class AugmentationSchemaBuilderImpl extends AbstractDocumentedDataNodeContainerBuilder implements AugmentationSchemaBuilder {
21 private final int order;
22 private AugmentationSchemaImpl instance;
23 private String whenCondition;
25 private final String augmentTargetStr;
26 private final SchemaPath targetPath;
28 private boolean resolved;
29 private boolean unsupportedTarget = false;
31 private AugmentationSchemaBuilder copyOf;
33 public AugmentationSchemaBuilderImpl(final String moduleName, final int line, final String augmentTargetStr,
34 final SchemaPath targetPath, final int order) {
35 super(moduleName, line, null);
37 this.augmentTargetStr = augmentTargetStr;
38 this.targetPath = targetPath;
42 protected String getStatementName() {
47 public SchemaPath getPath() {
52 public SchemaPath getTargetPath() {
57 public AugmentationSchema build() {
58 if (instance != null) {
64 instance = new AugmentationSchemaImpl(targetPath, order,this);
66 Builder parent = getParent();
67 if (parent instanceof ModuleBuilder) {
68 ModuleBuilder moduleBuilder = (ModuleBuilder) parent;
69 instance.namespace = moduleBuilder.getNamespace();
70 instance.revision = moduleBuilder.getRevision();
74 instance.setCopyOf(copyOf.build());
77 RevisionAwareXPath whenStmt;
78 if (whenCondition == null) {
81 whenStmt = new RevisionAwareXPathImpl(whenCondition, false);
83 instance.whenCondition = whenStmt;
86 for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
87 unknownNodes.add(b.build());
89 instance.unknownNodes = ImmutableList.copyOf(unknownNodes);
95 public boolean isResolved() {
100 public void setResolved(final boolean resolved) {
101 this.resolved = resolved;
105 * Set true if target of augment is unsupported (e.g. node in body of extension).
106 * In such case, augmentation is skipped and AugmentationSchema is not built.
109 public void setUnsupportedTarget(boolean unsupportedTarget) {
110 this.unsupportedTarget = unsupportedTarget;
114 * Return true if target of augment is unsupported (e.g. node in body of extension).
115 * In such case, augmentation is skipped and AugmentationSchema is not built.
118 public boolean isUnsupportedTarget() {
119 return unsupportedTarget;
123 public String getWhenCondition() {
124 return whenCondition;
128 public void addWhenCondition(final String whenCondition) {
129 this.whenCondition = whenCondition;
133 public String getTargetPathAsString() {
134 return augmentTargetStr;
138 public int getOrder() {
143 public int hashCode() {
144 final int prime = 17;
146 result = prime * result + ((augmentTargetStr == null) ? 0 : augmentTargetStr.hashCode());
147 result = prime * result + ((whenCondition == null) ? 0 : whenCondition.hashCode());
148 result = prime * result + getChildNodeBuilders().hashCode();
153 public boolean equals(final Object obj) {
160 if (getClass() != obj.getClass()) {
163 AugmentationSchemaBuilderImpl other = (AugmentationSchemaBuilderImpl) obj;
164 if (augmentTargetStr == null) {
165 if (other.augmentTargetStr != null) {
168 } else if (!augmentTargetStr.equals(other.augmentTargetStr)) {
171 if (whenCondition == null) {
172 if (other.whenCondition != null) {
175 } else if (!whenCondition.equals(other.whenCondition)) {
178 if (!getChildNodeBuilders().equals(other.getChildNodeBuilders())) {
185 public String toString() {
186 return "augment " + augmentTargetStr;
189 public void setCopyOf(final AugmentationSchemaBuilder old) {