Bug 2364: Migrated Binding MD-SAL to not use composites nodes
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / md / sal / binding / impl / BindingDOMAdapterLoader.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. 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.md.sal.binding.impl;
9
10 import com.google.common.base.Preconditions;
11 import com.google.common.collect.ImmutableMap;
12 import java.util.Map;
13 import org.opendaylight.controller.md.sal.binding.api.BindingService;
14 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
15 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
16 import org.opendaylight.controller.md.sal.binding.api.NotificationService;
17 import org.opendaylight.controller.md.sal.binding.impl.BindingDOMAdapterBuilder.Factory;
18 import org.opendaylight.controller.md.sal.binding.spi.AdapterBuilder;
19 import org.opendaylight.controller.md.sal.binding.spi.AdapterLoader;
20 import org.opendaylight.controller.md.sal.dom.api.DOMService;
21 import org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry;
22
23 public abstract class BindingDOMAdapterLoader extends AdapterLoader<BindingService, DOMService> {
24
25
26     private static final Map<Class<?>,BindingDOMAdapterBuilder.Factory<?>> FACTORIES = ImmutableMap.<Class<?>,BindingDOMAdapterBuilder.Factory<?>>builder()
27             .put(NotificationService.class,ForwardedNotificationService.BUILDER_FACTORY)
28             .put(NotificationPublishService.class,ForwardedNotificationPublishService.BUILDER_FACTORY)
29             .put(DataBroker.class,ForwardedBindingDataBroker.BUILDER_FACTORY)
30             .put(RpcConsumerRegistry.class,BindingDOMRpcServiceAdapter.BUILDER_FACTORY)
31             .build();
32
33     private final BindingToNormalizedNodeCodec codec;
34
35     public BindingDOMAdapterLoader(final BindingToNormalizedNodeCodec codec) {
36         super();
37         this.codec = codec;
38     }
39
40     @Override
41     protected final AdapterBuilder<? extends BindingService, DOMService> createBuilder(final Class<? extends BindingService> key)
42             throws IllegalArgumentException {
43         final Factory<?> factory = FACTORIES.get(key);
44         Preconditions.checkArgument(factory != null, "Unsupported service type %s", key);
45         final BindingDOMAdapterBuilder<?> builder = factory.newBuilder();
46         builder.setCodec(codec);
47         return builder;
48     }
49 }

©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.