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.mdsal.binding.dom.adapter.test.util;
10 import static com.google.common.base.Verify.verifyNotNull;
12 import com.google.common.collect.ClassToInstanceMap;
13 import com.google.common.collect.ImmutableClassToInstanceMap;
14 import org.opendaylight.mdsal.binding.dom.adapter.AdapterContext;
15 import org.opendaylight.mdsal.binding.dom.adapter.CurrentAdapterSerializer;
16 import org.opendaylight.mdsal.binding.dom.codec.impl.BindingCodecContext;
17 import org.opendaylight.mdsal.binding.runtime.api.BindingRuntimeContext;
18 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
19 import org.opendaylight.mdsal.dom.api.DOMSchemaServiceExtension;
20 import org.opendaylight.yangtools.concepts.ListenerRegistration;
21 import org.opendaylight.yangtools.util.ListenerRegistry;
22 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
23 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextListener;
24 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextProvider;
26 public final class MockSchemaService implements DOMSchemaService, EffectiveModelContextProvider, AdapterContext {
27 private EffectiveModelContext schemaContext;
28 private CurrentAdapterSerializer serializer;
30 final ListenerRegistry<EffectiveModelContextListener> listeners = ListenerRegistry.create();
33 public synchronized EffectiveModelContext getGlobalContext() {
38 public ListenerRegistration<EffectiveModelContextListener> registerSchemaContextListener(
39 final EffectiveModelContextListener listener) {
40 return listeners.register(listener);
44 public synchronized EffectiveModelContext getEffectiveModelContext() {
49 public ClassToInstanceMap<DOMSchemaServiceExtension> getExtensions() {
50 return ImmutableClassToInstanceMap.of();
53 public synchronized void changeSchema(final BindingRuntimeContext newContext) {
54 serializer = new CurrentAdapterSerializer(new BindingCodecContext(newContext));
55 schemaContext = newContext.getEffectiveModelContext();
56 listeners.streamListeners().forEach(listener -> listener.onModelContextUpdated(schemaContext));
60 public synchronized CurrentAdapterSerializer currentSerializer() {
61 return verifyNotNull(serializer);