2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.yang.parser.builder.impl;
10 import java.util.ArrayList;
11 import java.util.Collections;
12 import java.util.HashSet;
13 import java.util.List;
16 import org.opendaylight.controller.yang.common.QName;
17 import org.opendaylight.controller.yang.model.api.ContainerSchemaNode;
18 import org.opendaylight.controller.yang.model.api.GroupingDefinition;
19 import org.opendaylight.controller.yang.model.api.RpcDefinition;
20 import org.opendaylight.controller.yang.model.api.SchemaPath;
21 import org.opendaylight.controller.yang.model.api.Status;
22 import org.opendaylight.controller.yang.model.api.TypeDefinition;
23 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
24 import org.opendaylight.controller.yang.parser.builder.api.GroupingBuilder;
25 import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;
26 import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionAwareBuilder;
27 import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
29 public final class RpcDefinitionBuilder implements SchemaNodeBuilder, TypeDefinitionAwareBuilder {
30 private boolean isBuilt;
31 private final RpcDefinitionImpl instance;
32 private final int line;
33 private final QName qname;
34 private SchemaPath schemaPath;
35 private String description;
36 private String reference;
37 private Status status = Status.CURRENT;
38 private ContainerSchemaNodeBuilder inputBuilder;
39 private ContainerSchemaNodeBuilder outputBuilder;
40 private final Set<TypeDefinitionBuilder> addedTypedefs = new HashSet<TypeDefinitionBuilder>();
41 private final Set<GroupingBuilder> addedGroupings = new HashSet<GroupingBuilder>();
42 private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
44 RpcDefinitionBuilder(final QName qname, final int line) {
47 this.instance = new RpcDefinitionImpl(qname);
51 public RpcDefinition build() {
53 instance.setDescription(description);
54 instance.setReference(reference);
55 instance.setStatus(status);
57 final ContainerSchemaNode input = inputBuilder == null ? null : inputBuilder.build();
58 final ContainerSchemaNode output = outputBuilder == null ? null : outputBuilder.build();
59 instance.setInput(input);
60 instance.setOutput(output);
62 instance.setPath(schemaPath);
65 final Set<TypeDefinition<?>> typedefs = new HashSet<TypeDefinition<?>>();
66 for (TypeDefinitionBuilder entry : addedTypedefs) {
67 typedefs.add(entry.build());
69 instance.setTypeDefinitions(typedefs);
72 final Set<GroupingDefinition> groupings = new HashSet<GroupingDefinition>();
73 for (GroupingBuilder entry : addedGroupings) {
74 groupings.add(entry.build());
76 instance.setGroupings(groupings);
79 final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
80 for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
81 unknownNodes.add(b.build());
83 instance.setUnknownSchemaNodes(unknownNodes);
91 public int getLine() {
95 void setInput(final ContainerSchemaNodeBuilder inputBuilder) {
96 this.inputBuilder = inputBuilder;
99 void setOutput(final ContainerSchemaNodeBuilder outputBuilder) {
100 this.outputBuilder = outputBuilder;
103 public Set<TypeDefinitionBuilder> getTypeDefinitions() {
104 return addedTypedefs;
108 public void addTypedef(final TypeDefinitionBuilder type) {
109 addedTypedefs.add(type);
112 public Set<GroupingBuilder> getGroupings() {
113 return addedGroupings;
116 public void addGrouping(GroupingBuilder grouping) {
117 addedGroupings.add(grouping);
121 public SchemaPath getPath() {
126 public void setPath(SchemaPath schemaPath) {
127 this.schemaPath = schemaPath;
131 public String getDescription() {
136 public void setDescription(final String description) {
137 this.description = description;
141 public String getReference() {
146 public void setReference(String reference) {
147 this.reference = reference;
151 public Status getStatus() {
156 public void setStatus(final Status status) {
157 if (status != null) {
158 this.status = status;
163 public QName getQName() {
168 public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
169 addedUnknownNodes.add(unknownNode);
173 public int hashCode() {
174 final int prime = 31;
176 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
177 result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());
182 public boolean equals(Object obj) {
186 if (!(obj instanceof RpcDefinitionBuilder)) {
189 final RpcDefinitionBuilder other = (RpcDefinitionBuilder) obj;
190 if (other.qname == null) {
191 if (this.qname != null) {
194 } else if (!other.qname.equals(this.qname)) {
197 if (other.schemaPath == null) {
198 if (this.schemaPath != null) {
201 } else if (!other.schemaPath.equals(this.schemaPath)) {
207 private final class RpcDefinitionImpl implements RpcDefinition {
208 private final QName qname;
209 private SchemaPath path;
210 private String description;
211 private String reference;
212 private Status status;
213 private ContainerSchemaNode input;
214 private ContainerSchemaNode output;
215 private Set<TypeDefinition<?>> typeDefinitions;
216 private Set<GroupingDefinition> groupings;
217 private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
219 private RpcDefinitionImpl(final QName qname) {
224 public QName getQName() {
229 public SchemaPath getPath() {
233 private void setPath(SchemaPath path) {
238 public String getDescription() {
242 private void setDescription(String description) {
243 this.description = description;
247 public String getReference() {
251 private void setReference(String reference) {
252 this.reference = reference;
256 public Status getStatus() {
260 private void setStatus(Status status) {
261 this.status = status;
265 public ContainerSchemaNode getInput() {
269 private void setInput(ContainerSchemaNode input) {
274 public ContainerSchemaNode getOutput() {
278 private void setOutput(ContainerSchemaNode output) {
279 this.output = output;
283 public Set<TypeDefinition<?>> getTypeDefinitions() {
284 return typeDefinitions;
287 private void setTypeDefinitions(Set<TypeDefinition<?>> typeDefinitions) {
288 this.typeDefinitions = typeDefinitions;
292 public Set<GroupingDefinition> getGroupings() {
296 private void setGroupings(Set<GroupingDefinition> groupings) {
297 this.groupings = groupings;
301 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
305 private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownNodes) {
306 if (unknownNodes != null) {
307 this.unknownNodes = unknownNodes;
312 public int hashCode() {
313 final int prime = 31;
315 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
316 result = prime * result + ((path == null) ? 0 : path.hashCode());
321 public boolean equals(Object obj) {
328 if (getClass() != obj.getClass()) {
331 final RpcDefinitionImpl other = (RpcDefinitionImpl) obj;
333 if (other.qname != null) {
336 } else if (!qname.equals(other.qname)) {
340 if (other.path != null) {
343 } else if (!path.equals(other.path)) {
350 public String toString() {
351 StringBuilder sb = new StringBuilder(RpcDefinitionImpl.class.getSimpleName() + "[");
352 sb.append("qname=" + qname);
353 sb.append(", path=" + path);
354 sb.append(", input=" + input);
355 sb.append(", output=" + output + "]");
356 return sb.toString();