BindingAdapterFactory should be Immutable
[mdsal.git] / binding / mdsal-binding-dom-adapter / src / main / java / org / opendaylight / mdsal / binding / dom / adapter / BindingAdapterFactory.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.mdsal.binding.dom.adapter;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.annotations.Beta;
13 import org.eclipse.jdt.annotation.NonNullByDefault;
14 import org.opendaylight.mdsal.binding.api.ActionProviderService;
15 import org.opendaylight.mdsal.binding.api.ActionService;
16 import org.opendaylight.mdsal.binding.api.DataBroker;
17 import org.opendaylight.mdsal.binding.api.DataTreeService;
18 import org.opendaylight.mdsal.binding.api.MountPointService;
19 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
20 import org.opendaylight.mdsal.binding.api.NotificationService;
21 import org.opendaylight.mdsal.binding.api.RpcConsumerRegistry;
22 import org.opendaylight.mdsal.binding.api.RpcProviderService;
23 import org.opendaylight.mdsal.binding.dom.adapter.spi.AdapterFactory;
24 import org.opendaylight.mdsal.dom.api.DOMActionProviderService;
25 import org.opendaylight.mdsal.dom.api.DOMActionService;
26 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
27 import org.opendaylight.mdsal.dom.api.DOMDataTreeService;
28 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
29 import org.opendaylight.mdsal.dom.api.DOMNotificationPublishService;
30 import org.opendaylight.mdsal.dom.api.DOMNotificationService;
31 import org.opendaylight.mdsal.dom.api.DOMRpcProviderService;
32 import org.opendaylight.mdsal.dom.api.DOMRpcService;
33 import org.opendaylight.yangtools.concepts.Immutable;
34
35 /**
36  * Implementation of AdapterFactory.
37  *
38  * @author Robert Varga
39  */
40 @Beta
41 @NonNullByDefault
42 public final class BindingAdapterFactory implements AdapterFactory, Immutable {
43     private final BindingToNormalizedNodeCodec codec;
44
45     public BindingAdapterFactory(final BindingToNormalizedNodeCodec codec) {
46         this.codec = requireNonNull(codec);
47     }
48
49     /**
50      * Create a {@link DataBroker} backed by a {@link DOMDataBroker}.
51      *
52      * @param domService Backing DOMDataBroker
53      * @return A DataBroker
54      * @throws NullPointerException if {@code domService} is null
55      */
56     @Override
57     public DataBroker createDataBroker(final DOMDataBroker domService) {
58         return new BindingDOMDataBrokerAdapter(domService, codec);
59     }
60
61     /**
62      * Create a {@link DataTreeService} backed by a {@link DOMDataTreeService}.
63      *
64      * @param domService Backing DOMDataTreeService
65      * @return A DataTreeService
66      * @throws NullPointerException if {@code domService} is null
67      */
68     @Override
69     public DataTreeService createDataTreeService(final DOMDataTreeService domService) {
70         return BindingDOMDataTreeServiceAdapter.create(domService, codec);
71     }
72
73     /**
74      * Create a {@link MountPointService} backed by a {@link DOMMountPointService}.
75      *
76      * @param domService Backing DOMMountPointService
77      * @return A MountPointService
78      * @throws NullPointerException if {@code domService} is null
79      */
80     @Override
81     public MountPointService createMountPointService(final DOMMountPointService domService) {
82         return new BindingDOMMountPointServiceAdapter(domService, codec);
83     }
84
85     /**
86      * Create a {@link DataBroker} backed by a {@link DOMDataBroker}.
87      *
88      * @param domService Backing DOMDataBroker
89      * @return A DataBroker
90      * @throws NullPointerException if {@code domService} is null
91      */
92     @Override
93     public NotificationService createNotificationService(final DOMNotificationService domService) {
94         return new BindingDOMNotificationServiceAdapter(domService, codec);
95     }
96
97     /**
98      * Create a {@link NotificationPublishService} backed by a {@link DOMNotificationPublishService}.
99      *
100      * @param domService Backing DOMNotificationPublishService
101      * @return A NotificationPublishService
102      * @throws NullPointerException if {@code domService} is null
103      */
104     @Override
105     public NotificationPublishService createNotificationPublishService(final DOMNotificationPublishService domService) {
106         return new BindingDOMNotificationPublishServiceAdapter(domService, codec);
107     }
108
109     /**
110      * Create a {@link RpcConsumerRegistry} backed by a {@link DOMRpcService}.
111      *
112      * @param domService Backing DOMRpcService
113      * @return A RpcConsumerRegistry
114      * @throws NullPointerException if {@code domService} is null
115      */
116     @Override
117     public RpcConsumerRegistry createRpcConsumerRegistry(final DOMRpcService domService) {
118         return new BindingDOMRpcServiceAdapter(domService, codec);
119     }
120
121     /**
122      * Create a {@link RpcProviderService} backed by a {@link DOMRpcProviderService}.
123      *
124      * @param domService Backing DOMRpcProviderService
125      * @return A RpcProviderService
126      * @throws NullPointerException if {@code domService} is null
127      */
128     @Override
129     public RpcProviderService createRpcProviderService(final DOMRpcProviderService domService) {
130         return new BindingDOMRpcProviderServiceAdapter(domService, codec);
131     }
132
133     @Override
134     public ActionService createActionService(final DOMActionService domService) {
135         return new ActionServiceAdapter(codec, domService);
136     }
137
138     @Override
139     public ActionProviderService createActionProviderService(final DOMActionProviderService domService) {
140         return new ActionProviderServiceAdapter(codec, domService);
141     }
142 }