6eab3499fede5a77a3b4737eb2cd3f92e3e02c34
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / md / sal / binding / spi / AdapterLoader.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.spi;
9
10 import com.google.common.base.Optional;
11 import com.google.common.cache.CacheLoader;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.eclipse.jdt.annotation.Nullable;
14 import org.gaul.modernizer_maven_annotations.SuppressModernizer;
15
16 @Deprecated
17 public abstract class AdapterLoader<T, D> extends CacheLoader<Class<? extends T>, Optional<T>> {
18
19     @Override
20     @SuppressModernizer
21     public Optional<T> load(final Class<? extends T> key) {
22
23         final AdapterBuilder<? extends T, D> builder = createBuilder(key);
24         for (final Class<? extends D> reqDeleg : builder.getRequiredDelegates()) {
25             final D deleg = getDelegate(reqDeleg);
26             if (deleg != null) {
27                 builder.addDelegate(reqDeleg, deleg);
28             } else {
29                 return Optional.absent();
30             }
31         }
32         return  Optional.<T>of(builder.build());
33     }
34
35     protected abstract @Nullable D getDelegate(Class<? extends D> reqDeleg);
36
37     protected abstract @NonNull AdapterBuilder<? extends T, D> createBuilder(Class<? extends T> key);
38 }

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