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;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.base.MoreObjects.ToStringHelper;
16 * An {@link NamespaceBehaviour} which derives keys from a different namespace.
19 * @param <V> Value type
20 * @param <N> Namespace type
21 * @param <L> Original key type
22 * @param <O> Original namespace type
24 public abstract class DerivedNamespaceBehaviour<K, V, L, N extends ParserNamespace<K, V>,
25 O extends ParserNamespace<L, ?>> extends NamespaceBehaviour<K, V, N> {
27 private final Class<O> derivedFrom;
29 protected DerivedNamespaceBehaviour(final Class<N> identifier, final Class<O> derivedFrom) {
31 this.derivedFrom = requireNonNull(derivedFrom);
34 public Class<O> getDerivedFrom() {
39 public Map<K, V> getAllFrom(final NamespaceStorageNode storage) {
40 throw new UnsupportedOperationException("Virtual namespaces does not support provision of all items.");
44 public abstract V getFrom(NamespaceBehaviour.NamespaceStorageNode storage, K key);
47 public void addTo(final NamespaceStorageNode storage, final K key, final V value) {
51 public abstract L getSignificantKey(K key);
54 protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
55 return helper.add("derivedFrom", derivedFrom.getName());