EMMA Coverage Report (generated Fri Jan 30 13:20:29 EST 2009)
[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%  (250/260)93%  (55/59)

COVERAGE BREAKDOWN BY CLASS AND METHOD

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

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