001/*
002 * Copyright 2002-2012 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.test.annotation;
018
019import org.springframework.util.Assert;
020
021/**
022 * Implementation of {@link ProfileValueSource} which uses system properties as
023 * the underlying source.
024 *
025 * @author Rod Johnson
026 * @author Sam Brannen
027 * @since 2.0
028 */
029public class SystemProfileValueSource implements ProfileValueSource {
030
031        private static final SystemProfileValueSource INSTANCE = new SystemProfileValueSource();
032
033
034        /**
035         * Obtain the canonical instance of this ProfileValueSource.
036         */
037        public static final SystemProfileValueSource getInstance() {
038                return INSTANCE;
039        }
040
041
042        /**
043         * Private constructor, enforcing the singleton pattern.
044         */
045        private SystemProfileValueSource() {
046        }
047
048        /**
049         * Get the <em>profile value</em> indicated by the specified key from the
050         * system properties.
051         * @see System#getProperty(String)
052         */
053        @Override
054        public String get(String key) {
055                Assert.hasText(key, "'key' must not be empty");
056                return System.getProperty(key);
057        }
058
059}