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 [ClassPathXmlApplicationContextFactory.java]

nameclass, %method, %block, %line, %
ClassPathXmlApplicationContextFactory.java100% (2/2)100% (8/8)95%  (52/55)93%  (14/15)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ClassPathXmlApplicationContextFactory100% (1/1)100% (5/5)91%  (29/32)90%  (9/10)
createApplicationContext (): ConfigurableApplicationContext 100% (1/1)79%  (11/14)67%  (2/3)
ClassPathXmlApplicationContextFactory (): void 100% (1/1)100% (3/3)100% (1/1)
access$0 (ClassPathXmlApplicationContextFactory): Resource 100% (1/1)100% (3/3)100% (1/1)
setApplicationContext (ApplicationContext): void 100% (1/1)100% (8/8)100% (3/3)
setPath (Resource): void 100% (1/1)100% (4/4)100% (2/2)
     
class ClassPathXmlApplicationContextFactory$ResourceXmlApplicationContext100% (1/1)100% (3/3)100% (23/23)100% (5/5)
ClassPathXmlApplicationContextFactory$ResourceXmlApplicationContext (ClassPat... 100% (1/1)100% (9/9)100% (3/3)
ClassPathXmlApplicationContextFactory$ResourceXmlApplicationContext (ClassPat... 100% (1/1)100% (5/5)100% (1/1)
getConfigResources (): Resource [] 100% (1/1)100% (9/9)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 */
16 
17package org.springframework.batch.core.configuration.support;
18 
19import org.springframework.beans.BeansException;
20import org.springframework.context.ApplicationContext;
21import org.springframework.context.ApplicationContextAware;
22import org.springframework.context.ConfigurableApplicationContext;
23import org.springframework.context.support.AbstractXmlApplicationContext;
24import org.springframework.core.io.Resource;
25import org.springframework.util.Assert;
26 
27/**
28 * {@link ApplicationContextFactory} implementation that takes a parent context and a path 
29 * to the context to create.  Each time the createApplicationContext method is called, a new
30 * {@link ApplicationContext} will be returned.  It should be noted that if a path isn't
31 * set, the parent will always be returned.
32 * 
33 */
34public class ClassPathXmlApplicationContextFactory implements ApplicationContextFactory, ApplicationContextAware {
35 
36        private ConfigurableApplicationContext parent;
37 
38        private Resource path;
39 
40        /**
41         * Setter for the path to the xml to load to create an
42         * {@link ApplicationContext}. Use imports to centralise the configuration in
43         * one file.
44         * 
45         * @param path the resource path to the xml to load for the child context.
46         */
47        public void setPath(Resource path) {
48                this.path = path;
49        }
50 
51        /**
52         * Setter for the parent application context.
53         * 
54         * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
55         */
56        public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
57                Assert.isInstanceOf(ConfigurableApplicationContext.class, applicationContext);
58                parent = (ConfigurableApplicationContext) applicationContext;
59        }
60 
61        /**
62         * Creates an {@link ApplicationContext} from the provided path.
63         * 
64         * @see ApplicationContextFactory#createApplicationContext()
65         */
66        public ConfigurableApplicationContext createApplicationContext() {
67                if (path == null) {
68                        return parent;
69                }
70                return new ResourceXmlApplicationContext(parent);
71        }
72 
73        /**
74         * @author Dave Syer
75         * 
76         */
77        private final class ResourceXmlApplicationContext extends AbstractXmlApplicationContext {
78                /**
79                 * @param parent
80                 */
81                private ResourceXmlApplicationContext(ApplicationContext parent) {
82                        super(parent);
83                        refresh();
84                }
85 
86                protected Resource[] getConfigResources() {
87                        return new Resource[] {path};
88                }
89        }
90 
91}

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