1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.springframework.batch.core.configuration.xml;
17
18 import org.springframework.batch.core.JobExecutionListener;
19 import org.springframework.batch.core.JobParametersIncrementer;
20 import org.springframework.batch.core.JobParametersValidator;
21 import org.springframework.batch.core.job.flow.Flow;
22 import org.springframework.batch.core.job.flow.FlowJob;
23 import org.springframework.batch.core.repository.JobRepository;
24 import org.springframework.beans.factory.FactoryBean;
25 import org.springframework.beans.factory.SmartFactoryBean;
26 import org.springframework.util.Assert;
27 import org.springframework.util.StringUtils;
28
29
30
31
32
33
34
35
36
37
38 class JobParserJobFactoryBean implements SmartFactoryBean {
39
40 private String name;
41
42 private Boolean restartable;
43
44 private JobRepository jobRepository;
45
46 private JobParametersValidator jobParametersValidator;
47
48 private JobExecutionListener[] jobExecutionListeners;
49
50 private JobParametersIncrementer jobParametersIncrementer;
51
52 private Flow flow;
53
54 public JobParserJobFactoryBean(String name) {
55 this.name = name;
56 }
57
58 @Override
59 public final Object getObject() throws Exception {
60 Assert.isTrue(StringUtils.hasText(name), "The job must have an id.");
61 FlowJob flowJob = new FlowJob(name);
62
63 if (restartable != null) {
64 flowJob.setRestartable(restartable);
65 }
66
67 if (jobRepository != null) {
68 flowJob.setJobRepository(jobRepository);
69 }
70
71 if (jobParametersValidator != null) {
72 flowJob.setJobParametersValidator(jobParametersValidator);
73 }
74
75 if (jobExecutionListeners != null) {
76 flowJob.setJobExecutionListeners(jobExecutionListeners);
77 }
78
79 if (jobParametersIncrementer != null) {
80 flowJob.setJobParametersIncrementer(jobParametersIncrementer);
81 }
82
83 if (flow != null) {
84 flowJob.setFlow(flow);
85 }
86
87 flowJob.afterPropertiesSet();
88 return flowJob;
89 }
90
91 public void setRestartable(Boolean restartable) {
92 this.restartable = restartable;
93 }
94
95 public void setJobRepository(JobRepository jobRepository) {
96 this.jobRepository = jobRepository;
97 }
98
99 public void setJobParametersValidator(JobParametersValidator jobParametersValidator) {
100 this.jobParametersValidator = jobParametersValidator;
101 }
102
103 public JobRepository getJobRepository() {
104 return this.jobRepository;
105 }
106
107 public void setJobExecutionListeners(JobExecutionListener[] jobExecutionListeners) {
108 this.jobExecutionListeners = jobExecutionListeners;
109 }
110
111 public void setJobParametersIncrementer(JobParametersIncrementer jobParametersIncrementer) {
112 this.jobParametersIncrementer = jobParametersIncrementer;
113 }
114
115 public void setFlow(Flow flow) {
116 this.flow = flow;
117 }
118
119 @Override
120 public Class<FlowJob> getObjectType() {
121 return FlowJob.class;
122 }
123
124 @Override
125 public boolean isSingleton() {
126 return true;
127 }
128
129 @Override
130 public boolean isEagerInit() {
131 return true;
132 }
133
134 @Override
135 public boolean isPrototype() {
136 return false;
137 }
138
139 }