Initial opendaylight infrastructure commit!!
[controller.git] / opendaylight / sal / yang-prototype / code-generator / yang-model-parser-impl / src / main / java / org / opendaylight / controller / model / parser / builder / FeatureBuilder.java
1 /*\r
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
3  *\r
4  * This program and the accompanying materials are made available under the\r
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
6  * and is available at http://www.eclipse.org/legal/epl-v10.html\r
7  */\r
8 package org.opendaylight.controller.model.parser.builder;\r
9 \r
10 import java.util.List;\r
11 \r
12 import org.opendaylight.controller.model.parser.api.SchemaNodeBuilder;\r
13 import org.opendaylight.controller.yang.common.QName;\r
14 import org.opendaylight.controller.yang.model.api.ExtensionDefinition;\r
15 import org.opendaylight.controller.yang.model.api.FeatureDefinition;\r
16 import org.opendaylight.controller.yang.model.api.SchemaNode;\r
17 import org.opendaylight.controller.yang.model.api.SchemaPath;\r
18 import org.opendaylight.controller.yang.model.api.Status;\r
19 \r
20 \r
21 public class FeatureBuilder implements SchemaNodeBuilder {\r
22 \r
23         private final FeatureDefinitionImpl instance;\r
24         private final QName qname;\r
25 \r
26         FeatureBuilder(QName qname) {\r
27                 this.qname = qname;\r
28                 instance = new FeatureDefinitionImpl(qname);\r
29         }\r
30 \r
31         @Override\r
32         public SchemaNode build() {\r
33                 return instance;\r
34         }\r
35 \r
36         @Override\r
37         public QName getQName() {\r
38                 return qname;\r
39         }\r
40 \r
41         @Override\r
42         public void setPath(SchemaPath path) {\r
43                 instance.setPath(path);\r
44         }\r
45 \r
46         @Override\r
47         public void setDescription(String description) {\r
48                 instance.setDescription(description);\r
49         }\r
50 \r
51         @Override\r
52         public void setReference(String reference) {\r
53                 instance.setReference(reference);\r
54         }\r
55 \r
56         @Override\r
57         public void setStatus(Status status) {\r
58                 instance.setStatus(status);\r
59         }\r
60 \r
61         private static class FeatureDefinitionImpl implements FeatureDefinition {\r
62 \r
63                 private final QName qname;\r
64                 private SchemaPath path;\r
65                 private String description;\r
66                 private String reference;\r
67                 private Status status;\r
68 \r
69                 private FeatureDefinitionImpl(QName qname) {\r
70                         this.qname = qname;\r
71                 }\r
72 \r
73                 @Override\r
74                 public QName getQName() {\r
75                         return qname;\r
76                 }\r
77 \r
78                 @Override\r
79                 public SchemaPath getPath() {\r
80                         return path;\r
81                 }\r
82                 private void setPath(SchemaPath path) {\r
83                         this.path = path;;\r
84                 }\r
85 \r
86                 @Override\r
87                 public String getDescription() {\r
88                         return description;\r
89                 }\r
90                 private void setDescription(String description) {\r
91                         this.description = description;\r
92                 }\r
93 \r
94                 @Override\r
95                 public String getReference() {\r
96                         return reference;\r
97                 }\r
98                 private void setReference(String reference) {\r
99                         this.reference = reference;\r
100                 }\r
101 \r
102                 @Override\r
103                 public Status getStatus() {\r
104                         return status;\r
105                 }\r
106                 private void setStatus(Status status) {\r
107                         this.status = status;\r
108                 }\r
109 \r
110                 @Override\r
111                 public List<ExtensionDefinition> getExtensionSchemaNodes() {\r
112                         // TODO Auto-generated method stub\r
113                         return null;\r
114                 }\r
115 \r
116                 @Override\r
117         public int hashCode() {\r
118             final int prime = 31;\r
119             int result = 1;\r
120             result = prime * result + ((qname == null) ? 0 : qname.hashCode());\r
121             result = prime * result + ((path == null) ? 0 : path.hashCode());\r
122             result = prime * result + ((description == null) ? 0 : description.hashCode());\r
123             result = prime * result + ((reference == null) ? 0 : reference.hashCode());\r
124             result = prime * result + ((status == null) ? 0 : status.hashCode());\r
125             return result;\r
126         }\r
127 \r
128         @Override\r
129         public boolean equals(Object obj) {\r
130             if (this == obj) {\r
131                 return true;\r
132             }\r
133             if (obj == null) {\r
134                 return false;\r
135             }\r
136             if (getClass() != obj.getClass()) {\r
137                 return false;\r
138             }\r
139             FeatureDefinitionImpl other = (FeatureDefinitionImpl) obj;\r
140             if (qname == null) {\r
141                 if (other.qname != null) {\r
142                     return false;\r
143                 }\r
144             } else if (!qname.equals(other.qname)) {\r
145                 return false;\r
146             }\r
147             if (path == null) {\r
148                 if (other.path != null) {\r
149                     return false;\r
150                 }\r
151             } else if (!path.equals(other.path)) {\r
152                 return false;\r
153             }\r
154             if (description == null) {\r
155                 if (other.description != null) {\r
156                     return false;\r
157                 }\r
158             } else if (!description.equals(other.description)) {\r
159                 return false;\r
160             }\r
161             if (reference == null) {\r
162                 if (other.reference != null) {\r
163                     return false;\r
164                 }\r
165             } else if (!reference.equals(other.reference)) {\r
166                 return false;\r
167             }\r
168             if (status == null) {\r
169                 if (other.status != null) {\r
170                     return false;\r
171                 }\r
172             } else if (!status.equals(other.status)) {\r
173                 return false;\r
174             }\r
175             return true;\r
176         }\r
177 \r
178                 @Override\r
179                 public String toString() {\r
180                         StringBuilder sb = new StringBuilder(FeatureDefinitionImpl.class.getSimpleName());\r
181                         sb.append("[name="+ qname);\r
182                         sb.append(", path="+ path);\r
183                         sb.append(", description="+ description);\r
184                         sb.append(", reference="+ reference);\r
185                         sb.append(", status="+ status +"]");\r
186                         return sb.toString();\r
187                 }\r
188         }\r
189 \r
190 }\r