f4193bea7b5166888b8db28a420a29223ee19c3f
[yangtools.git] / yang / yang-parser-spi / src / main / java / org / opendaylight / yangtools / yang / parser / spi / meta / DerivedNamespaceBehaviour.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.parser.spi.meta;
9
10 import com.google.common.base.Preconditions;
11 import java.util.Map;
12 import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
13
14 @SuppressWarnings("checkstyle:classTypeParameterName")
15 public abstract class DerivedNamespaceBehaviour<K, V, DK, N extends IdentifierNamespace<K, V>,
16        DN extends IdentifierNamespace<DK, ?>> extends NamespaceBehaviour<K, V, N> {
17
18     private final Class<DN> derivedFrom;
19
20     protected DerivedNamespaceBehaviour(Class<N> identifier, Class<DN> derivedFrom) {
21         super(identifier);
22         this.derivedFrom = Preconditions.checkNotNull(derivedFrom);
23     }
24
25     public Class<DN> getDerivedFrom() {
26         return derivedFrom;
27     }
28
29     @Override
30     public Map<K, V> getAllFrom(NamespaceStorageNode storage) {
31         throw new UnsupportedOperationException("Virtual namespaces does not support provision of all items.");
32     }
33
34     @Override
35     public abstract V getFrom(NamespaceBehaviour.NamespaceStorageNode storage, K key);
36
37     @Override
38     public void addTo(NamespaceStorageNode storage, K key, V value) {
39         // Intentional noop
40     }
41
42     public abstract DK getSignificantKey(K key);
43 }