EMMA Coverage Report (generated Fri Aug 21 15:59:46 BST 2009)
[all classes][org.springframework.batch.core.configuration.support]

COVERAGE SUMMARY FOR SOURCE FILE [ApplicationContextJobFactory.java]

nameclass, %method, %block, %line, %
ApplicationContextJobFactory.java100% (2/2)62%  (5/8)65%  (42/65)65%  (13/20)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ApplicationContextJobFactory$ContextClosingJob100% (1/1)40%  (2/5)36%  (13/36)42%  (5/12)
execute (JobExecution): void 0%   (0/1)0%   (0/15)0%   (0/5)
getJobParametersIncrementer (): JobParametersIncrementer 0%   (0/1)0%   (0/4)0%   (0/1)
isRestartable (): boolean 0%   (0/1)0%   (0/4)0%   (0/1)
ApplicationContextJobFactory$ContextClosingJob (Job, ConfigurableApplicationC... 100% (1/1)100% (9/9)100% (4/4)
getName (): String 100% (1/1)100% (4/4)100% (1/1)
     
class ApplicationContextJobFactory100% (1/1)100% (3/3)100% (29/29)100% (8/8)
ApplicationContextJobFactory (ApplicationContextFactory, String): void 100% (1/1)100% (9/9)100% (4/4)
createJob (): Job 100% (1/1)100% (17/17)100% (3/3)
getJobName (): String 100% (1/1)100% (3/3)100% (1/1)

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.configuration.support;
17 
18import org.springframework.batch.core.Job;
19import org.springframework.batch.core.JobExecution;
20import org.springframework.batch.core.JobParametersIncrementer;
21import org.springframework.batch.core.configuration.JobFactory;
22import org.springframework.context.ApplicationContext;
23import org.springframework.context.ConfigurableApplicationContext;
24 
25/**
26 * A {@link JobFactory} that creates its own {@link ApplicationContext} from a
27 * path supplied, and pulls a bean out when asked to create a {@link Job}.
28 * 
29 * @author Dave Syer
30 * 
31 */
32public class ApplicationContextJobFactory implements JobFactory {
33 
34        final private String jobName;
35 
36        final private ApplicationContextFactory applicationContextFactory;
37 
38        /**
39         * @param jobName the id of the {@link Job} in the application context to be
40         * created
41         */
42        public ApplicationContextJobFactory(ApplicationContextFactory applicationContextFactory, String jobName) {
43                super();
44                this.jobName = jobName;
45                this.applicationContextFactory = applicationContextFactory;
46        }
47 
48        /**
49         * Create an {@link ApplicationContext} from the factory provided and pull
50         * out a bean with the name given during initialization.
51         * 
52         * @see org.springframework.batch.core.configuration.JobFactory#createJob()
53         */
54        public Job createJob() {
55                ConfigurableApplicationContext context = applicationContextFactory.createApplicationContext();
56                Job job = (Job) context.getBean(jobName, Job.class);
57                return new ContextClosingJob(job, context);
58        }
59 
60        /**
61         * Return the bean name of the job in the application context. N.B. this is
62         * usually the name of the job as well, but it needn't be. The important
63         * thing is that the job can be located by this name.
64         * 
65         * @see org.springframework.batch.core.configuration.JobFactory#getJobName()
66         */
67        public String getJobName() {
68                return jobName;
69        }
70 
71        /**
72         * @author Dave Syer
73         * 
74         */
75        private static class ContextClosingJob implements Job {
76                private Job delegate;
77 
78                private ConfigurableApplicationContext context;
79 
80                /**
81                 * @param delegate
82                 * @param context
83                 */
84                public ContextClosingJob(Job delegate, ConfigurableApplicationContext context) {
85                        super();
86                        this.delegate = delegate;
87                        this.context = context;
88                }
89 
90                /**
91                 * @param execution
92                 * @see org.springframework.batch.core.Job#execute(org.springframework.batch.core.JobExecution)
93                 */
94                public void execute(JobExecution execution) {
95                        try {
96                                delegate.execute(execution);
97                        }
98                        finally {
99                                context.close();
100                        }
101                }
102 
103                /**
104                 * @see org.springframework.batch.core.Job#getName()
105                 */
106                public String getName() {
107                        return delegate.getName();
108                }
109 
110                /**
111                 * @see org.springframework.batch.core.Job#isRestartable()
112                 */
113                public boolean isRestartable() {
114                        return delegate.isRestartable();
115                }
116 
117                /**
118                 * @see org.springframework.batch.core.Job#getJobParametersIncrementer()
119                 */
120                public JobParametersIncrementer getJobParametersIncrementer() {
121                        return delegate.getJobParametersIncrementer();
122                }
123 
124        }
125 
126}

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