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.List;
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.parser.builder.api.SchemaNodeBuilder;
21 public final class IdentitySchemaNodeBuilder implements SchemaNodeBuilder {
22 private boolean isBuilt;
23 private final IdentitySchemaNodeImpl instance;
24 private final int line;
25 private final QName qname;
26 private SchemaPath schemaPath;
27 private String description;
28 private String reference;
29 private Status status = Status.CURRENT;
30 private IdentitySchemaNodeBuilder baseIdentityBuilder;
31 private IdentitySchemaNode baseIdentity;
32 private String baseIdentityName;
33 private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
35 IdentitySchemaNodeBuilder(final QName qname, final int line) {
38 instance = new IdentitySchemaNodeImpl(qname);
42 public IdentitySchemaNode build() {
44 instance.setPath(schemaPath);
45 instance.setDescription(description);
46 instance.setReference(reference);
47 instance.setStatus(status);
49 if (baseIdentity == null) {
50 if (baseIdentityBuilder != null) {
51 instance.setBaseIdentity(baseIdentityBuilder.build());
54 instance.setBaseIdentity(baseIdentity);
58 final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
59 for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
60 unknownNodes.add(b.build());
62 instance.setUnknownSchemaNodes(unknownNodes);
71 public int getLine() {
76 public QName getQName() {
81 public SchemaPath getPath() {
86 public void setPath(SchemaPath schemaPath) {
87 this.schemaPath = schemaPath;
91 public String getDescription() {
96 public void setDescription(final String description) {
97 this.description = description;
101 public String getReference() {
106 public void setReference(final String reference) {
107 this.reference = reference;
111 public Status getStatus() {
116 public void setStatus(final Status status) {
117 if (status != null) {
118 this.status = status;
123 public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
124 addedUnknownNodes.add(unknownNode);
127 public String getBaseIdentityName() {
128 return baseIdentityName;
131 public void setBaseIdentityName(final String baseIdentityName) {
132 this.baseIdentityName = baseIdentityName;
135 public void setBaseIdentity(final IdentitySchemaNodeBuilder baseType) {
136 this.baseIdentityBuilder = baseType;
139 public void setBaseIdentity(final IdentitySchemaNode baseType) {
140 this.baseIdentity = baseType;
143 private final class IdentitySchemaNodeImpl implements IdentitySchemaNode {
144 private final QName qname;
145 private IdentitySchemaNode baseIdentity;
146 private String description;
147 private String reference;
148 private Status status = Status.CURRENT;
149 private SchemaPath path;
150 private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
152 private IdentitySchemaNodeImpl(final QName qname) {
157 public QName getQName() {
162 public IdentitySchemaNode getBaseIdentity() {
166 private void setBaseIdentity(final IdentitySchemaNode baseIdentity) {
167 this.baseIdentity = baseIdentity;
171 public String getDescription() {
175 private void setDescription(final String description) {
176 this.description = description;
180 public String getReference() {
184 private void setReference(final String reference) {
185 this.reference = reference;
189 public Status getStatus() {
193 private void setStatus(final Status status) {
194 if (status != null) {
195 this.status = status;
200 public SchemaPath getPath() {
204 private void setPath(final SchemaPath path) {
209 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
213 private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownSchemaNodes) {
214 if (unknownSchemaNodes != null) {
215 this.unknownNodes = unknownSchemaNodes;
220 public int hashCode() {
221 final int prime = 31;
223 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
224 result = prime * result + ((path == null) ? 0 : path.hashCode());
229 public boolean equals(Object obj) {
236 if (getClass() != obj.getClass()) {
239 IdentitySchemaNodeImpl other = (IdentitySchemaNodeImpl) obj;
241 if (other.qname != null) {
244 } else if (!qname.equals(other.qname)) {
248 if (other.path != null) {
251 } else if (!path.equals(other.path)) {
258 public String toString() {
259 StringBuilder sb = new StringBuilder(IdentitySchemaNodeImpl.class.getSimpleName());
261 sb.append("base=" + baseIdentity);
262 sb.append(", qname=" + qname);
264 return sb.toString();