Proxy MD-SAL interfaces in DOMMountPointServiceImpl
[controller.git] / opendaylight / md-sal / sal-dom-compat / src / main / java / org / opendaylight / controller / sal / core / compat / DOMDataBrokerAdapter.java
1 /*
2  * Copyright (c) 2018 Pantheon Technologies, 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.controller.sal.core.compat;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.collect.ClassToInstanceMap;
13 import com.google.common.collect.ForwardingObject;
14 import com.google.common.collect.ImmutableClassToInstanceMap;
15 import com.google.common.collect.ImmutableClassToInstanceMap.Builder;
16 import java.util.Map;
17 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
18 import org.opendaylight.controller.md.sal.dom.api.DOMDataBrokerExtension;
19 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService;
20 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeCommitCohortRegistry;
21 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction;
22 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction;
23 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
24 import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
25 import org.opendaylight.mdsal.dom.api.DOMTransactionChainListener;
26
27 @Deprecated
28 public class DOMDataBrokerAdapter extends ForwardingObject implements org.opendaylight.mdsal.dom.api.DOMDataBroker {
29     private final ClassToInstanceMap<org.opendaylight.mdsal.dom.api.DOMDataBrokerExtension> extensions;
30     private final DOMDataBroker delegate;
31
32     public DOMDataBrokerAdapter(final DOMDataBroker delegate) {
33         this.delegate = requireNonNull(delegate);
34
35         Map<Class<? extends DOMDataBrokerExtension>, DOMDataBrokerExtension> delegateExtensions =
36                 delegate.getSupportedExtensions();
37         Builder<org.opendaylight.mdsal.dom.api.DOMDataBrokerExtension> extBuilder =
38                 ImmutableClassToInstanceMap.builder();
39
40         final DOMDataTreeChangeService delegateTreeChangeService = (DOMDataTreeChangeService) delegateExtensions.get(
41             DOMDataTreeChangeService.class);
42         if (delegateTreeChangeService != null) {
43             extBuilder.put(org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService.class,
44                 new DOMDataTreeChangeServiceAdapter(delegateTreeChangeService));
45         }
46
47         final DOMDataTreeCommitCohortRegistry delegateCohortRegistry =
48                 (DOMDataTreeCommitCohortRegistry) delegateExtensions.get(DOMDataTreeCommitCohortRegistry.class);
49         if (delegateCohortRegistry != null) {
50             extBuilder.put(DOMDataTreeCommitCohortRegistry.class, delegateCohortRegistry::registerCommitCohort);
51         }
52
53         extensions = extBuilder.build();
54     }
55
56     @Override
57     public DOMDataTreeReadTransaction newReadOnlyTransaction() {
58         return new DOMDataTreeReadTransactionAdapter(delegate.newReadOnlyTransaction());
59     }
60
61     @Override
62     public DOMDataTreeWriteTransaction newWriteOnlyTransaction() {
63         return new DOMDataTreeWriteTransactionAdapter(delegate.newWriteOnlyTransaction());
64     }
65
66     @Override
67     public DOMDataTreeReadWriteTransaction newReadWriteTransaction() {
68         return new DOMDataTreeReadWriteTransactionAdapter(delegate.newReadWriteTransaction());
69     }
70
71     @Override
72     public ClassToInstanceMap<org.opendaylight.mdsal.dom.api.DOMDataBrokerExtension> getExtensions() {
73         return extensions;
74     }
75
76     @Override
77     public DOMTransactionChain createTransactionChain(final DOMTransactionChainListener listener) {
78         return new DOMTransactionChainAdapter(listener, delegate::createTransactionChain);
79     }
80
81     @Override
82     protected DOMDataBroker delegate() {
83         return delegate;
84     }
85 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.