e59e5e606f4cdb602bf939832d3a1f9d6c2215da
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / reactor / SimpleNamespaceContext.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 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;
15
16 final class SimpleNamespaceContext<K, V, N extends IdentifierNamespace<K, V>>
17         extends NamespaceBehaviourWithListeners<K, V, N> {
18
19     // FIXME: Change this to Multimap, once issue with modules is resolved.
20     private final List<ValueAddedListener<K>> listeners = new ArrayList<>();
21
22     SimpleNamespaceContext(final NamespaceBehaviour<K, V, N> delegate) {
23         super(delegate);
24     }
25
26     @Override
27     void addListener(final K key, final ValueAddedListener<K> listener) {
28         listeners.add(listener);
29     }
30
31     private Iterator<ValueAddedListener<K>> getMutableListeners(final K key) {
32         return listeners.iterator();
33     }
34
35     @Override
36     public void addTo(final NamespaceStorageNode storage, final K key, final V value) {
37         delegate.addTo(storage, key, value);
38         notifyListeners(storage, getMutableListeners(key), value);
39         notifyDerivedNamespaces(storage, key, value);
40     }
41 }