EMMA Coverage Report (generated Thu May 22 12:08:10 CDT 2014)
[all classes][org.springframework.batch.core.configuration.support]

COVERAGE SUMMARY FOR SOURCE FILE [OsgiBundleXmlApplicationContextFactory.java]

nameclass, %method, %block, %line, %
OsgiBundleXmlApplicationContextFactory.java100% (1/1)78%  (7/9)44%  (52/118)54%  (12.5/23)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class OsgiBundleXmlApplicationContextFactory100% (1/1)78%  (7/9)44%  (52/118)54%  (12.5/23)
createApplicationContext (): ConfigurableApplicationContext 0%   (0/1)0%   (0/39)0%   (0/6)
setApplicationContext (ApplicationContext): void 0%   (0/1)0%   (0/4)0%   (0/2)
toString (): String 100% (1/1)54%  (22/41)76%  (1.5/2)
equals (Object): boolean 100% (1/1)73%  (11/15)60%  (3/5)
OsgiBundleXmlApplicationContextFactory (): void 100% (1/1)100% (3/3)100% (1/1)
hashCode (): int 100% (1/1)100% (4/4)100% (1/1)
setBundleContext (BundleContext): void 100% (1/1)100% (4/4)100% (2/2)
setDisplayName (String): void 100% (1/1)100% (4/4)100% (2/2)
setPath (String): void 100% (1/1)100% (4/4)100% (2/2)

1/*
2 * Copyright 2006-2013 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.osgi.framework.BundleContext;
20import org.springframework.beans.BeansException;
21import org.springframework.context.ApplicationContext;
22import org.springframework.context.ApplicationContextAware;
23import org.springframework.context.ConfigurableApplicationContext;
24import org.springframework.osgi.context.BundleContextAware;
25import org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext;
26 
27/**
28 * {@link ApplicationContextFactory} that can be used to load a context from an
29 * XML location in a bundle.
30 *
31 * @author Dave Syer
32 *
33 */
34public class OsgiBundleXmlApplicationContextFactory implements BundleContextAware, ApplicationContextFactory,
35ApplicationContextAware {
36 
37        private BundleContext bundleContext;
38 
39        private ApplicationContext parent;
40 
41        private String path;
42 
43        private String displayName;
44 
45        /**
46         * @param path the resource path to the xml to load for the child context.
47         */
48        public void setPath(String path) {
49                this.path = path;
50        }
51 
52        /**
53         * @param displayName the display name for the application context created.
54         */
55        public void setDisplayName(String displayName) {
56                this.displayName = displayName;
57        }
58 
59        /**
60         * Setter for the parent application context.
61         *
62         * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
63         */
64        @Override
65        public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
66                parent = applicationContext;
67        }
68 
69        /**
70         * Stash the {@link BundleContext} for creating a job application context
71         * later.
72         *
73         * @see org.springframework.osgi.context.BundleContextAware#setBundleContext(org.osgi.framework.BundleContext)
74         */
75        @Override
76        public void setBundleContext(BundleContext context) {
77                this.bundleContext = context;
78        }
79 
80        /**
81         * Create an application context from the provided path, using the current
82         * OSGi {@link BundleContext} and the enclosing Spring
83         * {@link ApplicationContext} as a parent context.
84         *
85         * @see ApplicationContextFactory#createApplicationContext()
86         */
87        @Override
88        public ConfigurableApplicationContext createApplicationContext() {
89                OsgiBundleXmlApplicationContext context = new OsgiBundleXmlApplicationContext(new String[] { path }, parent);
90                String displayName = bundleContext.getBundle().getSymbolicName() + ":" + this.displayName;
91                context.setDisplayName(displayName);
92                context.setBundleContext(bundleContext);
93                context.refresh();
94                return context;
95        }
96 
97        @Override
98        public String toString() {
99                String bundleId = bundleContext == null ? null : (bundleContext.getBundle() == null ? bundleContext.toString()
100                                : "" + bundleContext.getBundle().getBundleId());
101                return "OsgiBundleXmlApplicationContext [path=" + path + ", bundle=" + bundleId + "]";
102        }
103 
104        @Override
105        public int hashCode() {
106                return toString().hashCode();
107        }
108 
109        @Override
110        public boolean equals(Object obj) {
111                if (this == obj) {
112                        return true;
113                }
114                if (obj == null) {
115                        return false;
116                }
117                return toString().equals(obj.toString());
118        }
119 
120}

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