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.stmt.reactor;
10 import com.google.common.collect.HashMultimap;
11 import com.google.common.collect.Multimap;
12 import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
13 import org.opendaylight.yangtools.yang.parser.spi.meta.DerivedNamespaceBehaviour;
14 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
16 final class VirtualNamespaceContext<K, V, N extends IdentifierNamespace<K, V>, D>
17 extends NamespaceBehaviourWithListeners<K, V, N> {
19 private final Multimap<D, ValueAddedListener<K>> listeners = HashMultimap.create();
20 private final DerivedNamespaceBehaviour<K, V, D, N, ?> derivedDelegate;
22 VirtualNamespaceContext(final DerivedNamespaceBehaviour<K, V, D, N, ?> delegate) {
24 this.derivedDelegate = delegate;
28 protected boolean isRequestedValue(final ValueAddedListener<K> listener, final NamespaceStorageNode storage,
30 return value == getFrom(listener.getCtxNode(), listener.getKey());
34 protected void addListener(final K key, final ValueAddedListener<K> listener) {
35 listeners.put(derivedDelegate.getSignificantKey(key), listener);
38 void addedToSourceNamespace(final NamespaceBehaviour.NamespaceStorageNode storage, final D key, final V value) {
39 notifyListeners(storage, listeners.get(key).iterator(), value);
43 public void addTo(final NamespaceStorageNode storage, final K key, final V value) {
44 delegate.addTo(storage, key, value);
45 notifyListeners(storage, listeners.get(derivedDelegate.getSignificantKey(key)).iterator(), value);
46 notifyDerivedNamespaces(storage, key, value);