2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.md.sal.binding.spi;
10 import com.google.common.base.Optional;
11 import com.google.common.cache.CacheLoader;
12 import javax.annotation.Nonnull;
13 import javax.annotation.Nullable;
15 public abstract class AdapterLoader<T, D> extends CacheLoader<Class<? extends T>, Optional<T>> {
18 public Optional<T> load(final Class<? extends T> key) {
20 final AdapterBuilder<? extends T, D> builder = createBuilder(key);
21 for(final Class<? extends D> reqDeleg : builder.getRequiredDelegates()) {
22 final D deleg = getDelegate(reqDeleg);
24 builder.addDelegate(reqDeleg,deleg);
26 return Optional.absent();
29 return Optional.<T>of(builder.build());
32 protected abstract @Nullable D getDelegate(Class<? extends D> reqDeleg);
34 protected abstract @Nonnull AdapterBuilder<? extends T, D> createBuilder(Class<? extends T> key) throws IllegalArgumentException;