EMMA Coverage Report (generated Fri Jan 30 13:20:29 EST 2009)
[all classes][org.springframework.batch.core.configuration.support]

COVERAGE SUMMARY FOR SOURCE FILE [ClassPathXmlApplicationContextJobFactory.java]

nameclass, %method, %block, %line, %
ClassPathXmlApplicationContextJobFactory.java100% (2/2)50%  (4/8)71%  (70/99)65%  (15/23)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ClassPathXmlApplicationContextJobFactory$ContextClosingJob100% (1/1)20%  (1/5)24%  (9/37)33%  (4/12)
execute (JobExecution): void 0%   (0/1)0%   (0/16)0%   (0/5)
getName (): String 0%   (0/1)0%   (0/4)0%   (0/1)
getSteps (): List 0%   (0/1)0%   (0/4)0%   (0/1)
isRestartable (): boolean 0%   (0/1)0%   (0/4)0%   (0/1)
ClassPathXmlApplicationContextJobFactory$ContextClosingJob (Job, Configurable... 100% (1/1)100% (9/9)100% (4/4)
     
class ClassPathXmlApplicationContextJobFactory100% (1/1)100% (3/3)98%  (61/62)100% (11/11)
createJob (): Job 100% (1/1)98%  (46/47)99%  (5/5)
ClassPathXmlApplicationContextJobFactory (String, String, ApplicationContext)... 100% (1/1)100% (12/12)100% (5/5)
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 java.util.List;
19 
20import org.springframework.batch.core.Job;
21import org.springframework.batch.core.JobExecution;
22import org.springframework.batch.core.JobExecutionException;
23import org.springframework.batch.core.configuration.JobFactory;
24import org.springframework.context.ApplicationContext;
25import org.springframework.context.ConfigurableApplicationContext;
26import org.springframework.context.support.ClassPathXmlApplicationContext;
27 
28/**
29 * A {@link JobFactory} that creates its own {@link ApplicationContext} from a
30 * path supplied, and pulls a bean out when asked to create a {@link Job}.
31 * 
32 * @author Dave Syer
33 * 
34 */
35public class ClassPathXmlApplicationContextJobFactory implements JobFactory {
36 
37        final private String beanName;
38 
39        final private String path;
40 
41        final private ApplicationContext parent;
42 
43        /**
44         * @param beanName the id of the {@link Job} in the application context to
45         * be created
46         * @param path the path to the XML configuration containing the {@link Job}
47         * @param parent the application context to use as a parent (or null)
48         */
49        public ClassPathXmlApplicationContextJobFactory(String beanName, String path, ApplicationContext parent) {
50                super();
51                this.beanName = beanName;
52                this.path = path;
53                this.parent = parent;
54        }
55 
56        /**
57         * Create a {@link ClassPathXmlApplicationContext} from the path provided
58         * and pull out a bean with the name given during initialization.
59         * 
60         * @see org.springframework.batch.core.configuration.JobFactory#createJob()
61         */
62        public Job createJob() {
63                ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] { path }, false, parent);
64                context.setDisplayName("Job ApplicationContext "+beanName);
65                context.refresh();
66                Job job = (Job) context.getBean(beanName, Job.class);
67                return new ContextClosingJob(job, context);
68        }
69 
70        /**
71         * Return the bean name of the job in the application context. N.B. this is
72         * usually the name of the job as well, but it needn't be. The important
73         * thing is that the job can be located by this name.
74         * 
75         * @see org.springframework.batch.core.configuration.JobFactory#getJobName()
76         */
77        public String getJobName() {
78                return beanName;
79        }
80 
81        /**
82         * @author Dave Syer
83         * 
84         */
85        private static class ContextClosingJob implements Job {
86                private Job delegate;
87 
88                private ConfigurableApplicationContext context;
89 
90                /**
91                 * @param delegate
92                 * @param context
93                 */
94                public ContextClosingJob(Job delegate, ConfigurableApplicationContext context) {
95                        super();
96                        this.delegate = delegate;
97                        this.context = context;
98                }
99 
100                /**
101                 * @param execution
102                 * @throws JobExecutionException
103                 * @see org.springframework.batch.core.Job#execute(org.springframework.batch.core.JobExecution)
104                 */
105                public void execute(JobExecution execution) throws JobExecutionException {
106                        try {
107                                delegate.execute(execution);
108                        }
109                        finally {
110                                context.close();
111                        }
112                }
113 
114                /**
115                 * @see org.springframework.batch.core.Job#getName()
116                 */
117                public String getName() {
118                        return delegate.getName();
119                }
120 
121                /**
122                 * @deprecated planned for removal in 2.0
123                 * @see org.springframework.batch.core.Job#getSteps()
124                 */
125                public List getSteps() {
126                        return delegate.getSteps();
127                }
128 
129                /**
130                 * @see org.springframework.batch.core.Job#isRestartable()
131                 */
132                public boolean isRestartable() {
133                        return delegate.isRestartable();
134                }
135 
136        }
137 
138}

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