Bug fix for ForwardingRulesManager:
[controller.git] / opendaylight / sal / yang-prototype / code-generator / yang-model-parser-impl / src / main / java / org / opendaylight / controller / yang / model / parser / builder / impl / IdentitySchemaNodeBuilder.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 java.util.Collections;
11 import java.util.List;
12
13 import org.opendaylight.controller.yang.common.QName;
14 import org.opendaylight.controller.yang.model.api.IdentitySchemaNode;
15 import org.opendaylight.controller.yang.model.api.SchemaPath;
16 import org.opendaylight.controller.yang.model.api.Status;
17 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
18 import org.opendaylight.controller.yang.model.parser.builder.api.SchemaNodeBuilder;
19
20 public class IdentitySchemaNodeBuilder implements SchemaNodeBuilder {
21
22     private final QName qname;
23     private SchemaPath schemaPath;
24     private final IdentitySchemaNodeImpl instance;
25     private IdentitySchemaNodeBuilder baseIdentity;
26     private String baseIdentityName;
27
28     IdentitySchemaNodeBuilder(final QName qname) {
29         this.qname = qname;
30         instance = new IdentitySchemaNodeImpl(qname);
31     }
32
33     @Override
34     public IdentitySchemaNode build() {
35         instance.setPath(schemaPath);
36
37         if (baseIdentity != null) {
38             final IdentitySchemaNode base = baseIdentity.build();
39             instance.setBaseIdentity(base);
40         }
41         return instance;
42     }
43
44     @Override
45     public QName getQName() {
46         return qname;
47     }
48
49     @Override
50     public SchemaPath getPath() {
51         return schemaPath;
52     }
53
54     @Override
55     public void setPath(SchemaPath schemaPath) {
56         this.schemaPath = schemaPath;
57     }
58
59     @Override
60     public void setDescription(final String description) {
61         instance.setDescription(description);
62     }
63
64     @Override
65     public void setReference(final String reference) {
66         instance.setReference(reference);
67     }
68
69     @Override
70     public void setStatus(final Status status) {
71         if (status != null) {
72             instance.setStatus(status);
73         }
74     }
75
76     @Override
77     public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
78         throw new IllegalStateException(
79                 "Can not add schema node to identity statement");
80     }
81
82     public String getBaseIdentityName() {
83         return baseIdentityName;
84     }
85
86     public void setBaseIdentityName(final String baseIdentityName) {
87         this.baseIdentityName = baseIdentityName;
88     }
89
90     public void setBaseIdentity(final IdentitySchemaNodeBuilder baseType) {
91         this.baseIdentity = baseType;
92     }
93
94     private class IdentitySchemaNodeImpl implements IdentitySchemaNode {
95         private final QName qname;
96         private IdentitySchemaNode baseIdentity;
97         private String description;
98         private String reference;
99         private Status status = Status.CURRENT;
100         private SchemaPath path;
101
102         private IdentitySchemaNodeImpl(final QName qname) {
103             this.qname = qname;
104         }
105
106         @Override
107         public QName getQName() {
108             return qname;
109         }
110
111         @Override
112         public IdentitySchemaNode getBaseIdentity() {
113             return baseIdentity;
114         }
115
116         private void setBaseIdentity(final IdentitySchemaNode baseIdentity) {
117             this.baseIdentity = baseIdentity;
118         }
119
120         @Override
121         public String getDescription() {
122             return description;
123         }
124
125         private void setDescription(final String description) {
126             this.description = description;
127         }
128
129         @Override
130         public String getReference() {
131             return reference;
132         }
133
134         private void setReference(final String reference) {
135             this.reference = reference;
136         }
137
138         @Override
139         public Status getStatus() {
140             return status;
141         }
142
143         private void setStatus(final Status status) {
144             if (status != null) {
145                 this.status = status;
146             }
147         }
148
149         @Override
150         public SchemaPath getPath() {
151             return path;
152         }
153
154         private void setPath(final SchemaPath path) {
155             this.path = path;
156         }
157
158         @Override
159         public List<UnknownSchemaNode> getUnknownSchemaNodes() {
160             return Collections.emptyList();
161         }
162
163         @Override
164         public int hashCode() {
165             final int prime = 31;
166             int result = 1;
167             result = prime * result + ((qname == null) ? 0 : qname.hashCode());
168             return result;
169         }
170
171         @Override
172         public boolean equals(Object obj) {
173             if (this == obj) {
174                 return true;
175             }
176             if (obj == null) {
177                 return false;
178             }
179             if (getClass() != obj.getClass()) {
180                 return false;
181             }
182             IdentitySchemaNodeImpl other = (IdentitySchemaNodeImpl) obj;
183             if (qname == null) {
184                 if (other.qname != null) {
185                     return false;
186                 }
187             } else if (!qname.equals(other.qname)) {
188                 return false;
189             }
190             return true;
191         }
192
193         @Override
194         public String toString() {
195             StringBuilder sb = new StringBuilder(
196                     IdentitySchemaNodeImpl.class.getSimpleName());
197             sb.append("[");
198             sb.append("base=" + baseIdentity);
199             sb.append(", qname=" + qname);
200             sb.append("]");
201             return sb.toString();
202         }
203     }
204
205 }