*/
package org.opendaylight.mdsal.binding.dom.adapter.test.util;
+import static com.google.common.base.Verify.verifyNotNull;
+
import com.google.common.collect.ClassToInstanceMap;
import com.google.common.collect.ImmutableClassToInstanceMap;
+import org.opendaylight.mdsal.binding.dom.adapter.AdapterContext;
+import org.opendaylight.mdsal.binding.dom.adapter.CurrentAdapterSerializer;
+import org.opendaylight.mdsal.binding.dom.codec.impl.BindingCodecContext;
+import org.opendaylight.mdsal.binding.runtime.api.BindingRuntimeContext;
import org.opendaylight.mdsal.dom.api.DOMSchemaService;
import org.opendaylight.mdsal.dom.api.DOMSchemaServiceExtension;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.util.ListenerRegistry;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
-import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider;
-
-public final class MockSchemaService implements DOMSchemaService, SchemaContextProvider {
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextListener;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextProvider;
- private SchemaContext schemaContext;
+public final class MockSchemaService implements DOMSchemaService, EffectiveModelContextProvider, AdapterContext {
+ private EffectiveModelContext schemaContext;
+ private CurrentAdapterSerializer serializer;
- final ListenerRegistry<SchemaContextListener> listeners = ListenerRegistry.create();
+ final ListenerRegistry<EffectiveModelContextListener> listeners = ListenerRegistry.create();
@Override
- public synchronized SchemaContext getGlobalContext() {
+ public synchronized EffectiveModelContext getGlobalContext() {
return schemaContext;
}
@Override
- public synchronized SchemaContext getSessionContext() {
- return schemaContext;
- }
-
- @Override
- public ListenerRegistration<SchemaContextListener> registerSchemaContextListener(
- final SchemaContextListener listener) {
+ public ListenerRegistration<EffectiveModelContextListener> registerSchemaContextListener(
+ final EffectiveModelContextListener listener) {
return listeners.register(listener);
}
@Override
- public synchronized SchemaContext getSchemaContext() {
+ public synchronized EffectiveModelContext getEffectiveModelContext() {
return schemaContext;
}
return ImmutableClassToInstanceMap.of();
}
- public synchronized void changeSchema(final SchemaContext newContext) {
- schemaContext = newContext;
- for (ListenerRegistration<SchemaContextListener> listener : listeners) {
- listener.getInstance().onGlobalContextUpdated(schemaContext);
- }
+ public synchronized void changeSchema(final BindingRuntimeContext newContext) {
+ serializer = new CurrentAdapterSerializer(new BindingCodecContext(newContext));
+ schemaContext = newContext.getEffectiveModelContext();
+ listeners.streamListeners().forEach(listener -> listener.onModelContextUpdated(schemaContext));
+ }
+
+ @Override
+ public synchronized CurrentAdapterSerializer currentSerializer() {
+ return verifyNotNull(serializer);
}
}