2 * Copyright (c) 2015 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.spi.meta;
11 import javax.annotation.Nonnull;
12 import org.opendaylight.yangtools.yang.common.QName;
13 import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
16 * An {@link IdentifierNamespace} implementing a {@link QName} internment interface. Lookups in this namespace always
17 * return a non-null object. They capture the first object instance and return that on subsequent lookups.
19 public final class QNameCacheNamespace extends NamespaceBehaviour<QName, QName, QNameCacheNamespace>
20 implements IdentifierNamespace<QName, QName> {
22 private static final QNameCacheNamespace INSTANCE = new QNameCacheNamespace();
24 private QNameCacheNamespace() {
25 super(QNameCacheNamespace.class);
28 public static QNameCacheNamespace getInstance() {
33 public QName get(@Nonnull final QName identifier) {
34 throw new UnsupportedOperationException("Identifier/implementation API borkage");
37 private static NamespaceStorageNode getRoot(final NamespaceStorageNode storage) {
38 NamespaceStorageNode wlk = storage;
40 while (wlk.getParentNamespaceStorage() != null) {
41 wlk = wlk.getParentNamespaceStorage();
48 public QName getFrom(final NamespaceStorageNode storage, final QName key) {
49 final NamespaceStorageNode root = getRoot(storage);
50 final QName stored = root.getFromLocalStorage(QNameCacheNamespace.class, key);
55 root.addToLocalStorage(QNameCacheNamespace.class, key, key);
60 public Map<QName, QName> getAllFrom(final NamespaceStorageNode storage) {
61 return getRoot(storage).getAllFromLocalStorage(QNameCacheNamespace.class);
65 public void addTo(final NamespaceStorageNode storage, final QName key, final QName value) {
66 throw new UnsupportedOperationException("Automagically populated");