001/*
002 * Copyright 2006-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.support;
017
018import org.springframework.batch.core.Job;
019import org.springframework.batch.core.configuration.JobFactory;
020
021/**
022 * A {@link JobFactory} that just keeps a reference to a {@link Job}. It never
023 * modifies its {@link Job}.
024 *
025 * @author Dave Syer
026 *
027 */
028public class ReferenceJobFactory implements JobFactory {
029
030        private Job job;
031
032        /**
033         * @param job the {@link Job} to return from {@link #createJob()}.
034         */
035        public ReferenceJobFactory(Job job) {
036                this.job = job;
037        }
038
039        /**
040         * Just return the instance passed in on initialization.
041         *
042         * @see JobFactory#createJob()
043         */
044        @Override
045        public final Job createJob() {
046                return job;
047        }
048
049        /**
050         * Just return the name of instance passed in on initialization.
051         *
052         * @see JobFactory#getJobName()
053         */
054        @Override
055        public String getJobName() {
056                return job.getName();
057        }
058
059}