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.yangtools.yang.parser.builder.impl;
10 import java.util.List;
12 import org.opendaylight.yangtools.yang.common.QName;
13 import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
14 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
15 import org.opendaylight.yangtools.yang.model.api.Status;
16 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
17 import org.opendaylight.yangtools.yang.parser.builder.api.AbstractSchemaNodeBuilder;
19 import com.google.common.collect.ImmutableList;
21 public final class ExtensionBuilder extends AbstractSchemaNodeBuilder {
22 private ExtensionDefinitionImpl instance;
23 private String argument;
26 ExtensionBuilder(final String moduleName, final int line, final QName qname, final SchemaPath path) {
27 super(moduleName, line, qname);
28 this.schemaPath = path;
32 public ExtensionDefinition build() {
33 if (instance != null) {
37 instance = new ExtensionDefinitionImpl(qname, schemaPath);
38 instance.argument = argument;
42 for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
43 unknownNodes.add(b.build());
45 instance.unknownNodes = ImmutableList.copyOf(unknownNodes);
50 public void setYinElement(boolean yin) {
54 public void setArgument(String argument) {
55 this.argument = argument;
59 public String toString() {
60 return "extension " + qname.getLocalName();
63 private static final class ExtensionDefinitionImpl implements ExtensionDefinition {
64 private final QName qname;
65 private String argument;
66 private final SchemaPath schemaPath;
67 private String description;
68 private String reference;
69 private Status status;
70 private ImmutableList<UnknownSchemaNode> unknownNodes;
73 private ExtensionDefinitionImpl(QName qname, SchemaPath path) {
75 this.schemaPath = path;
79 public QName getQName() {
84 public SchemaPath getPath() {
89 public String getDescription() {
94 public String getReference() {
99 public Status getStatus() {
104 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
109 public String getArgument() {
114 public boolean isYinElement() {
119 public int hashCode() {
120 final int prime = 31;
122 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
123 result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());
128 public boolean equals(Object obj) {
135 if (getClass() != obj.getClass()) {
138 ExtensionDefinitionImpl other = (ExtensionDefinitionImpl) obj;
140 if (other.qname != null) {
143 } else if (!qname.equals(other.qname)) {
146 if (schemaPath == null) {
147 if (other.schemaPath != null) {
150 } else if (!schemaPath.equals(other.schemaPath)) {
157 public String toString() {
158 StringBuilder sb = new StringBuilder(ExtensionDefinitionImpl.class.getSimpleName());
160 sb.append("argument=" + argument);
161 sb.append(", qname=" + qname);
162 sb.append(", schemaPath=" + schemaPath);
163 sb.append(", extensionSchemaNodes=" + unknownNodes);
164 sb.append(", yin=" + yin);
166 return sb.toString();