001/* 002 * Copyright 2002-2008 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.beans.factory.serviceloader; 018 019import java.util.LinkedList; 020import java.util.List; 021import java.util.ServiceLoader; 022 023import org.springframework.beans.factory.BeanClassLoaderAware; 024 025/** 026 * {@link org.springframework.beans.factory.FactoryBean} that exposes <i>all</i> 027 * services for the configured service class, represented as a List of service objects, 028 * obtained through the JDK 1.6 {@link java.util.ServiceLoader} facility. 029 * 030 * @author Juergen Hoeller 031 * @since 2.5 032 * @see java.util.ServiceLoader 033 */ 034public class ServiceListFactoryBean extends AbstractServiceLoaderBasedFactoryBean implements BeanClassLoaderAware { 035 036 @Override 037 protected Object getObjectToExpose(ServiceLoader<?> serviceLoader) { 038 List<Object> result = new LinkedList<Object>(); 039 for (Object loaderObject : serviceLoader) { 040 result.add(loaderObject); 041 } 042 return result; 043 } 044 045 @Override 046 public Class<?> getObjectType() { 047 return List.class; 048 } 049 050}