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