Path: blob/master/src/java.desktop/share/classes/java/beans/ThreadGroupContext.java
41152 views
/*1* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.beans;2627import com.sun.beans.finder.BeanInfoFinder;28import com.sun.beans.finder.PropertyEditorFinder;2930import java.awt.GraphicsEnvironment;31import java.util.Map;32import java.util.WeakHashMap;3334/**35* The {@code ThreadGroupContext} is an application-dependent36* context referenced by the specific {@link ThreadGroup}.37* This is a replacement for the {@link sun.awt.AppContext}.38*39* @author Sergey Malenkov40*/41final class ThreadGroupContext {4243private static final WeakIdentityMap<ThreadGroupContext> contexts = new WeakIdentityMap<ThreadGroupContext>() {44protected ThreadGroupContext create(Object key) {45return new ThreadGroupContext();46}47};4849/**50* Returns the appropriate {@code ThreadGroupContext} for the caller,51* as determined by its {@code ThreadGroup}.52*53* @return the application-dependent context54*/55static ThreadGroupContext getContext() {56return contexts.get(Thread.currentThread().getThreadGroup());57}5859private volatile boolean isDesignTime;60private volatile Boolean isGuiAvailable;6162private Map<Class<?>, BeanInfo> beanInfoCache;63private BeanInfoFinder beanInfoFinder;64private PropertyEditorFinder propertyEditorFinder;6566private ThreadGroupContext() {67}6869boolean isDesignTime() {70return this.isDesignTime;71}7273void setDesignTime(boolean isDesignTime) {74this.isDesignTime = isDesignTime;75}767778boolean isGuiAvailable() {79Boolean isGuiAvailable = this.isGuiAvailable;80return (isGuiAvailable != null)81? isGuiAvailable.booleanValue()82: !GraphicsEnvironment.isHeadless();83}8485void setGuiAvailable(boolean isGuiAvailable) {86this.isGuiAvailable = Boolean.valueOf(isGuiAvailable);87}888990synchronized BeanInfo getBeanInfo(Class<?> type) {91return (this.beanInfoCache != null)92? this.beanInfoCache.get(type)93: null;94}9596synchronized BeanInfo putBeanInfo(Class<?> type, BeanInfo info) {97if (this.beanInfoCache == null) {98this.beanInfoCache = new WeakHashMap<>();99}100return this.beanInfoCache.put(type, info);101}102103synchronized void removeBeanInfo(Class<?> type) {104if (this.beanInfoCache != null) {105this.beanInfoCache.remove(type);106}107}108109synchronized void clearBeanInfoCache() {110if (this.beanInfoCache != null) {111this.beanInfoCache.clear();112}113}114115116synchronized BeanInfoFinder getBeanInfoFinder() {117if (this.beanInfoFinder == null) {118this.beanInfoFinder = new BeanInfoFinder();119}120return this.beanInfoFinder;121}122123synchronized PropertyEditorFinder getPropertyEditorFinder() {124if (this.propertyEditorFinder == null) {125this.propertyEditorFinder = new PropertyEditorFinder();126}127return this.propertyEditorFinder;128}129}130131132