/* * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.controller.md.sal.binding.spi; import com.google.common.base.Optional; import com.google.common.cache.CacheLoader; import javax.annotation.Nonnull; import javax.annotation.Nullable; public abstract class AdapterLoader extends CacheLoader, Optional> { @Override public Optional load(final Class key) { final AdapterBuilder builder = createBuilder(key); for(final Class reqDeleg : builder.getRequiredDelegates()) { final D deleg = getDelegate(reqDeleg); if(deleg != null) { builder.addDelegate(reqDeleg,deleg); } else { return Optional.absent(); } } return Optional.of(builder.build()); } protected abstract @Nullable D getDelegate(Class reqDeleg); protected abstract @Nonnull AdapterBuilder createBuilder(Class key) throws IllegalArgumentException; }