EMMA Coverage Report (generated Thu Jan 24 13:37:04 CST 2013)
[all classes][org.springframework.batch.core.configuration.support]

COVERAGE SUMMARY FOR SOURCE FILE [ClasspathXmlApplicationContextsFactoryBean.java]

nameclass, %method, %block, %line, %
ClasspathXmlApplicationContextsFactoryBean.java100% (1/1)56%  (5/9)74%  (72/97)67%  (20/30)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ClasspathXmlApplicationContextsFactoryBean100% (1/1)56%  (5/9)74%  (72/97)67%  (20/30)
getObjectType (): Class 0%   (0/1)0%   (0/2)0%   (0/1)
setBeanFactoryPostProcessorClasses (Class []): void 0%   (0/1)0%   (0/4)0%   (0/2)
setBeanPostProcessorExcludeClasses (Class []): void 0%   (0/1)0%   (0/4)0%   (0/2)
setCopyConfiguration (boolean): void 0%   (0/1)0%   (0/4)0%   (0/2)
getObject (): Object 100% (1/1)82%  (50/61)80%  (12/15)
ClasspathXmlApplicationContextsFactoryBean (): void 100% (1/1)100% (11/11)100% (3/3)
isSingleton (): boolean 100% (1/1)100% (2/2)100% (1/1)
setApplicationContext (ApplicationContext): void 100% (1/1)100% (4/4)100% (2/2)
setResources (Resource []): void 100% (1/1)100% (5/5)100% (2/2)

1/*
2 * Copyright 2006-2010 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.ArrayList;
19import java.util.Arrays;
20import java.util.List;
21 
22import org.springframework.beans.BeansException;
23import org.springframework.beans.factory.BeanFactoryAware;
24import org.springframework.beans.factory.FactoryBean;
25import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
26import org.springframework.beans.factory.config.BeanPostProcessor;
27import org.springframework.beans.factory.config.CustomEditorConfigurer;
28import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
29import org.springframework.context.ApplicationContext;
30import org.springframework.context.ApplicationContextAware;
31import org.springframework.core.io.Resource;
32 
33/**
34 * A convenient factory for creating a set of {@link ApplicationContextFactory}
35 * components from a set of {@link Resource resources}.
36 * 
37 * @author Dave Syer
38 * 
39 */
40public class ClasspathXmlApplicationContextsFactoryBean implements FactoryBean, ApplicationContextAware {
41 
42        private List<Resource> resources = new ArrayList<Resource>();
43 
44        private boolean copyConfiguration = true;
45 
46        private Class<? extends BeanFactoryPostProcessor>[] beanFactoryPostProcessorClasses;
47 
48        private Class<?>[] beanPostProcessorExcludeClasses;
49 
50        private ApplicationContext applicationContext;
51 
52        /**
53         * A set of resources to load using a
54         * {@link ClassPathXmlApplicationContextFactory}. Each resource should be a
55         * Spring configuration file which is loaded into an application context
56         * whose parent is the current context. In a configuration file the
57         * resources can be given as a pattern (e.g.
58         * <code>classpath*:/config/*-context.xml</code>).
59         * 
60         * @param resources
61         */
62        public void setResources(Resource[] resources) {
63                this.resources = Arrays.asList(resources);
64        }
65 
66        /**
67         * Flag to indicate that configuration such as bean post processors and
68         * custom editors should be copied from the parent context. Defaults to
69         * true.
70         * 
71         * @param copyConfiguration the flag value to set
72         */
73        public void setCopyConfiguration(boolean copyConfiguration) {
74                this.copyConfiguration = copyConfiguration;
75        }
76 
77        /**
78         * Determines which bean factory post processors (like property
79         * placeholders) should be copied from the parent context. Defaults to
80         * {@link PropertyPlaceholderConfigurer} and {@link CustomEditorConfigurer}.
81         * 
82         * @param copyBeanFactoryPostProcessors the flag value to set
83         */
84 
85        public void setBeanFactoryPostProcessorClasses(
86                        Class<? extends BeanFactoryPostProcessor>[] beanFactoryPostProcessorClasses) {
87                this.beanFactoryPostProcessorClasses = beanFactoryPostProcessorClasses;
88        }
89 
90        /**
91         * Determines by exclusion which bean post processors should be copied from
92         * the parent context. Defaults to {@link BeanFactoryAware} (so any post
93         * processors that have a reference to the parent bean factory are not
94         * copied into the child). Note that these classes do not themselves have to
95         * be {@link BeanPostProcessor} implementations or sub-interfaces.
96         * 
97         * @param beanPostProcessorExcludeClasses the classes to set
98         */
99        public void setBeanPostProcessorExcludeClasses(Class<?>[] beanPostProcessorExcludeClasses) {
100                this.beanPostProcessorExcludeClasses = beanPostProcessorExcludeClasses;
101        }
102 
103        /**
104         * Create an {@link ApplicationContextFactory} from each resource provided
105         * in {@link #setResources(Resource[])}.
106         * 
107         * @return an array of {@link ApplicationContextFactory}
108         * @throws Exception
109         * @see org.springframework.beans.factory.FactoryBean#getObject()
110         */
111        public Object getObject() throws Exception {
112 
113                if (resources == null) {
114                        return new ApplicationContextFactory[0];
115                }
116 
117                List<ApplicationContextFactory> applicationContextFactories = new ArrayList<ApplicationContextFactory>();
118                for (Resource resource : resources) {
119                        ClassPathXmlApplicationContextFactory factory = new ClassPathXmlApplicationContextFactory();
120                        factory.setCopyConfiguration(copyConfiguration);
121                        if (beanFactoryPostProcessorClasses != null) {
122                                factory.setBeanFactoryPostProcessorClasses(beanFactoryPostProcessorClasses);
123                        }
124                        if (beanPostProcessorExcludeClasses != null) {
125                                factory.setBeanPostProcessorExcludeClasses(beanPostProcessorExcludeClasses);
126                        }
127                        factory.setResource(resource);
128                        factory.setApplicationContext(applicationContext);
129                        applicationContextFactories.add(factory);
130                }
131                return applicationContextFactories.toArray(new ApplicationContextFactory[applicationContextFactories.size()]);
132        }
133 
134        /**
135         * The type of object returned by this factory - an array of
136         * {@link ApplicationContextFactory}.
137         * 
138         * @return array of {@link ApplicationContextFactory}
139         * @see FactoryBean#getObjectType()
140         */
141        public Class<?> getObjectType() {
142                return ApplicationContextFactory[].class;
143        }
144 
145        /**
146         * Optimization hint for bean factory.
147         * @return true
148         * @see FactoryBean#isSingleton()
149         */
150        public boolean isSingleton() {
151                return true;
152        }
153 
154        /**
155         * An application context that can be used as a parent context for all the
156         * factories.
157         * 
158         * @param applicationContext the {@link ApplicationContext} to set
159         * @throws BeansException
160         * @see ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
161         */
162        public void setApplicationContext(ApplicationContext applicationContext) {
163                this.applicationContext = applicationContext;
164        }
165 
166}

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