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.List;
12 import java.util.Objects;
13 import org.opendaylight.yangtools.yang.model.api.Deviation;
14 import org.opendaylight.yangtools.yang.model.api.Deviation.Deviate;
15 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
16 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
17 import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder;
18 import org.opendaylight.yangtools.yang.parser.builder.util.AbstractBuilder;
19 import org.opendaylight.yangtools.yang.parser.util.YangParseException;
22 * @deprecated Pre-Beryllium implementation, scheduled for removal.
25 public final class DeviationBuilder extends AbstractBuilder {
26 private DeviationImpl instance;
27 private final SchemaPath targetPath;
28 private Deviate deviate;
29 private String reference;
31 DeviationBuilder(final String moduleName, final int line, final SchemaPath targetPath) {
32 super(moduleName, line);
33 this.targetPath = targetPath;
37 public Deviation build() {
38 if (instance != null) {
41 if (targetPath == null) {
42 throw new YangParseException(getModuleName(), getLine(), "Unresolved deviation target");
45 instance = new DeviationImpl(targetPath);
46 instance.deviate = deviate;
47 instance.reference = reference;
50 for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
51 unknownNodes.add(b.build());
53 instance.unknownNodes = ImmutableList.copyOf(unknownNodes);
58 public SchemaPath getTargetPath() {
62 public void setDeviate(final String deviate) {
63 if ("not-supported".equals(deviate)) {
64 this.deviate = Deviate.NOT_SUPPORTED;
65 } else if ("add".equals(deviate)) {
66 this.deviate = Deviate.ADD;
67 } else if ("replace".equals(deviate)) {
68 this.deviate = Deviate.REPLACE;
69 } else if ("delete".equals(deviate)) {
70 this.deviate = Deviate.DELETE;
72 throw new YangParseException(getModuleName(), getLine(), "Unsupported type of 'deviate' statement: " + deviate);
76 public void setReference(final String reference) {
77 this.reference = reference;
81 public String toString() {
82 return "deviation " + targetPath;
85 private static final class DeviationImpl implements Deviation {
86 private final SchemaPath targetPath;
87 private Deviate deviate;
88 private String reference;
89 private ImmutableList<UnknownSchemaNode> unknownNodes;
91 private DeviationImpl(final SchemaPath targetPath) {
92 this.targetPath = targetPath;
96 public SchemaPath getTargetPath() {
101 public Deviate getDeviate() {
106 public String getReference() {
111 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
116 public int hashCode() {
117 final int prime = 31;
119 result = prime * result + Objects.hashCode(targetPath);
120 result = prime * result + Objects.hashCode(deviate);
121 result = prime * result + Objects.hashCode(reference);
126 public boolean equals(final Object obj) {
133 if (getClass() != obj.getClass()) {
136 DeviationImpl other = (DeviationImpl) obj;
137 if (targetPath == null) {
138 if (other.targetPath != null) {
141 } else if (!targetPath.equals(other.targetPath)) {
144 if (deviate == null) {
145 if (other.deviate != null) {
148 } else if (!deviate.equals(other.deviate)) {
151 if (reference == null) {
152 if (other.reference != null) {
155 } else if (!reference.equals(other.reference)) {
162 public String toString() {
163 StringBuilder sb = new StringBuilder(DeviationImpl.class.getSimpleName());
165 sb.append("targetPath=").append(targetPath);
166 sb.append(", deviate=").append(deviate);
167 sb.append(", reference=").append(reference);
169 return sb.toString();