001/*
002 * Copyright 2002-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 *      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.ui.context.support;
018
019import org.springframework.lang.Nullable;
020import org.springframework.ui.context.HierarchicalThemeSource;
021import org.springframework.ui.context.Theme;
022import org.springframework.ui.context.ThemeSource;
023
024/**
025 * Empty ThemeSource that delegates all calls to the parent ThemeSource.
026 * If no parent is available, it simply won't resolve any theme.
027 *
028 * <p>Used as placeholder by UiApplicationContextUtils, if a context doesn't
029 * define its own ThemeSource. Not intended for direct use in applications.
030 *
031 * @author Juergen Hoeller
032 * @since 1.2.4
033 * @see UiApplicationContextUtils
034 */
035public class DelegatingThemeSource implements HierarchicalThemeSource {
036
037        @Nullable
038        private ThemeSource parentThemeSource;
039
040
041        @Override
042        public void setParentThemeSource(@Nullable ThemeSource parentThemeSource) {
043                this.parentThemeSource = parentThemeSource;
044        }
045
046        @Override
047        @Nullable
048        public ThemeSource getParentThemeSource() {
049                return this.parentThemeSource;
050        }
051
052
053        @Override
054        @Nullable
055        public Theme getTheme(String themeName) {
056                if (this.parentThemeSource != null) {
057                        return this.parentThemeSource.getTheme(themeName);
058                }
059                else {
060                        return null;
061                }
062        }
063
064}