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 java.util.Arrays;
020
021import org.springframework.core.AttributeAccessorSupport;
022
023/**
024 * Context object for weakly typed data stored for the duration of a chunk
025 * (usually a group of items processed together in a transaction). If there is a
026 * rollback and the chunk is retried the same context will be associated with
027 * it.
028 * 
029 * @author Dave Syer
030 * 
031 */
032@SuppressWarnings("serial")
033public class ChunkContext extends AttributeAccessorSupport {
034
035        private final StepContext stepContext;
036
037        private boolean complete = false;
038
039        /**
040         * @param stepContext the current step context
041         */
042        public ChunkContext(StepContext stepContext) {
043                this.stepContext = stepContext;
044        }
045
046        /**
047         * @return the current step context
048         */
049        public StepContext getStepContext() {
050                return stepContext;
051        }
052
053        /**
054         * @return true if there is no more processing to be done on this chunk
055         */
056        public boolean isComplete() {
057                return complete;
058        }
059
060        /**
061         * Setter for the flag to signal complete processing of a chunk.
062         */
063        public void setComplete() {
064                this.complete = true;
065        }
066
067        /*
068         * (non-Javadoc)
069         * 
070         * @see java.lang.Object#toString()
071         */
072        @Override
073        public String toString() {
074                return String.format("ChunkContext: attributes=%s, complete=%b, stepContext=%s", Arrays
075                                .asList(attributeNames()), complete, stepContext);
076        }
077
078}