2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.sal.binding.test.util;
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;
20 public final class MockSchemaService implements DOMSchemaService, SchemaContextProvider {
22 private SchemaContext schemaContext;
24 ListenerRegistry<SchemaContextListener> listeners = ListenerRegistry.create();
27 public synchronized SchemaContext getGlobalContext() {
32 public synchronized SchemaContext getSessionContext() {
37 public ListenerRegistration<SchemaContextListener> registerSchemaContextListener(
38 final SchemaContextListener listener) {
39 return listeners.register(listener);
43 public synchronized SchemaContext getSchemaContext() {
48 public ClassToInstanceMap<DOMSchemaServiceExtension> getExtensions() {
49 return ImmutableClassToInstanceMap.of();
52 public synchronized void changeSchema(final SchemaContext newContext) {
53 schemaContext = newContext;
54 for (ListenerRegistration<? extends SchemaContextListener> listener : listeners.getRegistrations()) {
55 listener.getInstance().onGlobalContextUpdated(schemaContext);