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 [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-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.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,
35                ApplicationContextAware {
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        public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
65                parent = applicationContext;
66        }
67 
68        /**
69         * Stash the {@link BundleContext} for creating a job application context
70         * later.
71         * 
72         * @see org.springframework.osgi.context.BundleContextAware#setBundleContext(org.osgi.framework.BundleContext)
73         */
74        public void setBundleContext(BundleContext context) {
75                this.bundleContext = context;
76        }
77 
78        /**
79         * Create an application context from the provided path, using the current
80         * OSGi {@link BundleContext} and the enclosing Spring
81         * {@link ApplicationContext} as a parent context.
82         * 
83         * @see ApplicationContextFactory#createApplicationContext()
84         */
85        public ConfigurableApplicationContext createApplicationContext() {
86                OsgiBundleXmlApplicationContext context = new OsgiBundleXmlApplicationContext(new String[] { path }, parent);
87                String displayName = bundleContext.getBundle().getSymbolicName() + ":" + this.displayName;
88                context.setDisplayName(displayName);
89                context.setBundleContext(bundleContext);
90                context.refresh();
91                return context;
92        }
93 
94        @Override
95        public String toString() {
96                String bundleId = bundleContext == null ? null : (bundleContext.getBundle() == null ? bundleContext.toString()
97                                : "" + bundleContext.getBundle().getBundleId());
98                return "OsgiBundleXmlApplicationContext [path=" + path + ", bundle=" + bundleId + "]";
99        }
100 
101        @Override
102        public int hashCode() {
103                return toString().hashCode();
104        }
105 
106        @Override
107        public boolean equals(Object obj) {
108                if (this == obj)
109                        return true;
110                if (obj == null)
111                        return false;
112                return toString().equals(obj.toString());
113        }
114 
115}

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