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.model.util;
10 import java.util.Collections;
11 import java.util.List;
13 import org.opendaylight.yangtools.concepts.Immutable;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
16 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
17 import org.opendaylight.yangtools.yang.model.api.Status;
18 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefinition;
22 * The <code>default</code> implementation of Instance Identifier Type
23 * Definition interface.
25 * Instance Identifier has only two possible variants - one with
26 * {@link #requireInstance()} which returns true, other one
29 * @see InstanceIdentifierTypeDefinition
32 public final class InstanceIdentifierType implements InstanceIdentifierTypeDefinition, Immutable {
34 private static final QName NAME = BaseTypes.INSTANCE_IDENTIFIER_QNAME;
35 private static final SchemaPath PATH = SchemaPath.create(true, NAME);
36 private static final String DESCRIPTION = "The instance-identifier built-in type is used to "
37 + "uniquely identify a particular instance node in the data tree.";
38 private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.13";
40 private static final String UNITS = "";
41 private final Boolean requireInstance;
43 private static final InstanceIdentifierType INSTANCE_WITH_REQUIRED_TRUE = new InstanceIdentifierType(true);
44 private static final InstanceIdentifierType INSTANCE_WITH_REQUIRED_FALSE = new InstanceIdentifierType(false);
47 * Constructs new instance identifier.
50 * @deprecated Use {@link #getInstance()} for default one, since Instance Identifier does not have xpath.
53 public InstanceIdentifierType(final RevisionAwareXPath xpath) {
54 requireInstance = true;
58 * Constructs new instance identifier.
61 * @param requireInstance if instance of data is required
62 * @deprecated Use {@link #create(boolean)}, since Instance Identifier does not have xpath.
65 public InstanceIdentifierType(final RevisionAwareXPath xpath, final boolean requireInstance) {
66 this.requireInstance = requireInstance;
69 private InstanceIdentifierType(final boolean requiredInstance) {
70 this.requireInstance = requiredInstance;
73 public static InstanceIdentifierType getInstance() {
74 return INSTANCE_WITH_REQUIRED_TRUE;
77 public static InstanceIdentifierType create(final boolean requireInstance) {
78 return requireInstance ? INSTANCE_WITH_REQUIRED_TRUE : INSTANCE_WITH_REQUIRED_FALSE;
85 * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
88 public InstanceIdentifierTypeDefinition getBaseType() {
95 * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits()
98 public String getUnits() {
106 * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue
110 public Object getDefaultValue() {
117 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName()
120 public QName getQName() {
127 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath()
130 public SchemaPath getPath() {
138 * org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
141 public String getDescription() {
148 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference()
151 public String getReference() {
158 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus()
161 public Status getStatus() {
162 return Status.CURRENT;
169 * org.opendaylight.yangtools.yang.model.api.SchemaNode#getExtensionSchemaNodes
173 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
174 return Collections.emptyList();
180 * @see org.opendaylight.yangtools.yang.model.api.type.
181 * InstanceIdentifierTypeDefinition# getPathStatement()
185 public RevisionAwareXPath getPathStatement() {
192 * @see org.opendaylight.yangtools.yang.model.api.type.
193 * InstanceIdentifierTypeDefinition# requireInstance()
196 public boolean requireInstance() {
197 return requireInstance;
201 public int hashCode() {
202 final int prime = 31;
204 result = prime * result + requireInstance.hashCode();
209 public boolean equals(final Object obj) {
216 if (getClass() != obj.getClass()) {
219 InstanceIdentifierType other = (InstanceIdentifierType) obj;
220 return requireInstance.equals(other.requireInstance);