Updated SchemaNodeIdentifier namespace handling.
[yangtools.git] / yang / yang-parser-impl / 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 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 VirtualNamespaceContext<K, V, N extends IdentifierNamespace<K, V>>
17         extends NamespaceBehaviourWithListeners<K, V, N> {
18
19     private final List<NamespaceBehaviourWithListeners.ValueAddedListener<K>> listeners = new ArrayList<>(20);
20
21     public VirtualNamespaceContext(NamespaceBehaviour<K, V, N> delegate) {
22         super(delegate);
23     }
24
25     protected boolean isRequestedValue(NamespaceBehaviourWithListeners.ValueAddedListener<K> listener, NamespaceStorageNode storage, V value) {
26         return value == getFrom(listener.getCtxNode(), listener.getKey());
27     }
28
29     @Override
30     protected void addListener(K key, NamespaceBehaviourWithListeners.ValueAddedListener<K> listener) {
31         listeners.add(listener);
32     }
33
34     @Override
35     protected Iterator<NamespaceBehaviourWithListeners.ValueAddedListener<K>> getMutableListeners(K key) {
36         return listeners.iterator();
37     }
38 }