Fixed relative/absolute yang files directory resolving.
[controller.git] / opendaylight / sal / yang-prototype / code-generator / yang-model-parser-impl / src / main / java / org / opendaylight / controller / yang / model / parser / builder / impl / DeviationBuilder.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.yang.model.parser.builder.impl;
9
10 import org.opendaylight.controller.yang.model.api.Deviation;
11 import org.opendaylight.controller.yang.model.api.Deviation.Deviate;
12 import org.opendaylight.controller.yang.model.api.SchemaPath;
13 import org.opendaylight.controller.yang.model.parser.builder.api.Builder;
14 import org.opendaylight.controller.yang.model.parser.util.YangModelBuilderUtil;
15
16 public class DeviationBuilder implements Builder {
17     private final DeviationImpl instance;
18     private final int line;
19
20     DeviationBuilder(final String targetPathStr, final int line) {
21         this.line = line;
22         final SchemaPath targetPath = YangModelBuilderUtil
23                 .parseAugmentPath(targetPathStr);
24         instance = new DeviationImpl(targetPath);
25     }
26
27     @Override
28     public Deviation build() {
29         return instance;
30     }
31
32     @Override
33     public int getLine() {
34         return line;
35     }
36
37     public void setDeviate(final String deviate) {
38         if ("not-supported".equals(deviate)) {
39             instance.setDeviate(Deviate.NOT_SUPPORTED);
40         } else if ("add".equals(deviate)) {
41             instance.setDeviate(Deviate.ADD);
42         } else if ("replace".equals(deviate)) {
43             instance.setDeviate(Deviate.REPLACE);
44         } else if ("delete".equals(deviate)) {
45             instance.setDeviate(Deviate.DELETE);
46         } else {
47             throw new IllegalArgumentException(
48                     "Unsupported type of 'deviate' statement: " + deviate);
49         }
50     }
51
52     public void setReference(final String reference) {
53         instance.setReference(reference);
54     }
55
56     private static class DeviationImpl implements Deviation {
57         private final SchemaPath targetPath;
58         private Deviate deviate;
59         private String reference;
60
61         private DeviationImpl(final SchemaPath targetPath) {
62             this.targetPath = targetPath;
63         }
64
65         @Override
66         public SchemaPath getTargetPath() {
67             return targetPath;
68         }
69
70         @Override
71         public Deviate getDeviate() {
72             return deviate;
73         }
74
75         private void setDeviate(final Deviate deviate) {
76             this.deviate = deviate;
77         }
78
79         @Override
80         public String getReference() {
81             return reference;
82         }
83
84         private void setReference(final String reference) {
85             this.reference = reference;
86         }
87
88         @Override
89         public int hashCode() {
90             final int prime = 31;
91             int result = 1;
92             result = prime * result
93                     + ((targetPath == null) ? 0 : targetPath.hashCode());
94             result = prime * result
95                     + ((deviate == null) ? 0 : deviate.hashCode());
96             result = prime * result
97                     + ((reference == null) ? 0 : reference.hashCode());
98             return result;
99         }
100
101         @Override
102         public boolean equals(Object obj) {
103             if (this == obj) {
104                 return true;
105             }
106             if (obj == null) {
107                 return false;
108             }
109             if (getClass() != obj.getClass()) {
110                 return false;
111             }
112             DeviationImpl other = (DeviationImpl) obj;
113             if (targetPath == null) {
114                 if (other.targetPath != null) {
115                     return false;
116                 }
117             } else if (!targetPath.equals(other.targetPath)) {
118                 return false;
119             }
120             if (deviate == null) {
121                 if (other.deviate != null) {
122                     return false;
123                 }
124             } else if (!deviate.equals(other.deviate)) {
125                 return false;
126             }
127             if (reference == null) {
128                 if (other.reference != null) {
129                     return false;
130                 }
131             } else if (!reference.equals(other.reference)) {
132                 return false;
133             }
134             return true;
135         }
136
137         @Override
138         public String toString() {
139             StringBuilder sb = new StringBuilder(
140                     DeviationImpl.class.getSimpleName());
141             sb.append("[");
142             sb.append("targetPath=" + targetPath);
143             sb.append(", deviate=" + deviate);
144             sb.append(", reference=" + reference);
145             sb.append("]");
146             return sb.toString();
147         }
148     }
149
150 }