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

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.