df192a75cb633470a6056c7fe9ed1eb5e7b87e9d
[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 org.opendaylight.mdsal.dom.api.DOMSchemaService;
13 import org.opendaylight.mdsal.dom.api.DOMSchemaServiceExtension;
14 import org.opendaylight.yangtools.concepts.ListenerRegistration;
15 import org.opendaylight.yangtools.util.ListenerRegistry;
16 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
17 import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
18 import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider;
19
20 public final class MockSchemaService implements DOMSchemaService, SchemaContextProvider {
21
22     private SchemaContext schemaContext;
23
24     ListenerRegistry<SchemaContextListener> listeners = ListenerRegistry.create();
25
26     @Override
27     public synchronized SchemaContext getGlobalContext() {
28         return schemaContext;
29     }
30
31     @Override
32     public synchronized SchemaContext getSessionContext() {
33         return schemaContext;
34     }
35
36     @Override
37     public ListenerRegistration<SchemaContextListener> registerSchemaContextListener(
38             final SchemaContextListener listener) {
39         return listeners.register(listener);
40     }
41
42     @Override
43     public synchronized SchemaContext getSchemaContext() {
44         return schemaContext;
45     }
46
47     @Override
48     public ClassToInstanceMap<DOMSchemaServiceExtension> getExtensions() {
49         return ImmutableClassToInstanceMap.of();
50     }
51
52     public synchronized void changeSchema(final SchemaContext newContext) {
53         schemaContext = newContext;
54         for (ListenerRegistration<? extends SchemaContextListener> listener : listeners.getRegistrations()) {
55             listener.getInstance().onGlobalContextUpdated(schemaContext);
56         }
57     }
58 }