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