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.AbstractSchemaNodeBuilder;
21 public final class IdentitySchemaNodeBuilder extends AbstractSchemaNodeBuilder {
22 private boolean isBuilt;
23 private final IdentitySchemaNodeImpl instance;
24 private IdentitySchemaNodeBuilder baseIdentityBuilder;
25 private IdentitySchemaNode baseIdentity;
26 private String baseIdentityName;
28 IdentitySchemaNodeBuilder(final QName qname, final int line) {
30 instance = new IdentitySchemaNodeImpl(qname);
34 public IdentitySchemaNode build() {
36 instance.setPath(path);
37 instance.setDescription(description);
38 instance.setReference(reference);
39 instance.setStatus(status);
41 if (baseIdentity == null) {
42 if (baseIdentityBuilder != null) {
43 instance.setBaseIdentity(baseIdentityBuilder.build());
46 instance.setBaseIdentity(baseIdentity);
50 final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
51 for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
52 unknownNodes.add(b.build());
54 instance.setUnknownSchemaNodes(unknownNodes);
62 public String getBaseIdentityName() {
63 return baseIdentityName;
66 public void setBaseIdentityName(final String baseIdentityName) {
67 this.baseIdentityName = baseIdentityName;
70 public void setBaseIdentity(final IdentitySchemaNodeBuilder baseType) {
71 this.baseIdentityBuilder = baseType;
74 public void setBaseIdentity(final IdentitySchemaNode baseType) {
75 this.baseIdentity = baseType;
78 private final class IdentitySchemaNodeImpl implements IdentitySchemaNode {
79 private final QName qname;
80 private IdentitySchemaNode baseIdentity;
81 private String description;
82 private String reference;
83 private Status status = Status.CURRENT;
84 private SchemaPath path;
85 private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
87 private IdentitySchemaNodeImpl(final QName qname) {
92 public QName getQName() {
97 public IdentitySchemaNode getBaseIdentity() {
101 private void setBaseIdentity(final IdentitySchemaNode baseIdentity) {
102 this.baseIdentity = baseIdentity;
106 public String getDescription() {
110 private void setDescription(final String description) {
111 this.description = description;
115 public String getReference() {
119 private void setReference(final String reference) {
120 this.reference = reference;
124 public Status getStatus() {
128 private void setStatus(final Status status) {
129 if (status != null) {
130 this.status = status;
135 public SchemaPath getPath() {
139 private void setPath(final SchemaPath path) {
144 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
148 private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownSchemaNodes) {
149 if (unknownSchemaNodes != null) {
150 this.unknownNodes = unknownSchemaNodes;
155 public int hashCode() {
156 final int prime = 31;
158 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
159 result = prime * result + ((path == null) ? 0 : path.hashCode());
164 public boolean equals(Object obj) {
171 if (getClass() != obj.getClass()) {
174 IdentitySchemaNodeImpl other = (IdentitySchemaNodeImpl) obj;
176 if (other.qname != null) {
179 } else if (!qname.equals(other.qname)) {
183 if (other.path != null) {
186 } else if (!path.equals(other.path)) {
193 public String toString() {
194 StringBuilder sb = new StringBuilder(IdentitySchemaNodeImpl.class.getSimpleName());
196 sb.append("base=" + baseIdentity);
197 sb.append(", qname=" + qname);
199 return sb.toString();