EMMA Coverage Report (generated Tue May 06 07:29:23 PDT 2008)
[all classes][org.springframework.batch.core.launch.support]

COVERAGE SUMMARY FOR SOURCE FILE [SimpleExportedJobLauncher.java]

nameclass, %method, %block, %line, %
SimpleExportedJobLauncher.java100% (1/1)91%  (10/11)96%  (244/254)93%  (55/59)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SimpleExportedJobLauncher100% (1/1)91%  (10/11)96%  (244/254)93%  (55/59)
afterPropertiesSet (): void 0%   (0/1)0%   (0/9)0%   (0/3)
isRunning (): boolean 100% (1/1)96%  (25/26)86%  (6/7)
SimpleExportedJobLauncher (): void 100% (1/1)100% (13/13)100% (3/3)
addStatistics (Properties, JobExecution, String): void 100% (1/1)100% (51/51)100% (10/10)
getStatistics (): Properties 100% (1/1)100% (42/42)100% (9/9)
run (String): String 100% (1/1)100% (5/5)100% (1/1)
run (String, String): String 100% (1/1)100% (71/71)100% (13/13)
setJobLocator (JobLocator): void 100% (1/1)100% (4/4)100% (2/2)
setJobParametersFactory (JobParametersConverter): void 100% (1/1)100% (4/4)100% (2/2)
setLauncher (JobLauncher): void 100% (1/1)100% (4/4)100% (2/2)
stop (): void 100% (1/1)100% (25/25)100% (7/7)

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 */
16package org.springframework.batch.core.launch.support;
17 
18import java.util.HashMap;
19import java.util.Iterator;
20import java.util.Map;
21import java.util.Properties;
22 
23import org.springframework.batch.core.Job;
24import org.springframework.batch.core.JobExecution;
25import org.springframework.batch.core.JobExecutionException;
26import org.springframework.batch.core.JobParameters;
27import org.springframework.batch.core.StepExecution;
28import org.springframework.batch.core.configuration.JobLocator;
29import org.springframework.batch.core.converter.DefaultJobParametersConverter;
30import org.springframework.batch.core.converter.JobParametersConverter;
31import org.springframework.batch.core.launch.JobLauncher;
32import org.springframework.batch.core.repository.NoSuchJobException;
33import org.springframework.batch.support.PropertiesConverter;
34import org.springframework.beans.factory.InitializingBean;
35import org.springframework.util.Assert;
36 
37/**
38 * @author Dave Syer
39 * 
40 */
41public class SimpleExportedJobLauncher implements ExportedJobLauncher, InitializingBean {
42 
43        private JobLauncher launcher;
44 
45        private JobLocator jobLocator;
46 
47        private Map registry = new HashMap();
48 
49        private JobParametersConverter jobParametersConverter = new DefaultJobParametersConverter();
50        
51        /* (non-Javadoc)
52         * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
53         */
54        public void afterPropertiesSet() throws Exception {
55                Assert.notNull(launcher, "JobLauncher must be provided.");
56                Assert.notNull(jobLocator, "JobLocator must be provided.");
57        }
58 
59        /**
60         * Public setter for the {@link JobLauncher}.
61         * @param launcher the launcher to set
62         */
63        public void setLauncher(JobLauncher launcher) {
64                this.launcher = launcher;
65        }
66        
67        /**
68         * Public setter for the JobLocator.
69         * @param jobLocator the jobLocator to set
70         */
71        public void setJobLocator(JobLocator jobLocator) {
72                this.jobLocator = jobLocator;
73        }
74        
75        /**
76         * Public setter for the JobParametersFactory.
77         * @param jobParametersConverter the jobParametersFactory to set
78         */
79        public void setJobParametersFactory(JobParametersConverter jobParametersConverter) {
80                this.jobParametersConverter = jobParametersConverter;
81        }
82 
83        /*
84         * (non-Javadoc)
85         * @see org.springframework.batch.execution.bootstrap.support.ExportedJobLauncher#getStatistics()
86         */
87        public Properties getStatistics() {
88                Properties result = new Properties();
89                int i = 0;
90                for (Iterator iterator = registry.keySet().iterator(); iterator.hasNext();) {
91                        String key = (String) iterator.next();
92                        JobExecution execution = (JobExecution) registry.get(key);
93                        addStatistics(result, execution, "job" + i + ".");
94                        i++;
95                }
96                return result;
97        }
98 
99        /**
100         * @param result
101         * @param execution
102         */
103        private void addStatistics(Properties result, JobExecution execution, String prefix) {
104                int i = 0;
105                for (Iterator iterator = execution.getStepExecutions().iterator(); iterator.hasNext();) {
106                        StepExecution stepExecution = (StepExecution) iterator.next();
107                        Properties statistics = stepExecution.getExecutionContext().getProperties();
108                        for (Iterator iter = statistics.keySet().iterator(); iter.hasNext();) {
109                                String key = (String) iter.next();
110                                result.setProperty(prefix + "step" + i + "." + key, statistics.getProperty(key));
111                        }
112                }
113        }
114 
115        /*
116         * (non-Javadoc)
117         * @see org.springframework.batch.execution.bootstrap.support.ExportedJobLauncher#isRunning()
118         */
119        public boolean isRunning() {
120                for (Iterator iterator = registry.keySet().iterator(); iterator.hasNext();) {
121                        String key = (String) iterator.next();
122                        JobExecution execution = (JobExecution) registry.get(key);
123                        if (execution.isRunning()) {
124                                return true;
125                        }
126                }
127                return false;
128        }
129 
130        /*
131         * (non-Javadoc)
132         * @see org.springframework.batch.execution.bootstrap.support.ExportedJobLauncher#run(java.lang.String)
133         */
134        public String run(String name) {
135                return run(name, null);
136        }
137 
138        /*
139         * (non-Javadoc)
140         * @see org.springframework.batch.execution.bootstrap.support.ExportedJobLauncher#run(java.lang.String,
141         * java.lang.String)
142         */
143        public String run(String name, String params) {
144 
145                Job job;
146                try {
147                        job = jobLocator.getJob(name);
148                }
149                catch (NoSuchJobException e) {
150                        return e.getClass().getName() + ": " + e.getMessage();
151                }
152 
153                JobParameters jobParameters = new JobParameters();
154                if (params != null) {
155                        jobParameters = jobParametersConverter.getJobParameters(PropertiesConverter.stringToProperties(params));
156                }
157 
158                JobExecution execution;
159                try {
160                        execution = launcher.run(job, jobParameters);
161                }
162                catch (JobExecutionException e) {
163                        return e.getClass().getName() + ": " + e.getMessage();
164                }
165                registry.put(name + params, execution);
166 
167                return execution.toString();
168 
169        }
170 
171        /*
172         * (non-Javadoc)
173         * @see org.springframework.batch.execution.bootstrap.support.ExportedJobLauncher#stop()
174         */
175        public void stop() {
176                for (Iterator iterator = registry.keySet().iterator(); iterator.hasNext();) {
177                        String key = (String) iterator.next();
178                        JobExecution execution = (JobExecution) registry.get(key);
179                        execution.stop();
180                }
181                registry.clear();
182        }
183 
184}

[all classes][org.springframework.batch.core.launch.support]
EMMA 2.0.5312 (C) Vladimir Roubtsov