| 1 | /* |
| 2 | * Copyright 2006-2007 the original author or authors. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.springframework.batch.core.job; |
| 18 | |
| 19 | import java.util.ArrayList; |
| 20 | import java.util.List; |
| 21 | |
| 22 | import org.springframework.batch.core.Job; |
| 23 | import org.springframework.batch.core.Step; |
| 24 | import org.springframework.beans.factory.BeanNameAware; |
| 25 | import org.springframework.util.ClassUtils; |
| 26 | |
| 27 | /** |
| 28 | * Batch domain object representing a job. Job is an explicit abstraction |
| 29 | * representing the configuration of a job specified by a developer. It should |
| 30 | * be noted that restart policy is applied to the job as a whole and not to a |
| 31 | * step. |
| 32 | * |
| 33 | * @author Lucas Ward |
| 34 | * @author Dave Syer |
| 35 | */ |
| 36 | public abstract class AbstractJob implements BeanNameAware, Job { |
| 37 | |
| 38 | private List steps = new ArrayList(); |
| 39 | |
| 40 | private String name; |
| 41 | |
| 42 | private boolean restartable = false; |
| 43 | |
| 44 | /** |
| 45 | * Default constructor. |
| 46 | */ |
| 47 | public AbstractJob() { |
| 48 | super(); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Convenience constructor to immediately add name (which is mandatory but |
| 53 | * not final). |
| 54 | * |
| 55 | * @param name |
| 56 | */ |
| 57 | public AbstractJob(String name) { |
| 58 | super(); |
| 59 | this.name = name; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Set the name property if it is not already set. Because of the order of |
| 64 | * the callbacks in a Spring container the name property will be set first |
| 65 | * if it is present. Care is needed with bean definition inheritance - if a |
| 66 | * parent bean has a name, then its children need an explicit name as well, |
| 67 | * otherwise they will not be unique. |
| 68 | * |
| 69 | * @see org.springframework.beans.factory.BeanNameAware#setBeanName(java.lang.String) |
| 70 | */ |
| 71 | public void setBeanName(String name) { |
| 72 | if (this.name == null) { |
| 73 | this.name = name; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Set the name property. Always overrides the default value if this object |
| 79 | * is a Spring bean. |
| 80 | * |
| 81 | * @see #setBeanName(java.lang.String) |
| 82 | */ |
| 83 | public void setName(String name) { |
| 84 | this.name = name; |
| 85 | } |
| 86 | |
| 87 | /* (non-Javadoc) |
| 88 | * @see org.springframework.batch.core.domain.IJob#getName() |
| 89 | */ |
| 90 | public String getName() { |
| 91 | return name; |
| 92 | } |
| 93 | |
| 94 | /* (non-Javadoc) |
| 95 | * @see org.springframework.batch.core.domain.IJob#getSteps() |
| 96 | */ |
| 97 | public List getSteps() { |
| 98 | return steps; |
| 99 | } |
| 100 | |
| 101 | public void setSteps(List steps) { |
| 102 | this.steps.clear(); |
| 103 | this.steps.addAll(steps); |
| 104 | } |
| 105 | |
| 106 | public void addStep(Step step) { |
| 107 | this.steps.add(step); |
| 108 | } |
| 109 | |
| 110 | public void setRestartable(boolean restartable) { |
| 111 | this.restartable = restartable; |
| 112 | } |
| 113 | |
| 114 | /* (non-Javadoc) |
| 115 | * @see org.springframework.batch.core.domain.IJob#isRestartable() |
| 116 | */ |
| 117 | public boolean isRestartable() { |
| 118 | return restartable; |
| 119 | } |
| 120 | |
| 121 | public String toString() { |
| 122 | return ClassUtils.getShortName(getClass()) + ": [name=" + name + "]"; |
| 123 | } |
| 124 | } |