Merge "Snapshot changes"
[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 org.opendaylight.controller.sal.core.api.model.SchemaService;
11 import org.opendaylight.controller.sal.dom.broker.impl.SchemaContextProvider;
12 import org.opendaylight.yangtools.concepts.ListenerRegistration;
13 import org.opendaylight.yangtools.concepts.util.ListenerRegistry;
14 import org.opendaylight.yangtools.yang.model.api.Module;
15 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
16 import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
17
18 @SuppressWarnings("deprecation")
19 public final class MockSchemaService implements SchemaService, SchemaContextProvider {
20
21     private SchemaContext schemaContext;
22
23     ListenerRegistry<SchemaContextListener> listeners = ListenerRegistry.create();
24
25     @Override
26     public void addModule(final Module module) {
27         throw new UnsupportedOperationException();
28     }
29
30     @Override
31     public synchronized SchemaContext getGlobalContext() {
32         return schemaContext;
33     }
34
35     @Override
36     public synchronized SchemaContext getSessionContext() {
37         return schemaContext;
38     }
39
40     @Override
41     public ListenerRegistration<SchemaContextListener> registerSchemaContextListener(
42             final SchemaContextListener listener) {
43         return listeners.register(listener);
44     }
45
46     @Override
47     public void removeModule(final Module module) {
48         throw new UnsupportedOperationException();
49     }
50
51     @Override
52     public synchronized SchemaContext getSchemaContext() {
53         return schemaContext;
54     }
55
56     public synchronized void changeSchema(final SchemaContext newContext) {
57         schemaContext = newContext;
58         for (ListenerRegistration<SchemaContextListener> listener : listeners) {
59             listener.getInstance().onGlobalContextUpdated(schemaContext);
60         }
61     }
62 }