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