6662e2d2249ff79380e11372952add912953eea8
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / test / java / org / opendaylight / controller / sal / binding / test / util / MockSchemaService.java
1 /*
2  * Copyright (c) 2014 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.controller.sal.binding.test.util;
9
10 import com.google.common.collect.ClassToInstanceMap;
11 import com.google.common.collect.ImmutableClassToInstanceMap;
12 import java.util.Map;
13 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
14 import org.opendaylight.mdsal.dom.api.DOMSchemaServiceExtension;
15 import org.opendaylight.yangtools.concepts.ListenerRegistration;
16 import org.opendaylight.yangtools.util.ListenerRegistry;
17 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
18 import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
19 import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider;
20
21 public final class MockSchemaService implements DOMSchemaService, SchemaContextProvider {
22
23     private SchemaContext schemaContext;
24
25     ListenerRegistry<SchemaContextListener> listeners = ListenerRegistry.create();
26
27     @Override
28     public synchronized SchemaContext getGlobalContext() {
29         return schemaContext;
30     }
31
32     @Override
33     public synchronized SchemaContext getSessionContext() {
34         return schemaContext;
35     }
36
37     @Override
38     public ListenerRegistration<SchemaContextListener> registerSchemaContextListener(
39             final SchemaContextListener listener) {
40         return listeners.register(listener);
41     }
42
43     @Override
44     public synchronized SchemaContext getSchemaContext() {
45         return schemaContext;
46     }
47
48     @Override
49     @Deprecated
50     public Map<Class<? extends DOMSchemaServiceExtension>, DOMSchemaServiceExtension> getSupportedExtensions() {
51         return ImmutableClassToInstanceMap.of();
52     }
53
54     @Override
55     public ClassToInstanceMap<DOMSchemaServiceExtension> getExtensions() {
56         return ImmutableClassToInstanceMap.of();
57     }
58
59     public synchronized void changeSchema(final SchemaContext newContext) {
60         schemaContext = newContext;
61         for (ListenerRegistration<SchemaContextListener> listener : listeners) {
62             listener.getInstance().onGlobalContextUpdated(schemaContext);
63         }
64     }
65 }