All Downloads are FREE. Search and download functionalities are using the official Maven repository.

infra.beans.factory.support.DependencyResolvingStrategies Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2017 - 2024 the original author or authors.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see [https://www.gnu.org/licenses/]
 */

package infra.beans.factory.support;

import java.util.List;

import infra.beans.factory.config.DependencyDescriptor;
import infra.lang.Nullable;
import infra.lang.TodayStrategies;
import infra.logging.LoggerFactory;
import infra.util.ArrayHolder;

/**
 * Composite DependencyResolvingStrategy
 *
 * @author Harry Yang
 * @since 4.0 2021/11/16 22:50
 */
public class DependencyResolvingStrategies implements DependencyResolvingStrategy {

  private final ArrayHolder strategies
          = ArrayHolder.forClass(DependencyResolvingStrategy.class);

  public DependencyResolvingStrategies() { }

  public DependencyResolvingStrategies(List strategyList) {
    getStrategies().addAll(strategyList);
  }

  @Override
  public Object resolveDependency(DependencyDescriptor descriptor, Context context) {
    for (DependencyResolvingStrategy resolvingStrategy : strategies) {
      Object dependency = resolvingStrategy.resolveDependency(descriptor, context);
      if (dependency != null) {
        return dependency;
      }
    }
    return null;
  }

  public void initStrategies(@Nullable ClassLoader classLoader) {
    LoggerFactory.getLogger(DependencyResolvingStrategies.class)
            .debug("Initialize dependency-resolving-strategies");
    this.strategies.addAll(TodayStrategies.find(DependencyResolvingStrategy.class, classLoader));
  }

  public ArrayHolder getStrategies() {
    return strategies;
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy