001/* 002 * Copyright 2012-2013 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 */ 016package org.springframework.batch.core.configuration.annotation; 017 018import org.springframework.context.annotation.ImportSelector; 019import org.springframework.core.annotation.AnnotationAttributes; 020import org.springframework.core.type.AnnotationMetadata; 021import org.springframework.util.Assert; 022 023/** 024 * Base {@code Configuration} class providing common structure for enabling and using Spring Batch. Customization is 025 * available by implementing the {@link BatchConfigurer} interface. 026 * 027 * @author Dave Syer 028 * @since 2.2 029 * @see EnableBatchProcessing 030 */ 031public class BatchConfigurationSelector implements ImportSelector { 032 033 @Override 034 public String[] selectImports(AnnotationMetadata importingClassMetadata) { 035 Class<?> annotationType = EnableBatchProcessing.class; 036 AnnotationAttributes attributes = AnnotationAttributes.fromMap(importingClassMetadata.getAnnotationAttributes( 037 annotationType.getName(), false)); 038 Assert.notNull(attributes, String.format("@%s is not present on importing class '%s' as expected", 039 annotationType.getSimpleName(), importingClassMetadata.getClassName())); 040 041 String[] imports; 042 if (attributes.containsKey("modular") && attributes.getBoolean("modular")) { 043 imports = new String[] { ModularBatchConfiguration.class.getName() }; 044 } 045 else { 046 imports = new String[] { SimpleBatchConfiguration.class.getName() }; 047 } 048 049 return imports; 050 } 051 052}