Refactored YANG types resolving.
[controller.git] / opendaylight / sal / yang-prototype / code-generator / yang-model-parser-impl / src / main / java / org / opendaylight / controller / yang / model / parser / builder / impl / FeatureBuilder.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.FeatureDefinition;
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 FeatureBuilder implements SchemaNodeBuilder {
22
23     private final FeatureDefinitionImpl instance;
24     private final QName qname;
25     private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
26
27     FeatureBuilder(QName qname) {
28         this.qname = qname;
29         instance = new FeatureDefinitionImpl(qname);
30     }
31
32     @Override
33     public FeatureDefinitionImpl build() {
34         // UNKNOWN NODES
35         final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
36         for(UnknownSchemaNodeBuilder b : addedUnknownNodes) {
37             unknownNodes.add(b.build());
38         }
39         instance.setUnknownSchemaNodes(unknownNodes);
40
41         return instance;
42     }
43
44     @Override
45     public QName getQName() {
46         return qname;
47     }
48
49     @Override
50     public void setPath(SchemaPath path) {
51         instance.setPath(path);
52     }
53
54     @Override
55     public void setDescription(String description) {
56         instance.setDescription(description);
57     }
58
59     @Override
60     public void setReference(String reference) {
61         instance.setReference(reference);
62     }
63
64     @Override
65     public void setStatus(Status status) {
66         instance.setStatus(status);
67     }
68
69     @Override
70     public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownSchemaNodeBuilder) {
71         addedUnknownNodes.add(unknownSchemaNodeBuilder);
72     }
73
74     private static class FeatureDefinitionImpl implements FeatureDefinition {
75         private final QName qname;
76         private SchemaPath path;
77         private String description;
78         private String reference;
79         private Status status;
80         private List<UnknownSchemaNode> unknownSchemaNodes = Collections
81                 .emptyList();
82
83         private FeatureDefinitionImpl(QName qname) {
84             this.qname = qname;
85         }
86
87         @Override
88         public QName getQName() {
89             return qname;
90         }
91
92         @Override
93         public SchemaPath getPath() {
94             return path;
95         }
96
97         private void setPath(SchemaPath path) {
98             this.path = path;
99             ;
100         }
101
102         @Override
103         public String getDescription() {
104             return description;
105         }
106
107         private void setDescription(String description) {
108             this.description = description;
109         }
110
111         @Override
112         public String getReference() {
113             return reference;
114         }
115
116         private void setReference(String reference) {
117             this.reference = reference;
118         }
119
120         @Override
121         public Status getStatus() {
122             return status;
123         }
124
125         private void setStatus(Status status) {
126             this.status = status;
127         }
128
129         @Override
130         public List<UnknownSchemaNode> getUnknownSchemaNodes() {
131             return unknownSchemaNodes;
132         }
133
134         private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownSchemaNodes) {
135             if(unknownSchemaNodes != null) {
136                 this.unknownSchemaNodes = unknownSchemaNodes;
137             }
138         }
139
140         @Override
141         public int hashCode() {
142             final int prime = 31;
143             int result = 1;
144             result = prime * result + ((qname == null) ? 0 : qname.hashCode());
145             result = prime * result + ((path == null) ? 0 : path.hashCode());
146             return result;
147         }
148
149         @Override
150         public boolean equals(Object obj) {
151             if (this == obj) {
152                 return true;
153             }
154             if (obj == null) {
155                 return false;
156             }
157             if (getClass() != obj.getClass()) {
158                 return false;
159             }
160             FeatureDefinitionImpl other = (FeatureDefinitionImpl) obj;
161             if (qname == null) {
162                 if (other.qname != null) {
163                     return false;
164                 }
165             } else if (!qname.equals(other.qname)) {
166                 return false;
167             }
168             if (path == null) {
169                 if (other.path != null) {
170                     return false;
171                 }
172             } else if (!path.equals(other.path)) {
173                 return false;
174             }
175             return true;
176         }
177
178         @Override
179         public String toString() {
180             StringBuilder sb = new StringBuilder(
181                     FeatureDefinitionImpl.class.getSimpleName());
182             sb.append("[name=" + qname);
183             sb.append(", path=" + path + "]");
184             return sb.toString();
185         }
186     }
187
188 }