001/*
002 * Copyright 2012-2018 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 *      http://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.boot.env;
018
019import java.util.Map;
020
021import org.springframework.boot.origin.Origin;
022import org.springframework.boot.origin.OriginLookup;
023import org.springframework.boot.origin.OriginTrackedValue;
024import org.springframework.core.env.MapPropertySource;
025
026/**
027 * {@link OriginLookup} backed by a {@link Map} containing {@link OriginTrackedValue
028 * OriginTrackedValues}.
029 *
030 * @author Madhura Bhave
031 * @author Phillip Webb
032 * @since 2.0.0
033 * @see OriginTrackedValue
034 */
035public final class OriginTrackedMapPropertySource extends MapPropertySource
036                implements OriginLookup<String> {
037
038        @SuppressWarnings({ "unchecked", "rawtypes" })
039        public OriginTrackedMapPropertySource(String name, Map source) {
040                super(name, source);
041        }
042
043        @Override
044        public Object getProperty(String name) {
045                Object value = super.getProperty(name);
046                if (value instanceof OriginTrackedValue) {
047                        return ((OriginTrackedValue) value).getValue();
048                }
049                return value;
050        }
051
052        @Override
053        public Origin getOrigin(String name) {
054                Object value = super.getProperty(name);
055                if (value instanceof OriginTrackedValue) {
056                        return ((OriginTrackedValue) value).getOrigin();
057                }
058                return null;
059        }
060
061}