001/*
002 * Copyright 2006-2007 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.batch.core.scope.context;
018
019import org.aspectj.lang.annotation.Around;
020import org.aspectj.lang.annotation.Aspect;
021import org.springframework.batch.core.JobInterruptedException;
022import org.springframework.batch.core.Step;
023import org.springframework.batch.core.StepExecution;
024
025/**
026 * Convenient aspect to wrap a single threaded step execution, where the
027 * implementation of the {@link Step} is not step scope aware (i.e. not the ones
028 * provided by the framework).
029 * 
030 * @author Dave Syer
031 * 
032 */
033@Aspect
034public class StepScopeManager {
035
036        @Around("execution(void org.springframework.batch.core.Step+.execute(*)) && target(step) && args(stepExecution)")
037        public void execute(Step step, StepExecution stepExecution) throws JobInterruptedException {
038                StepSynchronizationManager.register(stepExecution);
039                try {
040                        step.execute(stepExecution);
041                }
042                finally {
043                        StepSynchronizationManager.release();
044                }
045        }
046
047}