360c94d539832dedf212e916c55e8a3b484b57f8
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / md / sal / binding / impl / BindingMountPointAdapter.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.Optional;
11 import com.google.common.cache.CacheBuilder;
12 import com.google.common.cache.LoadingCache;
13 import org.opendaylight.controller.md.sal.binding.api.BindingService;
14 import org.opendaylight.controller.md.sal.binding.api.MountPoint;
15 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
16 import org.opendaylight.controller.md.sal.dom.api.DOMService;
17 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
18
19 @Deprecated
20 public class BindingMountPointAdapter implements MountPoint {
21
22     private final InstanceIdentifier<?> identifier;
23     private LoadingCache<Class<? extends BindingService>, Optional<BindingService>> services;
24
25     public BindingMountPointAdapter(final BindingToNormalizedNodeCodec codec, final DOMMountPoint domMountPoint) {
26         identifier = codec.getCodecRegistry().fromYangInstanceIdentifier(domMountPoint.getIdentifier());
27         services = CacheBuilder.newBuilder().build(new BindingDOMAdapterLoader(codec) {
28
29             @Override
30             protected DOMService getDelegate(Class<? extends DOMService> reqDeleg) {
31                 return domMountPoint.getService(reqDeleg).orNull();
32             }
33         });
34     }
35
36     @Override
37     public InstanceIdentifier<?> getIdentifier() {
38         return identifier;
39     }
40
41     @Override
42     public <T extends BindingService> Optional<T> getService(Class<T> service) {
43         Optional<BindingService> potential = services.getUnchecked(service);
44         if (potential.isPresent()) {
45             return Optional.of(service.cast(potential.get()));
46         }
47         return Optional.absent();
48     }
49
50 }