Seal PathArgumentList
[yangtools.git] / parser / yang-parser-reactor / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / reactor / VirtualNamespaceContext.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.stmt.reactor;
9
10 import com.google.common.collect.HashMultimap;
11 import com.google.common.collect.Multimap;
12 import org.opendaylight.yangtools.yang.parser.spi.meta.DerivedNamespaceBehaviour;
13
14 final class VirtualNamespaceContext<K, V, D> extends NamespaceBehaviourWithListeners<K, V> {
15     private final Multimap<D, KeyedValueAddedListener<K>> listeners = HashMultimap.create();
16     private final DerivedNamespaceBehaviour<K, V, D, ?> derivedDelegate;
17
18     VirtualNamespaceContext(final DerivedNamespaceBehaviour<K, V, D, ?> delegate) {
19         super(delegate);
20         this.derivedDelegate = delegate;
21     }
22
23     @Override
24     void addListener(final KeyedValueAddedListener<K> listener) {
25         listeners.put(derivedDelegate.getSignificantKey(listener.getKey()), listener);
26     }
27
28     @Override
29     void addListener(final PredicateValueAddedListener<K, V> listener) {
30         throw new UnsupportedOperationException("Virtual namespaces support only exact lookups");
31     }
32
33     void addedToSourceNamespace(final NamespaceStorageNode storage, final D key, final V value) {
34         notifyListeners(storage, listeners.get(key).iterator(), value);
35     }
36
37     @Override
38     public void addTo(final NamespaceStorageNode storage, final K key, final V value) {
39         delegate.addTo(storage, key, value);
40         notifyListeners(storage, listeners.get(derivedDelegate.getSignificantKey(key)).iterator(), value);
41         notifyDerivedNamespaces(storage, key, value);
42     }
43 }