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 java.util.ArrayList;
11 import java.util.Iterator;
12 import java.util.List;
13 import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
14 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
16 final class SimpleNamespaceContext<K, V, N extends IdentifierNamespace<K, V>>
17 extends NamespaceBehaviourWithListeners<K, V, N> {
19 // FIXME: Change this to Multimap, once issue with modules
21 private final List<NamespaceBehaviourWithListeners.ValueAddedListener<K>> listeners = new ArrayList<>();
22 public SimpleNamespaceContext(NamespaceBehaviour<K, V, N> delegate) {
26 protected boolean isRequestedValue(NamespaceBehaviourWithListeners.ValueAddedListener<K> listener, NamespaceStorageNode storage, V value) {
27 NamespaceStorageNode listenerCtx = listener.getCtxNode();
28 return value == getFrom(listenerCtx, listener.getKey());
32 protected void addListener(K key, NamespaceBehaviourWithListeners.ValueAddedListener<K> listener) {
33 listeners.add(listener);
36 private Iterator<NamespaceBehaviourWithListeners.ValueAddedListener<K>> getMutableListeners(K key) {
37 return listeners.iterator();
41 public void addTo(final NamespaceStorageNode storage, final K key, final V value) {
42 delegate.addTo(storage, key, value);
43 notifyListeners(storage, getMutableListeners(key), value);
44 notifyDerivedNamespaces(storage, key, value);