c790345e2a9dc00c4f90496baf26392fb8adbe4f
[mdsal.git] / dom / mdsal-dom-schema-osgi / src / main / java / org / opendaylight / mdsal / dom / schema / osgi / impl / EffectiveModelContextImpl.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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.mdsal.dom.schema.osgi.impl;
9
10 import static com.google.common.base.Verify.verifyNotNull;
11
12 import com.google.common.annotations.VisibleForTesting;
13 import java.util.Dictionary;
14 import java.util.Map;
15 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
16 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextListener;
17 import org.osgi.framework.FrameworkUtil;
18 import org.osgi.service.component.annotations.Activate;
19 import org.osgi.service.component.annotations.Component;
20 import org.osgi.service.component.annotations.Deactivate;
21
22 /**
23  * A Factory Component which implements {@link EffectiveModelContextListener}. Instances of this component are created
24  * through by {@link OSGiDOMSchemaService} each time a listener is registered.
25  */
26 @Component(factory = EffectiveModelContextImpl.FACTORY_NAME, service = EffectiveModelContextListener.class)
27 public final class EffectiveModelContextImpl implements EffectiveModelContextListener {
28     static final String FACTORY_NAME = "org.opendaylight.mdsal.dom.schema.osgi.impl.SchemaSchemaContextListener";
29
30     @VisibleForTesting
31     static final String DELEGATE = "org.opendaylight.mdsal.dom.schema.osgi.SchemaSchemaContextListener";
32
33     private EffectiveModelContextListener delegate = null;
34
35     @Override
36     public void onModelContextUpdated(final EffectiveModelContext newModelContext) {
37         delegate.onModelContextUpdated(newModelContext);
38     }
39
40     @Activate
41     void activate(final Map<String, ?> properties) {
42         delegate = (EffectiveModelContextListener) verifyNotNull(properties.get(DELEGATE));
43     }
44
45     @Deactivate
46     void deactivate() {
47         delegate = null;
48     }
49
50     static Dictionary<String, ?> props(final EffectiveModelContextListener delegate) {
51         return FrameworkUtil.asDictionary(Map.of(DELEGATE, delegate));
52     }
53 }