4373N/A/*
5886N/A * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
4373N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4373N/A *
4373N/A * This code is free software; you can redistribute it and/or modify it
4373N/A * under the terms of the GNU General Public License version 2 only, as
4373N/A * published by the Free Software Foundation. Oracle designates this
4373N/A * particular file as subject to the "Classpath" exception as provided
4373N/A * by Oracle in the LICENSE file that accompanied this code.
4373N/A *
4373N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4373N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4373N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4373N/A * version 2 for more details (a copy is included in the LICENSE file that
4373N/A * accompanied this code).
4373N/A *
4373N/A * You should have received a copy of the GNU General Public License version
4373N/A * 2 along with this work; if not, write to the Free Software Foundation,
4373N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4373N/A *
4373N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4373N/A * or visit www.oracle.com if you need additional information or have any
4373N/A * questions.
4373N/A */
4373N/A
4373N/Apackage java.beans;
4373N/A
4373N/Aimport com.sun.beans.finder.BeanInfoFinder;
4373N/Aimport com.sun.beans.finder.PropertyEditorFinder;
4373N/A
4373N/Aimport java.awt.GraphicsEnvironment;
4373N/Aimport java.util.Map;
4373N/Aimport java.util.WeakHashMap;
4373N/A
4373N/A/**
4373N/A * The {@code ThreadGroupContext} is an application-dependent
4373N/A * context referenced by the specific {@link ThreadGroup}.
4373N/A * This is a replacement for the {@link sun.awt.AppContext}.
4373N/A *
4373N/A * @author Sergey Malenkov
4373N/A */
4373N/Afinal class ThreadGroupContext {
4373N/A
5886N/A private static final WeakIdentityMap<ThreadGroupContext> contexts = new WeakIdentityMap<>();
4373N/A
4373N/A /**
4373N/A * Returns the appropriate {@code AppContext} for the caller,
4373N/A * as determined by its {@code ThreadGroup}.
4373N/A *
4373N/A * @return the application-dependent context
4373N/A */
4373N/A static ThreadGroupContext getContext() {
4373N/A ThreadGroup group = Thread.currentThread().getThreadGroup();
4373N/A synchronized (contexts) {
4373N/A ThreadGroupContext context = contexts.get(group);
4373N/A if (context == null) {
4373N/A context = new ThreadGroupContext();
4373N/A contexts.put(group, context);
4373N/A }
4373N/A return context;
4373N/A }
4373N/A }
4373N/A
4373N/A private volatile boolean isDesignTime;
4373N/A private volatile Boolean isGuiAvailable;
4373N/A
4373N/A private Map<Class<?>, BeanInfo> beanInfoCache;
4373N/A private BeanInfoFinder beanInfoFinder;
4373N/A private PropertyEditorFinder propertyEditorFinder;
4373N/A
5886N/A private ThreadGroupContext() {
5886N/A }
4373N/A
4373N/A boolean isDesignTime() {
4373N/A return this.isDesignTime;
4373N/A }
4373N/A
4373N/A void setDesignTime(boolean isDesignTime) {
4373N/A this.isDesignTime = isDesignTime;
4373N/A }
4373N/A
4373N/A
4373N/A boolean isGuiAvailable() {
4373N/A Boolean isGuiAvailable = this.isGuiAvailable;
4373N/A return (isGuiAvailable != null)
4373N/A ? isGuiAvailable.booleanValue()
4373N/A : !GraphicsEnvironment.isHeadless();
4373N/A }
4373N/A
4373N/A void setGuiAvailable(boolean isGuiAvailable) {
4373N/A this.isGuiAvailable = Boolean.valueOf(isGuiAvailable);
4373N/A }
4373N/A
4373N/A
4373N/A BeanInfo getBeanInfo(Class<?> type) {
4373N/A return (this.beanInfoCache != null)
4373N/A ? this.beanInfoCache.get(type)
4373N/A : null;
4373N/A }
4373N/A
4373N/A BeanInfo putBeanInfo(Class<?> type, BeanInfo info) {
4373N/A if (this.beanInfoCache == null) {
4373N/A this.beanInfoCache = new WeakHashMap<>();
4373N/A }
4373N/A return this.beanInfoCache.put(type, info);
4373N/A }
4373N/A
4373N/A void removeBeanInfo(Class<?> type) {
4373N/A if (this.beanInfoCache != null) {
4373N/A this.beanInfoCache.remove(type);
4373N/A }
4373N/A }
4373N/A
4373N/A void clearBeanInfoCache() {
4373N/A if (this.beanInfoCache != null) {
4373N/A this.beanInfoCache.clear();
4373N/A }
4373N/A }
4373N/A
4373N/A
4373N/A synchronized BeanInfoFinder getBeanInfoFinder() {
4373N/A if (this.beanInfoFinder == null) {
4373N/A this.beanInfoFinder = new BeanInfoFinder();
4373N/A }
4373N/A return this.beanInfoFinder;
4373N/A }
4373N/A
4373N/A synchronized PropertyEditorFinder getPropertyEditorFinder() {
4373N/A if (this.propertyEditorFinder == null) {
4373N/A this.propertyEditorFinder = new PropertyEditorFinder();
4373N/A }
4373N/A return this.propertyEditorFinder;
4373N/A }
4373N/A}