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.Collections;
11 import java.util.List;
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.model.api.*;
15 import org.opendaylight.yangtools.yang.model.api.type.*;
16 import org.opendaylight.yangtools.yang.model.util.BaseTypes;
17 import org.opendaylight.yangtools.yang.model.util.IdentityrefType;
18 import org.opendaylight.yangtools.yang.parser.builder.api.AbstractTypeAwareBuilder;
19 import org.opendaylight.yangtools.yang.parser.builder.api.TypeDefinitionBuilder;
20 import org.opendaylight.yangtools.yang.parser.util.YangParseException;
23 * Builder for YANG identityref type.
25 public final class IdentityrefTypeBuilder extends AbstractTypeAwareBuilder implements TypeDefinitionBuilder {
26 private static final String NAME = "identityref";
28 private final String baseString;
29 private SchemaPath schemaPath;
30 private IdentitySchemaNodeBuilder baseIdentity;
32 public IdentityrefTypeBuilder(final String moduleName, final int line, final String baseString,
33 final SchemaPath schemaPath) {
34 super(moduleName, line, BaseTypes.constructQName(NAME));
35 this.baseString = baseString;
36 this.schemaPath = schemaPath;
40 public void setQName(QName qname) {
45 public IdentityrefType build() {
46 return new IdentityrefType(baseIdentity.build(), schemaPath);
49 public String getBaseString() {
53 public void setBaseIdentity(IdentitySchemaNodeBuilder baseIdentity) {
54 this.baseIdentity = baseIdentity;
58 public TypeDefinition<?> getType() {
63 public TypeDefinitionBuilder getTypedef() {
68 public void setType(final TypeDefinition<?> type) {
69 throw new YangParseException(moduleName, line, "Can not set type to " + NAME);
73 public void setTypedef(final TypeDefinitionBuilder tdb) {
74 throw new YangParseException(moduleName, line, "Can not set type to " + NAME);
78 public void setDescription(final String description) {
79 throw new YangParseException(moduleName, line, "Can not set description to " + NAME);
83 public void setReference(final String reference) {
84 throw new YangParseException(moduleName, line, "Can not set reference to " + NAME);
88 public void setStatus(final Status status) {
89 throw new YangParseException(moduleName, line, "Can not set status to " + NAME);
93 public boolean isAddedByUses() {
98 public void setAddedByUses(final boolean addedByUses) {
99 throw new YangParseException(moduleName, line, "Identityref type can not be added by uses.");
103 public void addUnknownNodeBuilder(final UnknownSchemaNodeBuilder unknownNode) {
104 throw new YangParseException(moduleName, line, "Can not add unknown node to " + NAME);
108 public QName getQName() {
113 public SchemaPath getPath() {
118 public void setPath(SchemaPath path) {
119 this.schemaPath = path;
123 public String getDescription() {
128 public String getReference() {
133 public Status getStatus() {
138 public List<RangeConstraint> getRanges() {
139 return Collections.emptyList();
143 public void setRanges(List<RangeConstraint> ranges) {
144 throw new YangParseException(moduleName, line, "Can not set ranges to " + NAME);
148 public List<LengthConstraint> getLengths() {
149 return Collections.emptyList();
153 public void setLengths(List<LengthConstraint> lengths) {
154 throw new YangParseException(moduleName, line, "Can not set lengths to " + NAME);
158 public List<PatternConstraint> getPatterns() {
159 return Collections.emptyList();
163 public void setPatterns(List<PatternConstraint> patterns) {
164 throw new YangParseException(moduleName, line, "Can not set patterns to " + NAME);
168 public Integer getFractionDigits() {
173 public void setFractionDigits(Integer fractionDigits) {
174 throw new YangParseException(moduleName, line, "Can not set fraction digits to " + NAME);
178 public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
179 return Collections.emptyList();
183 public Object getDefaultValue() {
188 public void setDefaultValue(Object defaultValue) {
189 throw new YangParseException(moduleName, line, "Can not set default value to " + NAME);
193 public String getUnits() {
198 public void setUnits(String units) {
199 throw new YangParseException(moduleName, line, "Can not set units to " + NAME);
203 public String toString() {
204 final StringBuilder result = new StringBuilder(IdentityrefTypeBuilder.class.getSimpleName());
206 result.append(", base=");
207 result.append(baseIdentity);
209 return result.toString();