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

COVERAGE SUMMARY FOR SOURCE FILE [SystemPropertyInitializer.java]

nameclass, %method, %block, %line, %
SystemPropertyInitializer.java100% (1/1)100% (4/4)100% (44/44)100% (9/9)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SystemPropertyInitializer100% (1/1)100% (4/4)100% (44/44)100% (9/9)
SystemPropertyInitializer (): void 100% (1/1)100% (6/6)100% (2/2)
afterPropertiesSet (): void 100% (1/1)100% (30/30)100% (3/3)
setDefaultValue (String): void 100% (1/1)100% (4/4)100% (2/2)
setKeyName (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 */
16package org.springframework.batch.support;
17 
18import org.springframework.beans.factory.InitializingBean;
19import org.springframework.util.Assert;
20 
21/**
22 * Helper class that sets up a System property with a default value. A System
23 * property is created with the specified key name, and default value (i.e. if
24 * the property already exists it is not changed).
25 * 
26 * @author Dave Syer
27 * 
28 */
29public class SystemPropertyInitializer implements InitializingBean {
30 
31        /**
32         * Name of system property used by default.
33         */
34        public static final String ENVIRONMENT = "org.springframework.batch.support.SystemPropertyInitializer.ENVIRONMENT";
35 
36        private String keyName = ENVIRONMENT;
37 
38        private String defaultValue;
39 
40        /**
41         * Set the key name for the System property that is created. Defaults to
42         * {@link #ENVIRONMENT}.
43         * 
44         * @param keyName the key name to set
45         */
46        public void setKeyName(String keyName) {
47                this.keyName = keyName;
48        }
49 
50        /**
51         * Mandatory property specifying the default value of the System property.
52         * 
53         * @param defaultValue the default value to set
54         */
55        public void setDefaultValue(String defaultValue) {
56                this.defaultValue = defaultValue;
57        }
58 
59        /**
60         * Sets the System property with the provided name and default value.
61         * 
62         * @see InitializingBean#afterPropertiesSet()
63         */
64        public void afterPropertiesSet() throws Exception {
65                Assert.state(defaultValue != null || System.getProperty(keyName) != null,
66                                "Either a default value must be specified or the value should already be set for System property: "
67                                                + keyName);
68                System.setProperty(keyName, System.getProperty(keyName, defaultValue));
69        }
70 
71}

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