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.AbstractSchemaNodeBuilder;
25 import org.opendaylight.controller.yang.parser.builder.api.GroupingBuilder;
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 extends AbstractSchemaNodeBuilder implements TypeDefinitionAwareBuilder {
30 private boolean isBuilt;
31 private final RpcDefinitionImpl instance;
32 private ContainerSchemaNodeBuilder inputBuilder;
33 private ContainerSchemaNodeBuilder outputBuilder;
34 private final Set<TypeDefinitionBuilder> addedTypedefs = new HashSet<TypeDefinitionBuilder>();
35 private final Set<GroupingBuilder> addedGroupings = new HashSet<GroupingBuilder>();
37 RpcDefinitionBuilder(final QName qname, final int line) {
39 this.instance = new RpcDefinitionImpl(qname);
43 public RpcDefinition build() {
45 instance.setDescription(description);
46 instance.setReference(reference);
47 instance.setStatus(status);
49 final ContainerSchemaNode input = inputBuilder == null ? null : inputBuilder.build();
50 final ContainerSchemaNode output = outputBuilder == null ? null : outputBuilder.build();
51 instance.setInput(input);
52 instance.setOutput(output);
54 instance.setPath(path);
57 final Set<TypeDefinition<?>> typedefs = new HashSet<TypeDefinition<?>>();
58 for (TypeDefinitionBuilder entry : addedTypedefs) {
59 typedefs.add(entry.build());
61 instance.setTypeDefinitions(typedefs);
64 final Set<GroupingDefinition> groupings = new HashSet<GroupingDefinition>();
65 for (GroupingBuilder entry : addedGroupings) {
66 groupings.add(entry.build());
68 instance.setGroupings(groupings);
71 final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
72 for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
73 unknownNodes.add(b.build());
75 instance.setUnknownSchemaNodes(unknownNodes);
82 void setInput(final ContainerSchemaNodeBuilder inputBuilder) {
83 this.inputBuilder = inputBuilder;
86 void setOutput(final ContainerSchemaNodeBuilder outputBuilder) {
87 this.outputBuilder = outputBuilder;
90 public Set<TypeDefinitionBuilder> getTypeDefinitions() {
95 public void addTypedef(final TypeDefinitionBuilder type) {
96 addedTypedefs.add(type);
99 public Set<GroupingBuilder> getGroupings() {
100 return addedGroupings;
103 public void addGrouping(GroupingBuilder grouping) {
104 addedGroupings.add(grouping);
108 public int hashCode() {
109 final int prime = 31;
111 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
112 result = prime * result + ((path == null) ? 0 : path.hashCode());
117 public boolean equals(Object obj) {
121 if (!(obj instanceof RpcDefinitionBuilder)) {
124 final RpcDefinitionBuilder other = (RpcDefinitionBuilder) obj;
125 if (other.qname == null) {
126 if (this.qname != null) {
129 } else if (!other.qname.equals(this.qname)) {
132 if (other.path == null) {
133 if (this.path != null) {
136 } else if (!other.path.equals(this.path)) {
142 private final class RpcDefinitionImpl implements RpcDefinition {
143 private final QName qname;
144 private SchemaPath path;
145 private String description;
146 private String reference;
147 private Status status;
148 private ContainerSchemaNode input;
149 private ContainerSchemaNode output;
150 private Set<TypeDefinition<?>> typeDefinitions;
151 private Set<GroupingDefinition> groupings;
152 private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
154 private RpcDefinitionImpl(final QName qname) {
159 public QName getQName() {
164 public SchemaPath getPath() {
168 private void setPath(SchemaPath path) {
173 public String getDescription() {
177 private void setDescription(String description) {
178 this.description = description;
182 public String getReference() {
186 private void setReference(String reference) {
187 this.reference = reference;
191 public Status getStatus() {
195 private void setStatus(Status status) {
196 this.status = status;
200 public ContainerSchemaNode getInput() {
204 private void setInput(ContainerSchemaNode input) {
209 public ContainerSchemaNode getOutput() {
213 private void setOutput(ContainerSchemaNode output) {
214 this.output = output;
218 public Set<TypeDefinition<?>> getTypeDefinitions() {
219 return typeDefinitions;
222 private void setTypeDefinitions(Set<TypeDefinition<?>> typeDefinitions) {
223 this.typeDefinitions = typeDefinitions;
227 public Set<GroupingDefinition> getGroupings() {
231 private void setGroupings(Set<GroupingDefinition> groupings) {
232 this.groupings = groupings;
236 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
240 private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownNodes) {
241 if (unknownNodes != null) {
242 this.unknownNodes = unknownNodes;
247 public int hashCode() {
248 final int prime = 31;
250 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
251 result = prime * result + ((path == null) ? 0 : path.hashCode());
256 public boolean equals(Object obj) {
263 if (getClass() != obj.getClass()) {
266 final RpcDefinitionImpl other = (RpcDefinitionImpl) obj;
268 if (other.qname != null) {
271 } else if (!qname.equals(other.qname)) {
275 if (other.path != null) {
278 } else if (!path.equals(other.path)) {
285 public String toString() {
286 StringBuilder sb = new StringBuilder(RpcDefinitionImpl.class.getSimpleName() + "[");
287 sb.append("qname=" + qname);
288 sb.append(", path=" + path);
289 sb.append(", input=" + input);
290 sb.append(", output=" + output + "]");
291 return sb.toString();