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 org.opendaylight.yangtools.yang.common.QName;
12 import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
15 * An {@link IdentifierNamespace} implementing a {@link QName} internment interface. Lookups in this namespace always
16 * return a non-null object. They capture the first object instance and return that on subsequent lookups.
18 public final class QNameCacheNamespace extends NamespaceBehaviour<QName, QName, QNameCacheNamespace>
19 implements IdentifierNamespace<QName, QName> {
21 private static final QNameCacheNamespace INSTANCE = new QNameCacheNamespace();
23 private QNameCacheNamespace() {
24 super(QNameCacheNamespace.class);
27 public static QNameCacheNamespace getInstance() {
32 public QName get(final QName identifier) {
33 throw new UnsupportedOperationException("Identifier/implementation API borkage");
36 private static NamespaceStorageNode getRoot(final NamespaceStorageNode storage) {
37 NamespaceStorageNode wlk = storage;
39 while (wlk.getParentNamespaceStorage() != null) {
40 wlk = wlk.getParentNamespaceStorage();
47 public QName getFrom(final NamespaceStorageNode storage, final QName key) {
48 final NamespaceStorageNode root = getRoot(storage);
49 final QName stored = root.getFromLocalStorage(QNameCacheNamespace.class, key);
54 root.addToLocalStorage(QNameCacheNamespace.class, key, key);
59 public Map<QName, QName> getAllFrom(final NamespaceStorageNode storage) {
60 return getRoot(storage).getAllFromLocalStorage(QNameCacheNamespace.class);
64 public void addTo(final NamespaceStorageNode storage, final QName key, final QName value) {
65 throw new UnsupportedOperationException("Automagically populated");